Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array Representation in Generated Documentation #636

Open
jchen1122-sibros opened this issue Nov 1, 2024 · 1 comment
Open

Array Representation in Generated Documentation #636

jchen1122-sibros opened this issue Nov 1, 2024 · 1 comment

Comments

@jchen1122-sibros
Copy link

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.

@jchen1122-sibros
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant