Skip to content

[BUG] Python Generator: '€' symbol in enum generates invalid code #22413

@rubenhoenle

Description

@rubenhoenle

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Euro symbol in enum creates invalid code.

openapi-generator version

v7.17.0 (latest)

OpenAPI declaration file content or url
openapi: 3.1.0
info:
  version: 0.1.0
  title: ''
  description: ''
components:
  schemas:
    Currency:
      type: string
      enum:
        - "$"
        - ""
Generation Details
# build openapi generator from source
./mvnw clean install
# generate python code
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate --generator-name python --input-spec spec.yaml --output "euro-fix-output"
Steps to reproduce

Look into euro-fix-output/openapi_client/models/currency.py. The generated enum looks like this:

class Currency(str, Enum):
    """
    Currency
    """

    """
    allowed enum values
    """
    DOLLAR = '$'= '€' # <------------- this is causing problems

    @classmethod
    def from_json(cls, json_str: str) -> Self:
        """Create an instance of Currency from a JSON string"""
        return cls(json.loads(json_str))

Instead it should look like this:

class Currency(str, Enum):
    """
    Currency
    """

    """
    allowed enum values
    """
    DOLLAR = '$'
    EURO = '€' # <------------- expected code

    @classmethod
    def from_json(cls, json_str: str) -> Self:
        """Create an instance of Currency from a JSON string"""
        return cls(json.loads(json_str))
Related issues/PRs
Suggest a fix

Will contribute it 😄

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions