Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GO] Invalid code generated when enum contains integers #11615

Closed
will-in-wi opened this issue Dec 30, 2021 · 0 comments · Fixed by #12076
Closed

[GO] Invalid code generated when enum contains integers #11615

will-in-wi opened this issue Dec 30, 2021 · 0 comments · Fixed by #12076

Comments

@will-in-wi
Copy link

Description

Per the Golang spec, the first character in an identifier must be a letter. When an enum contains strings which are numbers (as in IP versions), these are interpolated into invalid code.

Swagger-codegen version

3.0.30

Swagger declaration file content or url
openapi: 3.0.3
info:
  title: Test
  version: 1.0.0
paths:
  /test/:
    post:
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/IPAddressTypeEnum'
          description: null
components:
  schemas:
    IPAddressTypeEnum:
      enum:
      - '4'
      - '6'
      type: string
Command line used for generation
swagger-codegen generate -i ../schema.yml -l go
Steps to reproduce

Save above schema into file, run the command in an empty folder, and take a look at model_ip_address_type_enum.go. The identifiers start with numbers, which isn't valid in Go.

// List of IPAddressTypeEnum
const (
	4__IpAddressTypeEnum IpAddressTypeEnum = "4"
	6__IpAddressTypeEnum IpAddressTypeEnum = "6"
)
Suggest a fix/enhancement

I'm not really sure what the best approach would be. In my specific case, I'm manually changing them to v4 and v6. Maybe prepending an i for i4 and i6 to indicate integer? It isn't especially pretty either way.

I'm new to this codebase, so if I'm doing something weirdly or misunderstanding the purpose of something, please set me on the right track. Thank you all so much for your work on this project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant