You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to generate an OpenAPI spec from code that skips the additionalProperties when generating spec based on a map[string]interface{} type.
So I want a definition of:
typeCustomMetadatamap[string]interface{}
To generate:
CustomMetadata:
type: object
As far as I observed, the additionalProperties property comes from using a map[string]interface{}, since when using a simple interface{}, it generates the expected output. A definition:
typeCustomMetadatainterface{}
Generates:
CustomMetadata:
type: object
I have tried to achieve that using swagger:format. I expected a definition of:
so without the additionalProperties field. But it is not the case and the // swagger:type object seems to be ignored. The same happens with a type definition of type CustomMetadata interface{}: no matter the swagger:type, the type definitions based on a map or interface always generate their respective OpenAPI specs disregarding a swagger:type.
I've also checked other types, and so for example:
// swagger:type objecttypeCustomMetadatastring
Generates:
CustomMetadata: {}
This is still not ideal, since as far as I know, the {} in Swagger 2.0 means "any type", and not an object specifically. But it shows that the swagger:type is taken into account in this case.
The current solution is to use interface{} instead of map[string]interface{} which generates expected output, but is not ideal since it requires a lot of changes in the actual application code.
Problem statement
I'm trying to generate an OpenAPI spec from code that skips the
additionalProperties
when generating spec based on amap[string]interface{}
type.So I want a definition of:
To generate:
As far as I observed, the
additionalProperties
property comes from using amap[string]interface{}
, since when using a simpleinterface{}
, it generates the expected output. A definition:Generates:
I have tried to achieve that using
swagger:format
. I expected a definition of:To generate:
so without the
additionalProperties
field. But it is not the case and the// swagger:type object
seems to be ignored. The same happens with a type definition oftype CustomMetadata interface{}
: no matter theswagger:type
, the type definitions based on amap
orinterface
always generate their respective OpenAPI specs disregarding aswagger:type
.I've also checked other types, and so for example:
Generates:
This is still not ideal, since as far as I know, the
{}
in Swagger 2.0 means "any type", and not an object specifically. But it shows that theswagger:type
is taken into account in this case.The current solution is to use
interface{}
instead ofmap[string]interface{}
which generates expected output, but is not ideal since it requires a lot of changes in the actual application code.Swagger specification
Steps to reproduce
Run:
Environment
swagger version:
go version:
go version go1.17.2 linux/amd64
OS:
Ubuntu 18.04.6 LTS
The text was updated successfully, but these errors were encountered: