redskap / swagger-brake

Swagger contract checker for breaking API changes
Apache License 2.0
59 stars 16 forks source link

Null output for formData parameter #28

Closed MinniArora closed 4 years ago

MinniArora commented 4 years ago

Hi Defining parameter as below gives null on running swagger brake:

{"in":"formData","name":"fileName","description":"fileName","required":true,"schema":{"type":"string"}}

Output: Successfully loaded APIs Starting the check for breaking API changes null For help please use --help

Is there anything missing?

galovics commented 4 years ago

@MinniArora could you please provide a full Swagger that could be used to repro the issue? That would speed up the investigation for sure. Thanks!

MinniArora commented 4 years ago

@galovics Sure. PFA. swagger-brake-issue.zip

galovics commented 4 years ago

Hi @MinniArora. I've checked the attached definition, thanks for that. It seems like you are not conforming the OpenAPI specification. Your API definition is using the 2.0 version. In that case according to the specification:

schema is only used with in: body parameters. Any other parameters expect a primitive type, such as type: string, or an array of primitives.

Your API definition when using formData (like for access_token), you are specifying a schema. If you flatten it and change it to a primitive string type, its going to work.

For OpenAPI V3, the formData attribute concept has been replaced with relying on the requestBody attribute of a path. In that case, the way to define it is to always use a schema:

In OpenAPI 3.0, form data is modelled using a type: object schema where the object properties represent the form fields

I think your definition is between the 2 versions. Although I'm going to introduce some level of validation to detect the wrong usage of the schema attribute.

MinniArora commented 4 years ago

@galovics Thank you for a detailed reply. This swagger file is auto generated using springfox. Came across this

galovics commented 4 years ago

@MinniArora got it, then thats the reason.