Skip to content

[BUG][GO] Enums not generated #9567

@ngodzik

Description

@ngodzik

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Using the petstore.yaml sample file, the provided enum is not reflected in the Go generated files

 Pet:
  title: a Pet
  description: A pet for sale in the pet store
  type: object
  required:
    - name
    - photoUrls
  properties:
    id:
      type: integer
      format: int64
    category:
      $ref: '#/components/schemas/Category'
    name:
      type: string
      example: doggie
    photoUrls:
      type: array
      xml:
        name: photoUrl
        wrapped: true
      items:
        type: string
    tags:
      type: array
      xml:
        name: tag
        wrapped: true
      items:
        $ref: '#/components/schemas/Tag'
    status:
      type: string
      description: pet status in the store
      enum:
        - available
        - pending
        - sold

the Pet structure is generated this way:

// Pet A pet for sale in the pet store
type Pet struct {
Id *int64 json:"id,omitempty"
Category *Category json:"category,omitempty"
Name string json:"name"
PhotoUrls []string json:"photoUrls"
Tags *[]Tag json:"tags,omitempty"
// pet status in the store
Status *string json:"status,omitempty"
}

It implies to add manually files to reflect these enums, this decreases the interested of such generated files, hard to maintain

openapi-generator version

latest master version (does not work with previous versions as well to my knowledge)
commit 6c40192 (HEAD -> master, origin/master, origin/HEAD)
Date: Mon May 24 07:01:16 2021 +0200

OpenAPI declaration file content or url

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml

Generation Details

./run-in-docker.sh generate -i petstore.yaml -g go -o /gen/out/petstore --skip-validate-spec --package-name=ps -c config.yaml

config.yaml:

additionalProperties:
generateInterfaces: "true"
enumClassPrefix: "true"
isGoSubmodule: "true"

Steps to reproduce

generate the go files using the provided generation details and the petstore.yaml file

Related issues/PRs

This is related to this issue: #8937
but for the golang language

Suggest a fix

Instead of using a *string, generate a new dedicated type and set the possible values accordingly

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