OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.24k stars 6.43k forks source link

[BUG] [GOLANG] Nil property fields #10750

Open skiarn opened 2 years ago

skiarn commented 2 years ago

Bug Report Checklist

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
optimus-kart commented 2 years ago

Any updates on this? is there a workaround?

igr commented 2 years ago

Could you check the versions? My case is the following:

igr commented 2 years ago

btw it is so unbelievable that there is no at least a simple test that will generate API and compile it.