OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Golang] anyOf results in empty Go struct

Open
#2,164 10 comments 7 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 Go model code is generated for an "anyOf" type then the result will be an empty struct.

Yaml:

RatType:
anyOf:
- type: string
enum:
- NR
- EUTRA
- WLAN
- VIRTUAL
- type: string

Actual:
type RatType struct { }

Expected:

package openapi
type RatType string

// List of RatType
const (
  NR RatType = "NR"
  EUTRA RatType = "EUTRA"
  WLAN RatType = "WLAN"
  VIRTUAL RatType = "VIRTUAL"
)
openapi-generator version

4.0.0-SNAPSHOT

OpenAPI declaration file content or url

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

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

Command line used for generation

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

Steps to reproduce
./run-in-docker.sh generate -i 5GC_APIs/TS29518_Namf_MT.yaml -g go -o /gen/out -Dmodels

cat out/model_rat_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 provided run-in-docker.sh command and inspect out/model_rat_type.go. Compare the generated result with the RatType declaration and the linked OpenAPI YAML entries. Done means the Go generator no longer emits an empty struct and produces the expected string type and enum constants.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.