swagger-api / swagger-api/swagger-codegen

Petstore swagger example uses "default" incorrectly

Open
#8,604 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

"default" is used incorrectly in the petstore swagger example. An array schema has a default inside the "items" definition, when it should be the default of the array parameter itself.

Swagger declaration file content or url
"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"
    }
]

Found: https://petstore.swagger.io/v2/swagger.json

Related issues/PRs

https://github.com/OAI/OpenAPI-Specification/issues/1629
This is an issue in the openapi spec which notes that the example is wrong.

Suggest a fix/enhancement
"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"
    }
]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the source for the Petstore swagger.json example at petstore.swagger.io/v2/swagger.json and compare it with the declaration shown in this issue. Check the related OpenAPI Specification issue for context; done means the published example uses the corrected array-parameter default placement.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.