OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Go] The omitEmpty json tag is not generated for oneOf fields.
Open
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?
- 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?
Actual:
type Variant struct {
VariantA *VariantA
VariantB *VariantB
}
Expected:
type Variant struct {
VariantA *VariantA `json:"variantA,omitempty"`
VariantB *VariantB `json:"variantB,omitempty"`
}
Description
The omitEmpty json tag is not generated for oneOf fields.
openapi-generator version
7.14.0
OpenAPI declaration file content
openapi: 3.0.0
info:
title: Variant API
version: 1.0.0
paths:
/variant:
get:
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Variant'
components:
schemas:
Variant:
oneOf:
- $ref: '#/components/schemas/VariantA'
- $ref: '#/components/schemas/VariantB'
VariantA:
type: object
properties:
optionA:
$ref: '#/components/schemas/OptionA'
required:
- optionA
VariantB:
type: object
properties:
optionB:
$ref: '#/components/schemas/OptionB'
required:
- optionB
OptionA:
type: object
properties:
exampleField:
type: string
OptionB:
type: object
properties:
exampleField:
type: string
Generation Details
The command to generate the code:
docker run --rm \
-v ${PWD}:/local \
openapitools/openapi-generator-cli generate \
-i /local/openapi.yaml \
-g go \
-o /local/out/go-client
Steps to reproduce
See 'Generation Details'
Related issues/PRs
n/a
Suggest a fix
n/a
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 by running the documented Docker generation command with the supplied openapi.yaml and inspect the generated Go Variant struct. Compare the oneOf fields with the expected output; done means the generated fields include the appropriate json tags with omitempty.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100