oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

snake case and pascal case openapi properties can result in duplicate fields being generated

Open daviditkin opened this issue 1 year ago • 0 comments

  • The version of oapi-codegen you're using: v2.3.0

  • The YAML configuration file you're using:

package: duplicateFieldBug
generate:
  echo-server: true
  client: true
  models: true
  embedded-spec: true
  • The OpenAPI spec you're using:
openapi: 3.0.3
info:
  title: Duplicate Field Name Minimum Reproducible Example
  version: 1.0.0
paths:
  /foo:
    get:
      summary: Get a Foo object
      responses:
        '200':
          description: A Foo object
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Foo'
components:
  schemas:
    Foo:
      type: object
      properties:
        name_clash:
          type: string
        NameClash:
          type: string

  • What problem you're seeing: The generated go defines a struct with duplicate fields:
...
// Foo defines model for Foo.
type Foo struct {
        NameClash *string `json:"NameClash,omitempty"`
        NameClash *string `json:"name_clash,omitempty"`
}
...
  • What the expected behaviour is: Error message would be useful.

  • What version of Go you're using: go version go1.23.0 darwin/arm6

Workaround is to use x-go-name to specify unambiguous go field names, but it would be useful if the generator showed an error message.

daviditkin avatar Sep 10 '24 14:09 daviditkin