Skip to content

Naming issue with negative integers in enums #185

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

Closed
rweinberger opened this issue Sep 9, 2020 · 1 comment
Closed

Naming issue with negative integers in enums #185

rweinberger opened this issue Sep 9, 2020 · 1 comment
Labels
🐞bug Something isn't working
Milestone

Comments

@rweinberger
Copy link

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

@rweinberger rweinberger added the 🐞bug Something isn't working label Sep 9, 2020
@dbanty dbanty added this to the 0.6.0 milestone Sep 10, 2020
@dbanty
Copy link
Collaborator

dbanty commented Sep 10, 2020

When you get a chance, please try out 0.6.0-alpha.4 which should include the fix. If it works you can go ahead and close this issue.

@dbanty dbanty closed this as completed in feeccda Sep 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants