[BUG] Error transforming enum values beginning with numbers #400
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- 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
Description
Invalid generated function names base on enum values beginning with a number like 2D_Object
. This enum will be transformed to:
# coding: utf-8
"""
the test title
The test REST API # noqa: E501
The version of the OpenAPI document: 1
Generated by: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator
"""
from __future__ import annotations
from openapi_client.shared_imports.schema_imports import * # pyright: ignore [reportWildcardImportFromLibrary]
class AnnotationTypeEnums:
@schemas.classproperty
def 2D_OBJECT(cls) -> typing.Literal["2D_Object"]:
return AnnotationType.validate("2D_Object")
@schemas.classproperty
def 3D_OBJECT(cls) -> typing.Literal["3D_Object"]:
return AnnotationType.validate("3D_Object")
@dataclasses.dataclass(frozen=True)
class AnnotationType(
schemas.Schema
):
"""NOTE: This class is auto generated by OpenAPI JSON Schema Generator.
Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator
Do not edit the class manually.
"""
types: typing.FrozenSet[typing.Type] = frozenset({
str,
})
enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.Bool, None], str] = dataclasses.field(
default_factory=lambda: {
"2D_Object": "2D_OBJECT",
"3D_Object": "3D_OBJECT",
}
)
enums = AnnotationTypeEnums
@typing.overload
@classmethod
def validate(
cls,
arg: typing.Literal["2D_Object"],
configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None
) -> typing.Literal["2D_Object"]: ...
@typing.overload
@classmethod
def validate(
cls,
arg: typing.Literal["3D_Object"],
configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None
) -> typing.Literal["3D_Object"]: ...
@typing.overload
@classmethod
def validate(
cls,
arg: str,
configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None
) -> typing.Literal["2D_Object","3D_Object",]: ...
@classmethod
def validate(
cls,
arg,
configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None
) -> typing.Literal[
"2D_Object",
"3D_Object",
]:
validated_arg = super().validate_base(
arg,
configuration=configuration,
)
return typing.cast(typing.Literal[
"2D_Object",
"3D_Object",
],
validated_arg
)
The resulting function name is not a valid Python name.
I know that this issue mention the same problem which is apparently fixed but it still not working in my case.
openapi-json-schema-generator version
Current master branch
OpenAPI declaration file content or url
openapi: 3.0.0
components:
examples: {}
headers: {}
parameters: {}
requestBodies: {}
responses: {}
schemas:
AnnotationType:
enum:
- 2D_Object
- 3D_Object
type: string
info:
title: the test title
version: '1'
description: 'The test REST API'
contact: {}
paths:
'/example/get':
get:
operationId: GetExample
responses:
'200':
description: Ok
Generation Details
I I build the corresponding .jar
file based on the current master branch via the command mvn clean install
and used the following command to generate the python client:
java -jar target/openapi-json-schema-generator-cli.jar generate -i /home/marcel/Documents/arbeit_projekte/openapi_generator_tests/openapi_reduced.yaml -g python -o /home/marcel/Documents/arbeit_projekte/openapi_generator_tests/reduced_spec --skip-validate-spec --additional-properties=generateAliasAsModel=true
Java version: 11.0.22
Apache Maven: 3.9.6
Steps to reproduce
- Use the provided
yaml
file to generate the python client - Check the schema file for the
AnnotationType