OpenAPITools / OpenAPITools/openapi-generator

[BUG][GO] Enums not generated

Open
#9,567 7 comments 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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 6c40192706cf95329f03e4c80ea628fb32a8ecab (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: https://github.com/OpenAPITools/openapi-generator/issues/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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked petstore.yaml and config.yaml, then run the documented Go generation command to reproduce the generated Pet struct. Compare the status field with the requested dedicated enum type and rerun generation to confirm the generated files represent the declared values without manual additions.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.