question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

In Swagger 2.0, what should “default” within an array parameter actually mean?

See original GitHub issue

Not an issue, but a question on the swagger in the repo:

In the well-known petstore swagger document, the findByStatus endpoint takes a status:

"parameters": [
    {
        "name": "status",
        "in": "query",
        "description": "Status values that need to be considered for filter",
        "required": true,
        "type": "array",
        "items": {
            "type": "string",
            "enum": [
                "available",
                "pending",
                "sold"
            ],
            "default": "available"
        },
        "collectionFormat": "multi"
    }
]

While the default value could be implied from this, from a programmatic perspective what should be expected as the value for “status” (and for other parameters in a similar case)?

The value is of type array, it doesn’t have a default. Each item is a string, one of available, pending or sold, and the default if not supplied is “available” How would you use “default” for an array of arbitrary length? The default supplied is for the string, not the array so:

Does this imply that the array has no default value? Does it imply that the array has a default value of an array with one item that is the default value for the array items? Does it imply an array of arbitrary length where all the values are the default value for the array items? Or is it just for UI representation of the default selected value when adding a new item to the array?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
silkentrancecommented, Aug 3, 2018

I believe that the example is just wrong. It should rather read

"parameters": [
    {
        "name": "status",
        "in": "query",
        "description": "Status values that need to be considered for filter",
        "required": true,
        "type": "array",
        "items": {
            "type": "string",
            "enum": [
                "available",
                "pending",
                "sold"
            ]
        },
        "default": ["available"]
        "collectionFormat": "multi"
    }
]

which would in fact make more sense.

0reactions
handrewscommented, Feb 11, 2020

Looks like the example in question is not part of this project, and no more work is being done on OAS 2 anyway, so I’m going to close this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

json - In Swagger 2.0, what should "default" within an array ...
In Swagger 2.0, what should "default" within an array parameter actually mean? · Does this imply that the array has no default value?...
Read more >
Describing Parameters - Swagger
Use the default keyword in the parameter schema to specify the default value for an optional parameter. The default value is the one...
Read more >
Describing Parameters - Swagger
Default Parameter Values. You can use the default key to specify the default value for an optional parameter. The default value is the...
Read more >
Unlocking the Spec: The default keyword - Swagger
For body parameters of complex types, the default can represent a complex default value. Containers of array types should have an array ...
Read more >
OpenAPI Specification - Version 2.0 - Swagger
Version 2.0 specification defines a set of files required to describe an API. ... default, *, Declares the value of the parameter that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found