alexjomin / openapi-parser

Simple and still naive openapi documentation generator from comments of your Go code.
18 stars 8 forks source link

feat(support map): Add Map support on parsing #20

Closed lhauspie closed 5 years ago

lhauspie commented 5 years ago

Modification of the model

The openapi spec says:

additionalProperties - Value can be boolean or object. Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema.

It seems not possible in go to have this kind of "double type" but the openapi spec also says that:

type: object
additionalProperties: true

This is equivalent to:

type: object
additionalProperties: {}

So I changed type of AdditionalProperties from bool to &schema.

Modification of the parser#parseNamedType

implementing the case *ast.MapType to generate:

type: object
additionalProperties:
  type: string # or other simple type like integer or boolean

or

type: object
additionalProperties:
  $ref: '#/components/schemas/Pet' # or other complex type

Free-Form Objects (interface{}) still not be supported as Key or Value.

Note

Keys of maps can only be of type string, throw an error in case of keys are of another type.

lhauspie commented 5 years ago

Has this merge request a chance to be merged ?

@kratisto @denouche @alexjomin