OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Golang] unexported name is generated for enum

Open
#2,050 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

When I generate Go model code for an enum where a value starts with a number then the generated const will be unexported.

Actual:
// List of AccessType
const (
_3_GPP_ACCESS AccessType = "3GPP_ACCESS"
NON_3_GPP_ACCESS AccessType = "NON_3GPP_ACCESS"
)

Expected e.g.:
// List of AccessType
const (
ACCESS_TYPE_3_GPP_ACCESS AccessType = "3GPP_ACCESS"
ACCESS_TYPE_NON_3_GPP_ACCESS AccessType = "NON_3GPP_ACCESS"
)

Input validation:

docker run --rm -it -w /gen -e GEN_DIR=/gen -e MAVEN_CONFIG=/var/maven/.m2 -u 0:0 -v /ephemeral/opentas/openapi-generator:/gen -v /root/.m2:/root/.m2 --entrypoint /gen/docker-entrypoint.sh maven:3-jdk-8 validate -i 5GC_APIs/TS29122_CommonData.yaml
Validating spec (5GC_APIs/TS29122_CommonData.yaml)
No validation issues detected.

docker run --rm -it -w /gen -e GEN_DIR=/gen -e MAVEN_CONFIG=/var/maven/.m2 -u 0:0 -v /ephemeral/opentas/openapi-generator:/gen -v /root/.m2:/root/.m2 --entrypoint /gen/docker-entrypoint.sh maven:3-jdk-8 validate -i 5GC_APIs/TS29518_Namf_MT.yaml
Validating spec (5GC_APIs/TS29518_Namf_MT.yaml)
No validation issues detected.

openapi-generator version

4.0.0-SNAPSHOT

OpenAPI declaration file content or url

Type:
https://github.com/jdegre/5GC_APIs/blob/7298845c7ede07038838d5c40debb083f929f98b/TS29571_CommonData.yaml#L537

**AccessType:
  type: string
  enum:
    - 3GPP_ACCESS
    - NON_3GPP_ACCESS**

Service:
https://github.com/jdegre/5GC_APIs/blob/78b04e48a7fb92b1a5dc6f95419c9ed2f6c3c5ed/TS29518_Namf_MT.yaml#L164

Command line used for generation

./run-in-docker.sh generate -i 5GC_APIs/TS29518_Namf_MT.yam -g go -o /gen/out -Dmodels

Steps to reproduce

./run-in-docker.sh generate -i 5GC_APIs/TS29518_Namf_MT.yam -g go -o /gen/out -Dmodels
cat out/model_access_type.go

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

Reproduce the issue with the listed run-in-docker.sh generate command and inspect out/model_access_type.go for the AccessType enum. Trace the Go generator path that derives names from enum values beginning with a number, then confirm the generated constants are exported and retain the expected string values.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.