gointerfaceopenapigo-ginapi-doc

How to define "interface" as a datatype in open API?


In my golang project, I have a structure that contains this field:

type hook struct {
   Data interface{} `json:"data"`
}

How to represent this Data field in Open API Spec?


Solution

  • It is not a good idea to use the absolutely free form type in the specification, I think, but if you want to do so, use the {} form of definition:

    data: {}
    

    Also you can add a null value to the allowed:

    data:
      nullable: true
    

    See the "Any Type" section of the types documentation: https://swagger.io/docs/specification/data-models/data-types/