inaka / cowboy_swagger

Swagger integration for Cowboy (built on trails)
http://inaka.net/blog/2015/08/19/cowboy-swagger/
Apache License 2.0
121 stars 58 forks source link

Support 'components' section in openapi 3.0.0 #119

Closed brucify closed 4 years ago

brucify commented 4 years ago

Currently, add_definition/1 always adds to the definitions: section in swagger.json and schema/1 hardcodes to fetch from <<"#/definitions/", DefinitionName/binary>>.

Open API 3.0.0 has removed the #/definitions/ section and introduced #/components/schemas/ (Components Section)

OpenAPI 2.0                    OpenAPI 3.0
'#/definitions/User'         → '#/components/schemas/User'

This causes:

Structural error at 
should NOT have additional properties
additionalProperty: definitions
Jump to line 0

This PR adds support to point add_definition/1 and schema/1 to "components" section if openapi: "3.0.0" is defined. For swagger: "2.0", it will still add to "definitions" section.