Skip to content

[Go] Optional values should be pointers #522

@langston-barrett

Description

@langston-barrett
Description

If a field of a struct isn't specified as required, then it should be a pointer to that value so that one can differentiate between unset by the user or set to the "zero value". See the following Go playground: https://play.golang.org/p/85r_JbH5XVr

See also e.g. this Stackoverflow answer.

openapi-generator version

Docker container

OpenAPI declaration file content or url
---
openapi: 3.0.0
info:
  title: unset
  version: 0.1.0

paths:
  "/foo":
    get:
      summary: foo
      responses:
        '200':
          description: OK
          content:
            application/xml:
              schema:
                "$ref": "#/components/schemas/Bar"

components:
  schemas:
    Bar:
      properties:
        X:
          type: integer
        Y:
          type: integer
      required:
        - X
Related issues/PRs
Suggest a fix/enhancement

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions