Array Representation in Generated Documentation
I'm having some issues with generated documentation when it comes to array representation. Here is my struct code:
type ThingsPage struct {
Things []Thing `json:"things" doc:"A list of things."`
}
The generated yaml looks like
ThingsPage:
additionalProperties: true
properties:
things:
description: A list of things.
items:
$ref: "#/components/schemas/Thing"
type:
- array
- "null"
required:
- things
type: object
The "null" under the type removes the ability for the visualized documentation to expand the properties of Thing. I tried a couple things, like adding nullable:"false" and required:"true" struct tags, but nothing seems to remove that "null" from the generated yaml. The desired yaml should look like
ThingsPage:
additionalProperties: true
properties:
things:
description: A list of things.
items:
$ref: "#/components/schemas/Thing"
type: array
required:
- things
type: object
Any help would be appreciated.
I figured out that calling /openapi-3.0.yaml resolves this issue.
ThingsPage:
additionalProperties: true
properties:
things:
description: A list of things.
items:
$ref: "#/components/schemas/Thing"
nullable: true
type: array
required:
- things
type: object
In openapi version 3.1, we need to use the oneOf keyword, in order to support both null and array type. Keeping this issue open for this. It seems like the generated yaml does not generate the oneOf keyword.