diff --git a/modules/openapi-generator/src/main/resources/python-fastapi/model_generic.mustache b/modules/openapi-generator/src/main/resources/python-fastapi/model_generic.mustache index 3b01c4fa9ab8..41354ee62410 100644 --- a/modules/openapi-generator/src/main/resources/python-fastapi/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/python-fastapi/model_generic.mustache @@ -69,11 +69,11 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{/required}} {{#isArray}} for i in value: - if i not in ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}): + if i not in ({{#allowableValues}}{{#enumVars}}{{{value}}},{{^-last}} {{/-last}}{{/enumVars}}{{/allowableValues}}): raise ValueError("each list item must be one of ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}})") {{/isArray}} {{^isArray}} - if value not in ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}): + if value not in ({{#allowableValues}}{{#enumVars}}{{{value}}},{{^-last}} {{/-last}}{{/enumVars}}{{/allowableValues}}): raise ValueError("must be one of enum values ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}})") {{/isArray}} return value diff --git a/modules/openapi-generator/src/main/resources/python-pydantic-v1/model_generic.mustache b/modules/openapi-generator/src/main/resources/python-pydantic-v1/model_generic.mustache index 9a5b0c7fe8fc..a9ba41b394a9 100644 --- a/modules/openapi-generator/src/main/resources/python-pydantic-v1/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/python-pydantic-v1/model_generic.mustache @@ -74,11 +74,11 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{/required}} {{#isArray}} for i in value: - if i not in ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}): + if i not in ({{#allowableValues}}{{#enumVars}}{{{value}}},{{^-last}} {{/-last}}{{/enumVars}}{{/allowableValues}}): raise ValueError("each list item must be one of ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}})") {{/isArray}} {{^isArray}} - if value not in ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}): + if value not in ({{#allowableValues}}{{#enumVars}}{{{value}}},{{^-last}} {{/-last}}{{/enumVars}}{{/allowableValues}}): raise ValueError("must be one of enum values ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}})") {{/isArray}} return value diff --git a/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml index bd071a0b132d..c647aa74f4d8 100644 --- a/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml @@ -2124,6 +2124,15 @@ components: - FOOVar - BarVar - bazVar + enum_string_single_member: + type: string + enum: + - 'abc' + enum_integer_single_member: + type: integer + format: int32 + enum: + - 100 outerEnum: $ref: '#/components/schemas/OuterEnum' outerEnumInteger: diff --git a/samples/client/echo_api/python-pydantic-v1/openapi_client/models/default_value.py b/samples/client/echo_api/python-pydantic-v1/openapi_client/models/default_value.py index a73193247fd1..e038747ba4eb 100644 --- a/samples/client/echo_api/python-pydantic-v1/openapi_client/models/default_value.py +++ b/samples/client/echo_api/python-pydantic-v1/openapi_client/models/default_value.py @@ -44,7 +44,7 @@ def array_string_enum_default_validate_enum(cls, value): return value for i in value: - if i not in ('success', 'failure', 'unclassified'): + if i not in ('success', 'failure', 'unclassified',): raise ValueError("each list item must be one of ('success', 'failure', 'unclassified')") return value diff --git a/samples/client/echo_api/python-pydantic-v1/openapi_client/models/pet.py b/samples/client/echo_api/python-pydantic-v1/openapi_client/models/pet.py index 26832037b0e3..1d26ea28a588 100644 --- a/samples/client/echo_api/python-pydantic-v1/openapi_client/models/pet.py +++ b/samples/client/echo_api/python-pydantic-v1/openapi_client/models/pet.py @@ -42,7 +42,7 @@ def status_validate_enum(cls, value): if value is None: return value - if value not in ('available', 'pending', 'sold'): + if value not in ('available', 'pending', 'sold',): raise ValueError("must be one of enum values ('available', 'pending', 'sold')") return value diff --git a/samples/client/echo_api/python-pydantic-v1/openapi_client/models/query.py b/samples/client/echo_api/python-pydantic-v1/openapi_client/models/query.py index 43919c0f569d..b86d0fc09f85 100644 --- a/samples/client/echo_api/python-pydantic-v1/openapi_client/models/query.py +++ b/samples/client/echo_api/python-pydantic-v1/openapi_client/models/query.py @@ -37,7 +37,7 @@ def outcomes_validate_enum(cls, value): return value for i in value: - if i not in ('SUCCESS', 'FAILURE', 'SKIPPED'): + if i not in ('SUCCESS', 'FAILURE', 'SKIPPED',): raise ValueError("each list item must be one of ('SUCCESS', 'FAILURE', 'SKIPPED')") return value diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/EnumTest.md b/samples/openapi3/client/petstore/python-aiohttp/docs/EnumTest.md index 72f5fbdae230..8a3874d17375 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/EnumTest.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/EnumTest.md @@ -12,6 +12,8 @@ Name | Type | Description | Notes **enum_number** | **float** | | [optional] **enum_number_vendor_ext** | **int** | | [optional] **enum_string_vendor_ext** | **str** | | [optional] +**enum_string_single_member** | **str** | | [optional] +**enum_integer_single_member** | **int** | | [optional] **outer_enum** | [**OuterEnum**](OuterEnum.md) | | [optional] **outer_enum_integer** | [**OuterEnumInteger**](OuterEnumInteger.md) | | [optional] **outer_enum_default_value** | [**OuterEnumDefaultValue**](OuterEnumDefaultValue.md) | | [optional] [default to OuterEnumDefaultValue.PLACED] diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_test.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_test.py index bbbc4102de45..8d524d96f440 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_test.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_test.py @@ -37,11 +37,13 @@ class EnumTest(BaseModel): enum_number: Optional[float] = None enum_number_vendor_ext: Optional[StrictInt] = None enum_string_vendor_ext: Optional[StrictStr] = None + enum_string_single_member: Optional[StrictStr] = None + enum_integer_single_member: Optional[StrictInt] = None outer_enum: Optional[OuterEnum] = Field(default=None, alias="outerEnum") outer_enum_integer: Optional[OuterEnumInteger] = Field(default=None, alias="outerEnumInteger") outer_enum_default_value: Optional[OuterEnumDefaultValue] = Field(default=OuterEnumDefaultValue.PLACED, alias="outerEnumDefaultValue") outer_enum_integer_default_value: Optional[OuterEnumIntegerDefaultValue] = Field(default=OuterEnumIntegerDefaultValue.NUMBER_0, alias="outerEnumIntegerDefaultValue") - __properties: ClassVar[List[str]] = ["enum_string", "enum_string_required", "enum_integer_default", "enum_integer", "enum_number", "enum_number_vendor_ext", "enum_string_vendor_ext", "outerEnum", "outerEnumInteger", "outerEnumDefaultValue", "outerEnumIntegerDefaultValue"] + __properties: ClassVar[List[str]] = ["enum_string", "enum_string_required", "enum_integer_default", "enum_integer", "enum_number", "enum_number_vendor_ext", "enum_string_vendor_ext", "enum_string_single_member", "enum_integer_single_member", "outerEnum", "outerEnumInteger", "outerEnumDefaultValue", "outerEnumIntegerDefaultValue"] @field_validator('enum_string') def enum_string_validate_enum(cls, value): @@ -110,6 +112,26 @@ def enum_string_vendor_ext_validate_enum(cls, value): raise ValueError("must be one of enum values ('FOO', 'Bar', 'baz')") return value + @field_validator('enum_string_single_member') + def enum_string_single_member_validate_enum(cls, value): + """Validates the enum""" + if value is None: + return value + + if value not in set(['abc']): + raise ValueError("must be one of enum values ('abc')") + return value + + @field_validator('enum_integer_single_member') + def enum_integer_single_member_validate_enum(cls, value): + """Validates the enum""" + if value is None: + return value + + if value not in set([100]): + raise ValueError("must be one of enum values (100)") + return value + model_config = ConfigDict( populate_by_name=True, validate_assignment=True, @@ -173,6 +195,8 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: "enum_number": obj.get("enum_number"), "enum_number_vendor_ext": obj.get("enum_number_vendor_ext"), "enum_string_vendor_ext": obj.get("enum_string_vendor_ext"), + "enum_string_single_member": obj.get("enum_string_single_member"), + "enum_integer_single_member": obj.get("enum_integer_single_member"), "outerEnum": obj.get("outerEnum"), "outerEnumInteger": obj.get("outerEnumInteger"), "outerEnumDefaultValue": obj.get("outerEnumDefaultValue") if obj.get("outerEnumDefaultValue") is not None else OuterEnumDefaultValue.PLACED, diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/EnumTest.md b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/EnumTest.md index 15d7a6539f94..72470ff0c317 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/EnumTest.md +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/EnumTest.md @@ -11,6 +11,8 @@ Name | Type | Description | Notes **enum_number** | **float** | | [optional] **enum_number_vendor_ext** | **int** | | [optional] **enum_string_vendor_ext** | **str** | | [optional] +**enum_string_single_member** | **str** | | [optional] +**enum_integer_single_member** | **int** | | [optional] **outer_enum** | [**OuterEnum**](OuterEnum.md) | | [optional] **outer_enum_integer** | [**OuterEnumInteger**](OuterEnumInteger.md) | | [optional] **outer_enum_default_value** | [**OuterEnumDefaultValue**](OuterEnumDefaultValue.md) | | [optional] diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/bathing.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/bathing.py index 986de06f0c20..753acf8d6948 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/bathing.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/bathing.py @@ -33,14 +33,14 @@ class Bathing(BaseModel): @validator('task_name') def task_name_validate_enum(cls, value): """Validates the enum""" - if value not in ('cleaning_deep'): + if value not in ('cleaning_deep',): raise ValueError("must be one of enum values ('cleaning_deep')") return value @validator('function_name') def function_name_validate_enum(cls, value): """Validates the enum""" - if value not in ('care_nourish'): + if value not in ('care_nourish',): raise ValueError("must be one of enum values ('care_nourish')") return value diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/enum_arrays.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/enum_arrays.py index 5f3363b0a564..05d532614fff 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/enum_arrays.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/enum_arrays.py @@ -35,7 +35,7 @@ def just_symbol_validate_enum(cls, value): if value is None: return value - if value not in ('>=', '$'): + if value not in ('>=', '$',): raise ValueError("must be one of enum values ('>=', '$')") return value @@ -46,7 +46,7 @@ def array_enum_validate_enum(cls, value): return value for i in value: - if i not in ('fish', 'crab'): + if i not in ('fish', 'crab',): raise ValueError("each list item must be one of ('fish', 'crab')") return value diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/enum_test.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/enum_test.py index 66c688f9f484..5df6a535f199 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/enum_test.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/enum_test.py @@ -36,11 +36,13 @@ class EnumTest(BaseModel): enum_number: Optional[float] = None enum_number_vendor_ext: Optional[StrictInt] = None enum_string_vendor_ext: Optional[StrictStr] = None + enum_string_single_member: Optional[StrictStr] = None + enum_integer_single_member: Optional[StrictInt] = None outer_enum: Optional[OuterEnum] = Field(default=None, alias="outerEnum") outer_enum_integer: Optional[OuterEnumInteger] = Field(default=None, alias="outerEnumInteger") outer_enum_default_value: Optional[OuterEnumDefaultValue] = Field(default=None, alias="outerEnumDefaultValue") outer_enum_integer_default_value: Optional[OuterEnumIntegerDefaultValue] = Field(default=None, alias="outerEnumIntegerDefaultValue") - __properties = ["enum_string", "enum_string_required", "enum_integer_default", "enum_integer", "enum_number", "enum_number_vendor_ext", "enum_string_vendor_ext", "outerEnum", "outerEnumInteger", "outerEnumDefaultValue", "outerEnumIntegerDefaultValue"] + __properties = ["enum_string", "enum_string_required", "enum_integer_default", "enum_integer", "enum_number", "enum_number_vendor_ext", "enum_string_vendor_ext", "enum_string_single_member", "enum_integer_single_member", "outerEnum", "outerEnumInteger", "outerEnumDefaultValue", "outerEnumIntegerDefaultValue"] @validator('enum_string') def enum_string_validate_enum(cls, value): @@ -48,14 +50,14 @@ def enum_string_validate_enum(cls, value): if value is None: return value - if value not in ('UPPER', 'lower', ''): + if value not in ('UPPER', 'lower', '',): raise ValueError("must be one of enum values ('UPPER', 'lower', '')") return value @validator('enum_string_required') def enum_string_required_validate_enum(cls, value): """Validates the enum""" - if value not in ('UPPER', 'lower', ''): + if value not in ('UPPER', 'lower', '',): raise ValueError("must be one of enum values ('UPPER', 'lower', '')") return value @@ -65,7 +67,7 @@ def enum_integer_default_validate_enum(cls, value): if value is None: return value - if value not in (1, 5, 14): + if value not in (1, 5, 14,): raise ValueError("must be one of enum values (1, 5, 14)") return value @@ -75,7 +77,7 @@ def enum_integer_validate_enum(cls, value): if value is None: return value - if value not in (1, -1): + if value not in (1, -1,): raise ValueError("must be one of enum values (1, -1)") return value @@ -85,7 +87,7 @@ def enum_number_validate_enum(cls, value): if value is None: return value - if value not in (1.1, -1.2): + if value not in (1.1, -1.2,): raise ValueError("must be one of enum values (1.1, -1.2)") return value @@ -95,7 +97,7 @@ def enum_number_vendor_ext_validate_enum(cls, value): if value is None: return value - if value not in (42, 18, 56): + if value not in (42, 18, 56,): raise ValueError("must be one of enum values (42, 18, 56)") return value @@ -105,10 +107,30 @@ def enum_string_vendor_ext_validate_enum(cls, value): if value is None: return value - if value not in ('FOO', 'Bar', 'baz'): + if value not in ('FOO', 'Bar', 'baz',): raise ValueError("must be one of enum values ('FOO', 'Bar', 'baz')") return value + @validator('enum_string_single_member') + def enum_string_single_member_validate_enum(cls, value): + """Validates the enum""" + if value is None: + return value + + if value not in ('abc',): + raise ValueError("must be one of enum values ('abc')") + return value + + @validator('enum_integer_single_member') + def enum_integer_single_member_validate_enum(cls, value): + """Validates the enum""" + if value is None: + return value + + if value not in (100,): + raise ValueError("must be one of enum values (100)") + return value + class Config: """Pydantic configuration""" allow_population_by_field_name = True @@ -157,6 +179,8 @@ def from_dict(cls, obj: dict) -> EnumTest: "enum_number": obj.get("enum_number"), "enum_number_vendor_ext": obj.get("enum_number_vendor_ext"), "enum_string_vendor_ext": obj.get("enum_string_vendor_ext"), + "enum_string_single_member": obj.get("enum_string_single_member"), + "enum_integer_single_member": obj.get("enum_integer_single_member"), "outer_enum": obj.get("outerEnum"), "outer_enum_integer": obj.get("outerEnumInteger"), "outer_enum_default_value": obj.get("outerEnumDefaultValue"), diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/feeding.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/feeding.py index ad8143b457aa..3013f7d57d00 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/feeding.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/feeding.py @@ -33,14 +33,14 @@ class Feeding(BaseModel): @validator('task_name') def task_name_validate_enum(cls, value): """Validates the enum""" - if value not in ('cleaning'): + if value not in ('cleaning',): raise ValueError("must be one of enum values ('cleaning')") return value @validator('function_name') def function_name_validate_enum(cls, value): """Validates the enum""" - if value not in ('care_nourish'): + if value not in ('care_nourish',): raise ValueError("must be one of enum values ('care_nourish')") return value diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/map_test.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/map_test.py index 42e47b1cb4f3..ce853d3d77b1 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/map_test.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/map_test.py @@ -37,7 +37,7 @@ def map_of_enum_string_validate_enum(cls, value): if value is None: return value - if value not in ('UPPER', 'lower'): + if value not in ('UPPER', 'lower',): raise ValueError("must be one of enum values ('UPPER', 'lower')") return value diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/order.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/order.py index ca0c5e46b17b..fb76b99915a5 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/order.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/order.py @@ -39,7 +39,7 @@ def status_validate_enum(cls, value): if value is None: return value - if value not in ('placed', 'approved', 'delivered'): + if value not in ('placed', 'approved', 'delivered',): raise ValueError("must be one of enum values ('placed', 'approved', 'delivered')") return value diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/pet.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/pet.py index 2c97c7e598a4..112508adac5a 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/pet.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/pet.py @@ -41,7 +41,7 @@ def status_validate_enum(cls, value): if value is None: return value - if value not in ('available', 'pending', 'sold'): + if value not in ('available', 'pending', 'sold',): raise ValueError("must be one of enum values ('available', 'pending', 'sold')") return value diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/poop_cleaning.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/poop_cleaning.py index 54dff6de1f12..9bf76733284f 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/poop_cleaning.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/poop_cleaning.py @@ -33,14 +33,14 @@ class PoopCleaning(BaseModel): @validator('task_name') def task_name_validate_enum(cls, value): """Validates the enum""" - if value not in ('cleaning'): + if value not in ('cleaning',): raise ValueError("must be one of enum values ('cleaning')") return value @validator('function_name') def function_name_validate_enum(cls, value): """Validates the enum""" - if value not in ('care'): + if value not in ('care',): raise ValueError("must be one of enum values ('care')") return value diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/special_name.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/special_name.py index 2d3ad63ffcf3..1ce291e969be 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/special_name.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/special_name.py @@ -37,7 +37,7 @@ def var_schema_validate_enum(cls, value): if value is None: return value - if value not in ('available', 'pending', 'sold'): + if value not in ('available', 'pending', 'sold',): raise ValueError("must be one of enum values ('available', 'pending', 'sold')") return value diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/test_model_with_enum_default.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/test_model_with_enum_default.py index 7a3481e9d0cd..861926379409 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/test_model_with_enum_default.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/test_model_with_enum_default.py @@ -40,7 +40,7 @@ def test_inline_defined_enum_with_default_validate_enum(cls, value): if value is None: return value - if value not in ('A', 'B', 'C'): + if value not in ('A', 'B', 'C',): raise ValueError("must be one of enum values ('A', 'B', 'C')") return value diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/docs/EnumTest.md b/samples/openapi3/client/petstore/python-pydantic-v1/docs/EnumTest.md index 15d7a6539f94..72470ff0c317 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/docs/EnumTest.md +++ b/samples/openapi3/client/petstore/python-pydantic-v1/docs/EnumTest.md @@ -11,6 +11,8 @@ Name | Type | Description | Notes **enum_number** | **float** | | [optional] **enum_number_vendor_ext** | **int** | | [optional] **enum_string_vendor_ext** | **str** | | [optional] +**enum_string_single_member** | **str** | | [optional] +**enum_integer_single_member** | **int** | | [optional] **outer_enum** | [**OuterEnum**](OuterEnum.md) | | [optional] **outer_enum_integer** | [**OuterEnumInteger**](OuterEnumInteger.md) | | [optional] **outer_enum_default_value** | [**OuterEnumDefaultValue**](OuterEnumDefaultValue.md) | | [optional] diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/bathing.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/bathing.py index 09bb3b7a0385..a167526a6209 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/bathing.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/bathing.py @@ -34,14 +34,14 @@ class Bathing(BaseModel): @validator('task_name') def task_name_validate_enum(cls, value): """Validates the enum""" - if value not in ('cleaning_deep'): + if value not in ('cleaning_deep',): raise ValueError("must be one of enum values ('cleaning_deep')") return value @validator('function_name') def function_name_validate_enum(cls, value): """Validates the enum""" - if value not in ('care_nourish'): + if value not in ('care_nourish',): raise ValueError("must be one of enum values ('care_nourish')") return value diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/enum_arrays.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/enum_arrays.py index f804f117c9b3..4234f3968fe0 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/enum_arrays.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/enum_arrays.py @@ -36,7 +36,7 @@ def just_symbol_validate_enum(cls, value): if value is None: return value - if value not in ('>=', '$'): + if value not in ('>=', '$',): raise ValueError("must be one of enum values ('>=', '$')") return value @@ -47,7 +47,7 @@ def array_enum_validate_enum(cls, value): return value for i in value: - if i not in ('fish', 'crab'): + if i not in ('fish', 'crab',): raise ValueError("each list item must be one of ('fish', 'crab')") return value diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/enum_test.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/enum_test.py index a04be47a43fb..6dfb92bfe94c 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/enum_test.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/enum_test.py @@ -36,12 +36,14 @@ class EnumTest(BaseModel): enum_number: Optional[StrictFloat] = None enum_number_vendor_ext: Optional[StrictInt] = None enum_string_vendor_ext: Optional[StrictStr] = None + enum_string_single_member: Optional[StrictStr] = None + enum_integer_single_member: Optional[StrictInt] = None outer_enum: Optional[OuterEnum] = Field(default=None, alias="outerEnum") outer_enum_integer: Optional[OuterEnumInteger] = Field(default=None, alias="outerEnumInteger") outer_enum_default_value: Optional[OuterEnumDefaultValue] = Field(default=None, alias="outerEnumDefaultValue") outer_enum_integer_default_value: Optional[OuterEnumIntegerDefaultValue] = Field(default=None, alias="outerEnumIntegerDefaultValue") additional_properties: Dict[str, Any] = {} - __properties = ["enum_string", "enum_string_required", "enum_integer_default", "enum_integer", "enum_number", "enum_number_vendor_ext", "enum_string_vendor_ext", "outerEnum", "outerEnumInteger", "outerEnumDefaultValue", "outerEnumIntegerDefaultValue"] + __properties = ["enum_string", "enum_string_required", "enum_integer_default", "enum_integer", "enum_number", "enum_number_vendor_ext", "enum_string_vendor_ext", "enum_string_single_member", "enum_integer_single_member", "outerEnum", "outerEnumInteger", "outerEnumDefaultValue", "outerEnumIntegerDefaultValue"] @validator('enum_string') def enum_string_validate_enum(cls, value): @@ -49,14 +51,14 @@ def enum_string_validate_enum(cls, value): if value is None: return value - if value not in ('UPPER', 'lower', ''): + if value not in ('UPPER', 'lower', '',): raise ValueError("must be one of enum values ('UPPER', 'lower', '')") return value @validator('enum_string_required') def enum_string_required_validate_enum(cls, value): """Validates the enum""" - if value not in ('UPPER', 'lower', ''): + if value not in ('UPPER', 'lower', '',): raise ValueError("must be one of enum values ('UPPER', 'lower', '')") return value @@ -66,7 +68,7 @@ def enum_integer_default_validate_enum(cls, value): if value is None: return value - if value not in (1, 5, 14): + if value not in (1, 5, 14,): raise ValueError("must be one of enum values (1, 5, 14)") return value @@ -76,7 +78,7 @@ def enum_integer_validate_enum(cls, value): if value is None: return value - if value not in (1, -1): + if value not in (1, -1,): raise ValueError("must be one of enum values (1, -1)") return value @@ -86,7 +88,7 @@ def enum_number_validate_enum(cls, value): if value is None: return value - if value not in (1.1, -1.2): + if value not in (1.1, -1.2,): raise ValueError("must be one of enum values (1.1, -1.2)") return value @@ -96,7 +98,7 @@ def enum_number_vendor_ext_validate_enum(cls, value): if value is None: return value - if value not in (42, 18, 56): + if value not in (42, 18, 56,): raise ValueError("must be one of enum values (42, 18, 56)") return value @@ -106,10 +108,30 @@ def enum_string_vendor_ext_validate_enum(cls, value): if value is None: return value - if value not in ('FOO', 'Bar', 'baz'): + if value not in ('FOO', 'Bar', 'baz',): raise ValueError("must be one of enum values ('FOO', 'Bar', 'baz')") return value + @validator('enum_string_single_member') + def enum_string_single_member_validate_enum(cls, value): + """Validates the enum""" + if value is None: + return value + + if value not in ('abc',): + raise ValueError("must be one of enum values ('abc')") + return value + + @validator('enum_integer_single_member') + def enum_integer_single_member_validate_enum(cls, value): + """Validates the enum""" + if value is None: + return value + + if value not in (100,): + raise ValueError("must be one of enum values (100)") + return value + class Config: """Pydantic configuration""" allow_population_by_field_name = True @@ -164,6 +186,8 @@ def from_dict(cls, obj: dict) -> EnumTest: "enum_number": obj.get("enum_number"), "enum_number_vendor_ext": obj.get("enum_number_vendor_ext"), "enum_string_vendor_ext": obj.get("enum_string_vendor_ext"), + "enum_string_single_member": obj.get("enum_string_single_member"), + "enum_integer_single_member": obj.get("enum_integer_single_member"), "outer_enum": obj.get("outerEnum"), "outer_enum_integer": obj.get("outerEnumInteger"), "outer_enum_default_value": obj.get("outerEnumDefaultValue"), diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/feeding.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/feeding.py index 9afe7dce1b4f..3f4ba3f81eb6 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/feeding.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/feeding.py @@ -34,14 +34,14 @@ class Feeding(BaseModel): @validator('task_name') def task_name_validate_enum(cls, value): """Validates the enum""" - if value not in ('cleaning'): + if value not in ('cleaning',): raise ValueError("must be one of enum values ('cleaning')") return value @validator('function_name') def function_name_validate_enum(cls, value): """Validates the enum""" - if value not in ('care_nourish'): + if value not in ('care_nourish',): raise ValueError("must be one of enum values ('care_nourish')") return value diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/map_test.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/map_test.py index 4270158fd4d0..a6c761dfa2a8 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/map_test.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/map_test.py @@ -38,7 +38,7 @@ def map_of_enum_string_validate_enum(cls, value): if value is None: return value - if value not in ('UPPER', 'lower'): + if value not in ('UPPER', 'lower',): raise ValueError("must be one of enum values ('UPPER', 'lower')") return value diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/order.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/order.py index 34a39fe0aa94..635f1351ae4d 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/order.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/order.py @@ -40,7 +40,7 @@ def status_validate_enum(cls, value): if value is None: return value - if value not in ('placed', 'approved', 'delivered'): + if value not in ('placed', 'approved', 'delivered',): raise ValueError("must be one of enum values ('placed', 'approved', 'delivered')") return value diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/pet.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/pet.py index 89f8066ed168..2b29315173bd 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/pet.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/pet.py @@ -42,7 +42,7 @@ def status_validate_enum(cls, value): if value is None: return value - if value not in ('available', 'pending', 'sold'): + if value not in ('available', 'pending', 'sold',): raise ValueError("must be one of enum values ('available', 'pending', 'sold')") return value diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/poop_cleaning.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/poop_cleaning.py index 5649822e4f20..f6c7e3d2f04c 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/poop_cleaning.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/poop_cleaning.py @@ -34,14 +34,14 @@ class PoopCleaning(BaseModel): @validator('task_name') def task_name_validate_enum(cls, value): """Validates the enum""" - if value not in ('cleaning'): + if value not in ('cleaning',): raise ValueError("must be one of enum values ('cleaning')") return value @validator('function_name') def function_name_validate_enum(cls, value): """Validates the enum""" - if value not in ('care'): + if value not in ('care',): raise ValueError("must be one of enum values ('care')") return value diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/special_name.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/special_name.py index e19e49e199a4..71b40ec332ab 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/special_name.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/special_name.py @@ -38,7 +38,7 @@ def var_schema_validate_enum(cls, value): if value is None: return value - if value not in ('available', 'pending', 'sold'): + if value not in ('available', 'pending', 'sold',): raise ValueError("must be one of enum values ('available', 'pending', 'sold')") return value diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/test_model_with_enum_default.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/test_model_with_enum_default.py index 092b584a3606..3775fd5e29c2 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/test_model_with_enum_default.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/test_model_with_enum_default.py @@ -41,7 +41,7 @@ def test_inline_defined_enum_with_default_validate_enum(cls, value): if value is None: return value - if value not in ('A', 'B', 'C'): + if value not in ('A', 'B', 'C',): raise ValueError("must be one of enum values ('A', 'B', 'C')") return value diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/tests/test_model.py b/samples/openapi3/client/petstore/python-pydantic-v1/tests/test_model.py index ce84e0b035ff..a843b2e3cb24 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/tests/test_model.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1/tests/test_model.py @@ -378,6 +378,28 @@ def test_enum_ref_property(self): self.assertEqual(d5.__fields_set__, {'value', 'str_value'}) self.assertEqual(d5.to_json(), '{"value": 1, "str_value": null}') + def test_enum_single_members(self): + enum_test = petstore_api.EnumTest( + enum_string_required="lower", + enum_string_single_member="abc", + enum_integer_single_member=100, + ) + self.assertEqual(enum_test.enum_string_single_member, "abc") + self.assertEqual(enum_test.enum_integer_single_member, 100) + with self.assertRaises(ValueError) as e: + enum_test = petstore_api.EnumTest( + enum_string_required="lower", + enum_string_single_member="ab", + ) + self.assertTrue("must be one of enum values ('abc')" in str(e)) + + with self.assertRaises(ValueError) as e: + enum_test = petstore_api.EnumTest( + enum_string_required="lower", + enum_integer_single_member=10, + ) + self.assertTrue("must be one of enum values (100)" in str(e)) + def test_valdiator(self): # test regular expression a = petstore_api.FormatTest(number=123.45, byte=bytes("string", 'utf-8'), date="2013-09-17", password="testing09876") @@ -414,7 +436,6 @@ def test_object_id(self): pet_ap4 = petstore_api.Pet.from_dict(pet_ap.to_dict()) self.assertNotEqual(id(pet_ap3), id(pet_ap4)) - def test_additional_properties(self): pet_ap = petstore_api.Pet(name="test name", photo_urls=["string"]) pet_ap.id = 1 diff --git a/samples/openapi3/client/petstore/python/docs/EnumTest.md b/samples/openapi3/client/petstore/python/docs/EnumTest.md index 72f5fbdae230..8a3874d17375 100644 --- a/samples/openapi3/client/petstore/python/docs/EnumTest.md +++ b/samples/openapi3/client/petstore/python/docs/EnumTest.md @@ -12,6 +12,8 @@ Name | Type | Description | Notes **enum_number** | **float** | | [optional] **enum_number_vendor_ext** | **int** | | [optional] **enum_string_vendor_ext** | **str** | | [optional] +**enum_string_single_member** | **str** | | [optional] +**enum_integer_single_member** | **int** | | [optional] **outer_enum** | [**OuterEnum**](OuterEnum.md) | | [optional] **outer_enum_integer** | [**OuterEnumInteger**](OuterEnumInteger.md) | | [optional] **outer_enum_default_value** | [**OuterEnumDefaultValue**](OuterEnumDefaultValue.md) | | [optional] [default to OuterEnumDefaultValue.PLACED] diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py b/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py index d63819661558..6d09daf049db 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py @@ -37,12 +37,14 @@ class EnumTest(BaseModel): enum_number: Optional[StrictFloat] = None enum_number_vendor_ext: Optional[StrictInt] = None enum_string_vendor_ext: Optional[StrictStr] = None + enum_string_single_member: Optional[StrictStr] = None + enum_integer_single_member: Optional[StrictInt] = None outer_enum: Optional[OuterEnum] = Field(default=None, alias="outerEnum") outer_enum_integer: Optional[OuterEnumInteger] = Field(default=None, alias="outerEnumInteger") outer_enum_default_value: Optional[OuterEnumDefaultValue] = Field(default=OuterEnumDefaultValue.PLACED, alias="outerEnumDefaultValue") outer_enum_integer_default_value: Optional[OuterEnumIntegerDefaultValue] = Field(default=OuterEnumIntegerDefaultValue.NUMBER_0, alias="outerEnumIntegerDefaultValue") additional_properties: Dict[str, Any] = {} - __properties: ClassVar[List[str]] = ["enum_string", "enum_string_required", "enum_integer_default", "enum_integer", "enum_number", "enum_number_vendor_ext", "enum_string_vendor_ext", "outerEnum", "outerEnumInteger", "outerEnumDefaultValue", "outerEnumIntegerDefaultValue"] + __properties: ClassVar[List[str]] = ["enum_string", "enum_string_required", "enum_integer_default", "enum_integer", "enum_number", "enum_number_vendor_ext", "enum_string_vendor_ext", "enum_string_single_member", "enum_integer_single_member", "outerEnum", "outerEnumInteger", "outerEnumDefaultValue", "outerEnumIntegerDefaultValue"] @field_validator('enum_string') def enum_string_validate_enum(cls, value): @@ -111,6 +113,26 @@ def enum_string_vendor_ext_validate_enum(cls, value): raise ValueError("must be one of enum values ('FOO', 'Bar', 'baz')") return value + @field_validator('enum_string_single_member') + def enum_string_single_member_validate_enum(cls, value): + """Validates the enum""" + if value is None: + return value + + if value not in set(['abc']): + raise ValueError("must be one of enum values ('abc')") + return value + + @field_validator('enum_integer_single_member') + def enum_integer_single_member_validate_enum(cls, value): + """Validates the enum""" + if value is None: + return value + + if value not in set([100]): + raise ValueError("must be one of enum values (100)") + return value + model_config = ConfigDict( populate_by_name=True, validate_assignment=True, @@ -181,6 +203,8 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: "enum_number": obj.get("enum_number"), "enum_number_vendor_ext": obj.get("enum_number_vendor_ext"), "enum_string_vendor_ext": obj.get("enum_string_vendor_ext"), + "enum_string_single_member": obj.get("enum_string_single_member"), + "enum_integer_single_member": obj.get("enum_integer_single_member"), "outerEnum": obj.get("outerEnum"), "outerEnumInteger": obj.get("outerEnumInteger"), "outerEnumDefaultValue": obj.get("outerEnumDefaultValue") if obj.get("outerEnumDefaultValue") is not None else OuterEnumDefaultValue.PLACED, diff --git a/samples/server/petstore/python-fastapi/src/openapi_server/models/order.py b/samples/server/petstore/python-fastapi/src/openapi_server/models/order.py index abcb33a32a03..7a5a38cdb7b4 100644 --- a/samples/server/petstore/python-fastapi/src/openapi_server/models/order.py +++ b/samples/server/petstore/python-fastapi/src/openapi_server/models/order.py @@ -46,7 +46,7 @@ def status_validate_enum(cls, value): if value is None: return value - if value not in ('placed', 'approved', 'delivered'): + if value not in ('placed', 'approved', 'delivered',): raise ValueError("must be one of enum values ('placed', 'approved', 'delivered')") return value diff --git a/samples/server/petstore/python-fastapi/src/openapi_server/models/pet.py b/samples/server/petstore/python-fastapi/src/openapi_server/models/pet.py index 6d71c782720b..450c1b71393f 100644 --- a/samples/server/petstore/python-fastapi/src/openapi_server/models/pet.py +++ b/samples/server/petstore/python-fastapi/src/openapi_server/models/pet.py @@ -47,7 +47,7 @@ def status_validate_enum(cls, value): if value is None: return value - if value not in ('available', 'pending', 'sold'): + if value not in ('available', 'pending', 'sold',): raise ValueError("must be one of enum values ('available', 'pending', 'sold')") return value