Skip to content

Naming issue with negative integers in enums #185

@rweinberger

Description

@rweinberger

Describe the bug
Including negative integers in enums results in model class variables with invalid Python names. For example, this schema snippet:

    IntegerTest:
      type: object
      properties:
        test:
          type: integer
          enum: [1, -1]

will produce a model class:

class Test(IntEnum):
    VALUE_1 = 1
    VALUE_-1 = -1

where VALUE_-1 as a variable name will result in Python errors.

To Reproduce
openapi-python-client generate --path path/to/openapi.yaml, where the spec contains an enum with negative integers in a schema

Expected behavior
Expected negative integers in enums to result in valid variable names in model classes.

OpenAPI Spec File
https://gist.github.com/rweinberger/3fec7b999dc9f4659f28ce3be7c13193

Desktop (please complete the following information):

  • OS: macOS 10.15.4
  • Python Version: 3.8.0
  • openapi-python-client version: 0.6.0-alpha.3

A potential solution for this would be to adjust naming for negative integers to handle the hyphen, i.e. instead of -1 becoming VALUE_-1, have it become VALUE_NEGATIVE_1.

cc @dtkav

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐞bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions