MarcoMuellner / openapi-python-generator

A client generator from openapi for python.
MIT License
57 stars 26 forks source link

Can't Read Dash(-) in Enum #30

Open amyfelicia opened 1 year ago

amyfelicia commented 1 year ago

Describe the bug Hi I'm trying to use the generator to translate some enums. I have a few enums and some were successfully generated and some didn't. I realised that the ones that caused an error has dash in it. Here are 2 examples:

"components": {
    "schemas": {
      "AWSRegions": {
        "type": "string",
        "enum": [
          "us-east-1",
          "us-west-1",
          "us-west-2",
          "eu-central-1",
          "eu-west-1",
          "ap-southeast-1",
          "ap-southeast-2"
        ]
      },
      "AWSStatus": {
        "type": "string",
        "enum": [
          "available",
          "backing-up",
          "creating",
          "deleting",
          "failed",
          "inaccessible-encryption-credentials",
          "inaccessible-encryption-credentials-recoverable",
          "configuring-enhanced-monitoring",
          "maintenance",
          "modifying",
          "rebooting",
          "renaming",
          "starting",
          "stopping",
          "stopped",
          "storage-full",
          "storage-optimization",
          "upgrading"
        ]
      },

This is the error message:

Error in model AWSRegions: cannot assign to expression here. Maybe you meant '==' instead of '='? (<string>, line 5)
Error in model AWSStatus: cannot assign to expression here. Maybe you meant '==' instead of '='? (<string>, line 6)

To Reproduce You can create any OpenAPI JSON specs with the enums I provided and run the openapi-python-generator

Expected behavior I expect the enum to be created like any other enums

Desktop (please complete the following information):

MarcoMuellner commented 1 year ago

Can you provide an openapi.json file?

jstasiak commented 6 months ago

I just bumped into this. A minimal example to reproduce the problem:

{
    "openapi": "3.0.1",
    "info": {
        "version": "1.0",
        "title": "Title"
    },
    "components": {
        "schemas": {
            "Registry": {
                "type": "string",
                "enum": [
                    "A",
                    "B-B"
                ]
            }
        }
    }
}

The error:

% openapi-python-generator mini.json output
Generating data from mini.json
Error in model Registry: cannot assign to expression here. Maybe you meant '==' instead of '='? (<string>, line 6)