Skip to content

Generating variable names for enums fail in some cases #1239

@vegardb

Description

@vegardb

Generating code for the below document fails on the enum:

% go run oapi-codegen.go -generate types test.yaml
...
<some output>
...
: test.go:46:4: 'P' exponent requires hexadecimal mantissa (and 5 more errors)
exit status 1

It seems the reason is that the typeNamePrefix function in utils.go does not handle > or <, followed by a number. Also, the error message is different if you replace pepper below with anything not starting with p.

openapi: 3.0.0
info:
  description: Find error in generation
  version: 1.0.0
  title: Error
paths:
  /api:
    get:
      summary: Do stuff
      responses:
        "200":
          $ref: '#/components/responses/SomeResponse'
components:
  responses:
    SomeResponse:
      description: some response
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SomeSchema'
  schemas:
    SomeSchema:
      type: object
      properties:
        some_enum:
          type: string
          enum:
            - '>23 pepper'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions