How to define an optional parameter in path using swagger

后端 未结 5 1952
名媛妹妹
名媛妹妹 2020-12-29 00:51

There is a function in my REST web service working with GET method and it has two optional parameters.

I tried to define it in Swagger but I encountered an error, <

5条回答
  •  误落风尘
    2020-12-29 01:21

    It it likely blowing up because you cannot have a base uri parameter optional, only query string values (in the case of a url).

    For example:

    • GET /products/{id}/pricing?foo=bar
    • ** If foo is optional then your IN parameter needs to be "query" not "path"
    • ** If {id} is optional then something is wrong. {id} can't be optional because it is contained within the base uri.

    This should work:

    {
    "in":"query",
    "required":false
    }
    

    This should not work

    {
    "in":"path",
    "required":false
    }
    

    change your "in" property to be "query" instead of "path" and it should work.

提交回复
热议问题