Skip to content

Error building code generated with enum values as digits #341

@IvanRN

Description

@IvanRN

If there are numbers in enum values generated code is impossible to build.
yaml example:

openapi: 3.0.2

info:
  title: ...
  version: 0.0.0

paths:
  /foo:
    get:
      responses:
        200:
          description: ...
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Bar'

components:
  schemas:
    Bar:
      type: string
      enum: 
        - 1
        - Foo
        - Bar
        - Foo Bar
        - Foo-Bar
        - 1Foo
        - Bar
        - ' Foo'
        - ' Foo '
        - _Foo_

The issue is related due to enum values map generator.
To be percise the problem appears here:
sanitized := SchemaNameToTypeName(SanitizeGoIdentity(n))
it may be related to @vlastahajek fix #241

Result code for the above yaml will have:

const (
	Bar = "1"
	...

and

// Bar defines model for Bar.
type Bar string

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