How to define an optional parameter in path using swagger

Given that path parameter must be required according to the OpenAPI/Swagger spec, you can consider adding 2 separate endpoints with the following paths:

  • /get/{param1}/{param2} when param2 is provided
  • /get/{param1}/ when param2 is not provided

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.