fix: Do not wrap an example list value in another list - #1250
Conversation
|
Hi @psamuels00, and first of all sorry for the super late reply. Haven't had much spare time lately. I see your point there, but I am unsure whether we actually want that change. I think it makes definition of what we see as an example more ambiguous.
This meant that an example is usually ONE entity dict that is returned (e.g The thing is that you implicitly assume that nobody would want to have a list of entitites on Another issue: What does happen if you would give that example tldr: For drf-spectacular, examples were meant to be ONE atomic example. Sure, OpenAPI could be written differently, but in the context of DRF's Let me know what you think, but I am still quiet confident this would create more problems than it solves. |
The purpose of this PR is to allow a list of values (more than one) to be presented as the value of an Open API Example. In all the examples I found online, only a single value is supplied, which value is automatically turned into a list. Also, there are no unit tests for handling a list of values.
Background
In 0.22.0, a change was made, reflected by the following entry in the release notes:
Based on the following decorator...
...the Swagger example renders like this:
So far, so good.
The Problem
If a list is explicitly supplied for the example value, it is still wrapped in a list. Given the following...
...the Swagger example renders like this:
The Expectation
I would expect the rendered example to not be nested in a list, for example:
The Solution
With the proposed changes, if a list is supplied as the value of an example, it is not wrapped in a new list.