forked from loafle/openapi-generator-original
[python-nextgen] Add type to actual instance (#16204)
* [python-nextgen] add type to actual_instance Signed-off-by: ふぁ <yuki@yuki0311.com> * [python-nextgen] update samples Signed-off-by: ふぁ <yuki@yuki0311.com> * [python-nextgen] fixed unnecessary type conversions Signed-off-by: ふぁ <yuki@yuki0311.com> * [python-nextgen] update samples Signed-off-by: ふぁ <yuki@yuki0311.com> --------- Signed-off-by: ふぁ <yuki@yuki0311.com>
This commit is contained in:
parent
adac3b127f
commit
e411b2ac0a
@ -9,7 +9,7 @@ import re # noqa: F401
|
||||
{{#vendorExtensions.x-py-model-imports}}
|
||||
{{{.}}}
|
||||
{{/vendorExtensions.x-py-model-imports}}
|
||||
from typing import Any, List
|
||||
from typing import Union, Any, List, TYPE_CHECKING
|
||||
from pydantic import StrictStr, Field
|
||||
|
||||
{{#lambda.uppercase}}{{{classname}}}{{/lambda.uppercase}}_ANY_OF_SCHEMAS = [{{#anyOf}}"{{.}}"{{^-last}}, {{/-last}}{{/anyOf}}]
|
||||
@ -23,6 +23,9 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
|
||||
# data type: {{{dataType}}}
|
||||
{{vendorExtensions.x-py-name}}: {{{vendorExtensions.x-py-typing}}}
|
||||
{{/composedSchemas.anyOf}}
|
||||
if TYPE_CHECKING:
|
||||
actual_instance: Union[{{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}]
|
||||
else:
|
||||
actual_instance: Any
|
||||
any_of_schemas: List[str] = Field({{#lambda.uppercase}}{{{classname}}}{{/lambda.uppercase}}_ANY_OF_SCHEMAS, const=True)
|
||||
|
||||
|
@ -9,7 +9,7 @@ import re # noqa: F401
|
||||
{{#vendorExtensions.x-py-model-imports}}
|
||||
{{{.}}}
|
||||
{{/vendorExtensions.x-py-model-imports}}
|
||||
from typing import Any, List
|
||||
from typing import Union, Any, List, TYPE_CHECKING
|
||||
from pydantic import StrictStr, Field
|
||||
|
||||
{{#lambda.uppercase}}{{{classname}}}{{/lambda.uppercase}}_ONE_OF_SCHEMAS = [{{#oneOf}}"{{.}}"{{^-last}}, {{/-last}}{{/oneOf}}]
|
||||
@ -22,6 +22,9 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
|
||||
# data type: {{{dataType}}}
|
||||
{{vendorExtensions.x-py-name}}: {{{vendorExtensions.x-py-typing}}}
|
||||
{{/composedSchemas.oneOf}}
|
||||
if TYPE_CHECKING:
|
||||
actual_instance: Union[{{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}]
|
||||
else:
|
||||
actual_instance: Any
|
||||
one_of_schemas: List[str] = Field({{#lambda.uppercase}}{{{classname}}}{{/lambda.uppercase}}_ONE_OF_SCHEMAS, const=True)
|
||||
|
||||
|
@ -20,7 +20,7 @@ import re # noqa: F401
|
||||
|
||||
from typing import List, Optional
|
||||
from pydantic import BaseModel, Field, StrictStr, ValidationError, conint, conlist, constr, validator
|
||||
from typing import Any, List
|
||||
from typing import Union, Any, List, TYPE_CHECKING
|
||||
from pydantic import StrictStr, Field
|
||||
|
||||
ANYOFCOLOR_ANY_OF_SCHEMAS = ["List[int]", "str"]
|
||||
@ -36,6 +36,9 @@ class AnyOfColor(BaseModel):
|
||||
anyof_schema_2_validator: Optional[conlist(conint(strict=True, le=255, ge=0), max_items=4, min_items=4)] = Field(None, description="RGBA four element array with values 0-255.")
|
||||
# data type: str
|
||||
anyof_schema_3_validator: Optional[constr(strict=True, max_length=7, min_length=7)] = Field(None, description="Hex color string, such as #00FF00.")
|
||||
if TYPE_CHECKING:
|
||||
actual_instance: Union[List[int], str]
|
||||
else:
|
||||
actual_instance: Any
|
||||
any_of_schemas: List[str] = Field(ANYOFCOLOR_ANY_OF_SCHEMAS, const=True)
|
||||
|
||||
|
@ -22,7 +22,7 @@ from typing import Optional
|
||||
from pydantic import BaseModel, Field, StrictStr, ValidationError, validator
|
||||
from petstore_api.models.basque_pig import BasquePig
|
||||
from petstore_api.models.danish_pig import DanishPig
|
||||
from typing import Any, List
|
||||
from typing import Union, Any, List, TYPE_CHECKING
|
||||
from pydantic import StrictStr, Field
|
||||
|
||||
ANYOFPIG_ANY_OF_SCHEMAS = ["BasquePig", "DanishPig"]
|
||||
@ -36,6 +36,9 @@ class AnyOfPig(BaseModel):
|
||||
anyof_schema_1_validator: Optional[BasquePig] = None
|
||||
# data type: DanishPig
|
||||
anyof_schema_2_validator: Optional[DanishPig] = None
|
||||
if TYPE_CHECKING:
|
||||
actual_instance: Union[BasquePig, DanishPig]
|
||||
else:
|
||||
actual_instance: Any
|
||||
any_of_schemas: List[str] = Field(ANYOFPIG_ANY_OF_SCHEMAS, const=True)
|
||||
|
||||
|
@ -20,7 +20,7 @@ import re # noqa: F401
|
||||
|
||||
from typing import Any, List, Optional
|
||||
from pydantic import BaseModel, Field, StrictStr, ValidationError, conint, conlist, constr, validator
|
||||
from typing import Any, List
|
||||
from typing import Union, Any, List, TYPE_CHECKING
|
||||
from pydantic import StrictStr, Field
|
||||
|
||||
COLOR_ONE_OF_SCHEMAS = ["List[int]", "str"]
|
||||
@ -35,6 +35,9 @@ class Color(BaseModel):
|
||||
oneof_schema_2_validator: Optional[conlist(conint(strict=True, le=255, ge=0), max_items=4, min_items=4)] = Field(None, description="RGBA four element array with values 0-255.")
|
||||
# data type: str
|
||||
oneof_schema_3_validator: Optional[constr(strict=True, max_length=7, min_length=7)] = Field(None, description="Hex color string, such as #00FF00.")
|
||||
if TYPE_CHECKING:
|
||||
actual_instance: Union[List[int], str]
|
||||
else:
|
||||
actual_instance: Any
|
||||
one_of_schemas: List[str] = Field(COLOR_ONE_OF_SCHEMAS, const=True)
|
||||
|
||||
|
@ -20,7 +20,7 @@ import re # noqa: F401
|
||||
|
||||
from typing import Any, List, Optional
|
||||
from pydantic import BaseModel, Field, StrictStr, ValidationError, conint, validator
|
||||
from typing import Any, List
|
||||
from typing import Union, Any, List, TYPE_CHECKING
|
||||
from pydantic import StrictStr, Field
|
||||
|
||||
INTORSTRING_ONE_OF_SCHEMAS = ["int", "str"]
|
||||
@ -33,6 +33,9 @@ class IntOrString(BaseModel):
|
||||
oneof_schema_1_validator: Optional[conint(strict=True, ge=10)] = None
|
||||
# data type: str
|
||||
oneof_schema_2_validator: Optional[StrictStr] = None
|
||||
if TYPE_CHECKING:
|
||||
actual_instance: Union[int, str]
|
||||
else:
|
||||
actual_instance: Any
|
||||
one_of_schemas: List[str] = Field(INTORSTRING_ONE_OF_SCHEMAS, const=True)
|
||||
|
||||
|
@ -22,7 +22,7 @@ from typing import Any, List, Optional
|
||||
from pydantic import BaseModel, Field, StrictStr, ValidationError, validator
|
||||
from petstore_api.models.enum_string1 import EnumString1
|
||||
from petstore_api.models.enum_string2 import EnumString2
|
||||
from typing import Any, List
|
||||
from typing import Union, Any, List, TYPE_CHECKING
|
||||
from pydantic import StrictStr, Field
|
||||
|
||||
ONEOFENUMSTRING_ONE_OF_SCHEMAS = ["EnumString1", "EnumString2"]
|
||||
@ -35,6 +35,9 @@ class OneOfEnumString(BaseModel):
|
||||
oneof_schema_1_validator: Optional[EnumString1] = None
|
||||
# data type: EnumString2
|
||||
oneof_schema_2_validator: Optional[EnumString2] = None
|
||||
if TYPE_CHECKING:
|
||||
actual_instance: Union[EnumString1, EnumString2]
|
||||
else:
|
||||
actual_instance: Any
|
||||
one_of_schemas: List[str] = Field(ONEOFENUMSTRING_ONE_OF_SCHEMAS, const=True)
|
||||
|
||||
|
@ -22,7 +22,7 @@ from typing import Any, List, Optional
|
||||
from pydantic import BaseModel, Field, StrictStr, ValidationError, validator
|
||||
from petstore_api.models.basque_pig import BasquePig
|
||||
from petstore_api.models.danish_pig import DanishPig
|
||||
from typing import Any, List
|
||||
from typing import Union, Any, List, TYPE_CHECKING
|
||||
from pydantic import StrictStr, Field
|
||||
|
||||
PIG_ONE_OF_SCHEMAS = ["BasquePig", "DanishPig"]
|
||||
@ -35,6 +35,9 @@ class Pig(BaseModel):
|
||||
oneof_schema_1_validator: Optional[BasquePig] = None
|
||||
# data type: DanishPig
|
||||
oneof_schema_2_validator: Optional[DanishPig] = None
|
||||
if TYPE_CHECKING:
|
||||
actual_instance: Union[BasquePig, DanishPig]
|
||||
else:
|
||||
actual_instance: Any
|
||||
one_of_schemas: List[str] = Field(PIG_ONE_OF_SCHEMAS, const=True)
|
||||
|
||||
|
@ -20,7 +20,7 @@ import re # noqa: F401
|
||||
|
||||
from typing import List, Optional
|
||||
from pydantic import BaseModel, Field, StrictStr, ValidationError, conint, conlist, constr, validator
|
||||
from typing import Any, List
|
||||
from typing import Union, Any, List, TYPE_CHECKING
|
||||
from pydantic import StrictStr, Field
|
||||
|
||||
ANYOFCOLOR_ANY_OF_SCHEMAS = ["List[int]", "str"]
|
||||
@ -36,6 +36,9 @@ class AnyOfColor(BaseModel):
|
||||
anyof_schema_2_validator: Optional[conlist(conint(strict=True, le=255, ge=0), max_items=4, min_items=4)] = Field(None, description="RGBA four element array with values 0-255.")
|
||||
# data type: str
|
||||
anyof_schema_3_validator: Optional[constr(strict=True, max_length=7, min_length=7)] = Field(None, description="Hex color string, such as #00FF00.")
|
||||
if TYPE_CHECKING:
|
||||
actual_instance: Union[List[int], str]
|
||||
else:
|
||||
actual_instance: Any
|
||||
any_of_schemas: List[str] = Field(ANYOFCOLOR_ANY_OF_SCHEMAS, const=True)
|
||||
|
||||
|
@ -22,7 +22,7 @@ from typing import Optional
|
||||
from pydantic import BaseModel, Field, StrictStr, ValidationError, validator
|
||||
from petstore_api.models.basque_pig import BasquePig
|
||||
from petstore_api.models.danish_pig import DanishPig
|
||||
from typing import Any, List
|
||||
from typing import Union, Any, List, TYPE_CHECKING
|
||||
from pydantic import StrictStr, Field
|
||||
|
||||
ANYOFPIG_ANY_OF_SCHEMAS = ["BasquePig", "DanishPig"]
|
||||
@ -36,6 +36,9 @@ class AnyOfPig(BaseModel):
|
||||
anyof_schema_1_validator: Optional[BasquePig] = None
|
||||
# data type: DanishPig
|
||||
anyof_schema_2_validator: Optional[DanishPig] = None
|
||||
if TYPE_CHECKING:
|
||||
actual_instance: Union[BasquePig, DanishPig]
|
||||
else:
|
||||
actual_instance: Any
|
||||
any_of_schemas: List[str] = Field(ANYOFPIG_ANY_OF_SCHEMAS, const=True)
|
||||
|
||||
|
@ -20,7 +20,7 @@ import re # noqa: F401
|
||||
|
||||
from typing import Any, List, Optional
|
||||
from pydantic import BaseModel, Field, StrictStr, ValidationError, conint, conlist, constr, validator
|
||||
from typing import Any, List
|
||||
from typing import Union, Any, List, TYPE_CHECKING
|
||||
from pydantic import StrictStr, Field
|
||||
|
||||
COLOR_ONE_OF_SCHEMAS = ["List[int]", "str"]
|
||||
@ -35,6 +35,9 @@ class Color(BaseModel):
|
||||
oneof_schema_2_validator: Optional[conlist(conint(strict=True, le=255, ge=0), max_items=4, min_items=4)] = Field(None, description="RGBA four element array with values 0-255.")
|
||||
# data type: str
|
||||
oneof_schema_3_validator: Optional[constr(strict=True, max_length=7, min_length=7)] = Field(None, description="Hex color string, such as #00FF00.")
|
||||
if TYPE_CHECKING:
|
||||
actual_instance: Union[List[int], str]
|
||||
else:
|
||||
actual_instance: Any
|
||||
one_of_schemas: List[str] = Field(COLOR_ONE_OF_SCHEMAS, const=True)
|
||||
|
||||
|
@ -20,7 +20,7 @@ import re # noqa: F401
|
||||
|
||||
from typing import Any, List, Optional
|
||||
from pydantic import BaseModel, Field, StrictStr, ValidationError, conint, validator
|
||||
from typing import Any, List
|
||||
from typing import Union, Any, List, TYPE_CHECKING
|
||||
from pydantic import StrictStr, Field
|
||||
|
||||
INTORSTRING_ONE_OF_SCHEMAS = ["int", "str"]
|
||||
@ -33,6 +33,9 @@ class IntOrString(BaseModel):
|
||||
oneof_schema_1_validator: Optional[conint(strict=True, ge=10)] = None
|
||||
# data type: str
|
||||
oneof_schema_2_validator: Optional[StrictStr] = None
|
||||
if TYPE_CHECKING:
|
||||
actual_instance: Union[int, str]
|
||||
else:
|
||||
actual_instance: Any
|
||||
one_of_schemas: List[str] = Field(INTORSTRING_ONE_OF_SCHEMAS, const=True)
|
||||
|
||||
|
@ -22,7 +22,7 @@ from typing import Any, List, Optional
|
||||
from pydantic import BaseModel, Field, StrictStr, ValidationError, validator
|
||||
from petstore_api.models.enum_string1 import EnumString1
|
||||
from petstore_api.models.enum_string2 import EnumString2
|
||||
from typing import Any, List
|
||||
from typing import Union, Any, List, TYPE_CHECKING
|
||||
from pydantic import StrictStr, Field
|
||||
|
||||
ONEOFENUMSTRING_ONE_OF_SCHEMAS = ["EnumString1", "EnumString2"]
|
||||
@ -35,6 +35,9 @@ class OneOfEnumString(BaseModel):
|
||||
oneof_schema_1_validator: Optional[EnumString1] = None
|
||||
# data type: EnumString2
|
||||
oneof_schema_2_validator: Optional[EnumString2] = None
|
||||
if TYPE_CHECKING:
|
||||
actual_instance: Union[EnumString1, EnumString2]
|
||||
else:
|
||||
actual_instance: Any
|
||||
one_of_schemas: List[str] = Field(ONEOFENUMSTRING_ONE_OF_SCHEMAS, const=True)
|
||||
|
||||
|
@ -22,7 +22,7 @@ from typing import Any, List, Optional
|
||||
from pydantic import BaseModel, Field, StrictStr, ValidationError, validator
|
||||
from petstore_api.models.basque_pig import BasquePig
|
||||
from petstore_api.models.danish_pig import DanishPig
|
||||
from typing import Any, List
|
||||
from typing import Union, Any, List, TYPE_CHECKING
|
||||
from pydantic import StrictStr, Field
|
||||
|
||||
PIG_ONE_OF_SCHEMAS = ["BasquePig", "DanishPig"]
|
||||
@ -35,6 +35,9 @@ class Pig(BaseModel):
|
||||
oneof_schema_1_validator: Optional[BasquePig] = None
|
||||
# data type: DanishPig
|
||||
oneof_schema_2_validator: Optional[DanishPig] = None
|
||||
if TYPE_CHECKING:
|
||||
actual_instance: Union[BasquePig, DanishPig]
|
||||
else:
|
||||
actual_instance: Any
|
||||
one_of_schemas: List[str] = Field(PIG_ONE_OF_SCHEMAS, const=True)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user