OpenAPITools / OpenAPITools/openapi-generator
[BUG][GO] Enums not generated
Nobody has claimed this yet.
- 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 *int64json:"id,omitempty"
Category *Categoryjson:"category,omitempty"
Name stringjson:"name"
PhotoUrls []stringjson:"photoUrls"
Tags *[]Tagjson:"tags,omitempty"
// pet status in the store
Status *stringjson:"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
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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