OpenAPITools / OpenAPITools/openapi-generator
[BUG] [GOLANG] Nil property fields
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
I noticed a change while using docker image openapitools/openapi-generator-cli:v5.2.1 => openapitools/openapi-generator-cli:v5.3.0.
What is expected behaviour? In docker image version 5.3.0 I want to generate following code State *ExampleState `json:"state,omitempty"
openapi-generator version
openapitools/openapi-generator-cli:v5.2.1
vs
openapitools/openapi-generator-cli:v5.3.0
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: Example
version: '0.1'
description: |-
servers:
- url: 'https://example.com'
description: prod
paths:
/example:
get:
operationId: example
summary: example
description: GO *pointers behaves differently, models is different between versions
responses:
'200':
$ref: '#/components/responses/ExampleResponse'
components:
schemas:
Example:
title: Example
type: object
description: ''
properties:
id:
type: string
format: uuid
readOnly: true
description: ''
state:
readOnly: true
allOf:
- $ref: '#/components/schemas/ExampleState'
required:
- id
ExampleState:
title: ExampleState
type: string
description: ''
enum:
- A
- B
- C
responses:
ExampleResponse:
description: A list of examples
content:
application/json:
schema:
title: Examples
type: object
description: Response structure of the list examples request
properties:
examples:
type: array
items:
$ref: '#/components/schemas/Example'
Example:
description: Example response
content:
application/json:
schema:
$ref: '#/components/schemas/Example'
Generation Details
Steps to reproduce
docker run --rm
--volume "/Users/xx/openapi-generator-cli:/local"
--user "1001:121"
openapitools/openapi-generator-cli:v5.2.1
generate
--input-spec /local/openapi.yaml
--global-property models,modelDocs=false
--generator-name go
--additional-properties packageName=models
--output /local/models
v5.2.1 Generate:
// Example struct for Example
type Example struct {
Id string json:"id"
State *ExampleState json:"state,omitempty"
}
docker run --rm
--volume "/Users/xx/openapi-generator-cli:/local"
--user "1001:121"
openapitools/openapi-generator-cli:v5.3.0
generate
--input-spec /local/openapi.yaml
--global-property models,modelDocs=false
--generator-name go
--additional-properties packageName=models
--output /local/models
v5.3.0 Generate:
// Example struct for Example
type Example struct {
Id string json:"id"
State ExampleState json:"state,omitempty"
}
Suggest a fix
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 supplied OpenAPI declaration and the docker generate commands for the Go generator, comparing the generated Example model between v5.2.1 and v5.3.0. Done means the state field is generated with the expected pointer type while preserving the reproduction's other output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, go
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100