diff --git a/bin/configs/python-nextgen-aiohttp.yaml b/bin/configs/python-nextgen-aiohttp.yaml index 4d71a6d3d61f..b211652bf571 100644 --- a/bin/configs/python-nextgen-aiohttp.yaml +++ b/bin/configs/python-nextgen-aiohttp.yaml @@ -5,3 +5,4 @@ templateDir: modules/openapi-generator/src/main/resources/python-nextgen library: asyncio additionalProperties: packageName: petstore_api + floatStrictType: false diff --git a/docs/generators/python-nextgen.md b/docs/generators/python-nextgen.md index da228948cf6e..568db3e08817 100644 --- a/docs/generators/python-nextgen.md +++ b/docs/generators/python-nextgen.md @@ -20,6 +20,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl | Option | Description | Values | Default | | ------ | ----------- | ------ | ------- | |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| +|floatStrictType|Use strict type for float, i.e. StrictFloat or confloat(strict=true, ...)| |true| |generateSourceCodeOnly|Specifies that only a library source code is to be generated.| |false| |hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true| |library|library template (sub-template) to use: asyncio, tornado (deprecated), urllib3| |urllib3| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonNextgenClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonNextgenClientCodegen.java index 52e021c9c735..6cd2f1b45e2a 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonNextgenClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonNextgenClientCodegen.java @@ -46,13 +46,14 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements public static final String PACKAGE_URL = "packageUrl"; public static final String DEFAULT_LIBRARY = "urllib3"; public static final String RECURSION_LIMIT = "recursionLimit"; - public static final String PYTHON_ATTR_NONE_IF_UNSET = "pythonAttrNoneIfUnset"; + public static final String FLOAT_STRICT_TYPE = "floatStrictType"; protected String packageUrl; protected String apiDocPath = "docs" + File.separator; protected String modelDocPath = "docs" + File.separator; protected boolean hasModelsToImport = Boolean.FALSE; protected boolean useOneOfDiscriminatorLookup = false; // use oneOf discriminator's mapping for model lookup + protected boolean floatStrictType = true; protected Map regexModifiers; @@ -164,6 +165,8 @@ public PythonNextgenClientCodegen() { cliOptions.add(new CliOption(CodegenConstants.SOURCECODEONLY_GENERATION, CodegenConstants.SOURCECODEONLY_GENERATION_DESC) .defaultValue(Boolean.FALSE.toString())); cliOptions.add(new CliOption(RECURSION_LIMIT, "Set the recursion limit. If not set, use the system default value.")); + cliOptions.add(new CliOption(FLOAT_STRICT_TYPE, "Use strict type for float, i.e. StrictFloat or confloat(strict=true, ...)") + .defaultValue(Boolean.TRUE.toString())); supportedLibraries.put("urllib3", "urllib3-based client"); supportedLibraries.put("asyncio", "asyncio-based client"); @@ -259,6 +262,10 @@ public void processOpts() { additionalProperties.put(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, useOneOfDiscriminatorLookup); } + if (additionalProperties.containsKey(FLOAT_STRICT_TYPE)) { + setFloatStrictType(convertPropertyToBooleanAndWriteBack(FLOAT_STRICT_TYPE)); + } + String modelPath = packagePath() + File.separatorChar + modelPackage.replace('.', File.separatorChar); String apiPath = packagePath() + File.separatorChar + apiPackage.replace('.', File.separatorChar); @@ -424,7 +431,6 @@ private String getPydanticType(CodegenParameter cp, if (cp.hasValidation) { List fieldCustomization = new ArrayList<>(); // e.g. confloat(ge=10, le=100, strict=True) - fieldCustomization.add("strict=True"); if (cp.getMaximum() != null) { if (cp.getExclusiveMaximum()) { fieldCustomization.add("gt=" + cp.getMaximum()); @@ -443,12 +449,20 @@ private String getPydanticType(CodegenParameter cp, fieldCustomization.add("multiple_of=" + cp.getMultipleOf()); } + if (floatStrictType) { + fieldCustomization.add("strict=True"); + } + pydanticImports.add("confloat"); return String.format(Locale.ROOT, "%s(%s)", "confloat", StringUtils.join(fieldCustomization, ", ")); } else { - pydanticImports.add("StrictFloat"); - return "StrictFloat"; + if (floatStrictType) { + pydanticImports.add("StrictFloat"); + return "StrictFloat"; + } else { + return "float"; + } } } else if (cp.isInteger || cp.isLong || cp.isShort || cp.isUnboundedInteger) { if (cp.hasValidation) { @@ -645,7 +659,6 @@ private String getPydanticType(CodegenProperty cp, if (cp.hasValidation) { List fieldCustomization = new ArrayList<>(); // e.g. confloat(ge=10, le=100, strict=True) - fieldCustomization.add("strict=True"); if (cp.getMaximum() != null) { if (cp.getExclusiveMaximum()) { fieldCustomization.add("lt=" + cp.getMaximum()); @@ -664,12 +677,20 @@ private String getPydanticType(CodegenProperty cp, fieldCustomization.add("multiple_of=" + cp.getMultipleOf()); } + if (floatStrictType) { + fieldCustomization.add("strict=True"); + } + pydanticImports.add("confloat"); return String.format(Locale.ROOT, "%s(%s)", "confloat", StringUtils.join(fieldCustomization, ", ")); } else { - pydanticImports.add("StrictFloat"); - return "StrictFloat"; + if (floatStrictType) { + pydanticImports.add("StrictFloat"); + return "StrictFloat"; + } else { + return "float"; + } } } else if (cp.isInteger || cp.isLong || cp.isShort || cp.isUnboundedInteger) { if (cp.hasValidation) { @@ -1316,4 +1337,8 @@ public String escapeReservedWord(String name) { } return "var_" + name; } + + public void setFloatStrictType(boolean floatStrictType) { + this.floatStrictType = floatStrictType; + } } 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 2ebb657985be..f1b957130c01 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 @@ -1521,7 +1521,6 @@ components: type: object required: - number - - byte - date - password properties: diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/FormatTest.md b/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/FormatTest.md index e42fa1ea0199..5ea09e1908a0 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/FormatTest.md +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/FormatTest.md @@ -12,7 +12,7 @@ Name | Type | Description | Notes **double** | **float** | | [optional] **decimal** | **decimal.Decimal** | | [optional] **string** | **str** | | [optional] -**byte** | **str** | | +**byte** | **str** | | [optional] **binary** | **str** | | [optional] **var_date** | **date** | | **date_time** | **datetime** | | [optional] diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/api/fake_api.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/api/fake_api.py index 11fdde834715..e3ba02e6741e 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/api/fake_api.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/api/fake_api.py @@ -19,7 +19,7 @@ from datetime import date, datetime -from pydantic import Field, StrictBool, StrictFloat, StrictInt, StrictStr, confloat, conint, constr, validator +from pydantic import Field, StrictBool, StrictInt, StrictStr, confloat, conint, constr, validator from typing import Dict, List, Optional @@ -641,7 +641,7 @@ def fake_outer_composite_serialize_with_http_info(self, outer_composite : Annota _request_auth=_params.get('_request_auth')) @validate_arguments - def fake_outer_number_serialize(self, body : Annotated[Optional[StrictFloat], Field(description="Input number as post body")] = None, **kwargs) -> float: # noqa: E501 + def fake_outer_number_serialize(self, body : Annotated[Optional[float], Field(description="Input number as post body")] = None, **kwargs) -> float: # noqa: E501 """fake_outer_number_serialize # noqa: E501 Test serialization of outer number types # noqa: E501 @@ -672,7 +672,7 @@ def fake_outer_number_serialize(self, body : Annotated[Optional[StrictFloat], Fi return self.fake_outer_number_serialize_with_http_info(body, **kwargs) # noqa: E501 @validate_arguments - def fake_outer_number_serialize_with_http_info(self, body : Annotated[Optional[StrictFloat], Field(description="Input number as post body")] = None, **kwargs): # noqa: E501 + def fake_outer_number_serialize_with_http_info(self, body : Annotated[Optional[float], Field(description="Input number as post body")] = None, **kwargs): # noqa: E501 """fake_outer_number_serialize # noqa: E501 Test serialization of outer number types # noqa: E501 @@ -1678,7 +1678,7 @@ def test_client_model_with_http_info(self, client : Annotated[Client, Field(..., _request_auth=_params.get('_request_auth')) @validate_arguments - def test_endpoint_parameters(self, number : Annotated[confloat(strict=True, ge=543.2, le=32.1), Field(..., description="None")], double : Annotated[confloat(strict=True, ge=123.4, le=67.8), Field(..., description="None")], pattern_without_delimiter : Annotated[constr(strict=True), Field(..., description="None")], byte : Annotated[StrictStr, Field(..., description="None")], integer : Annotated[Optional[conint(strict=True, le=100, ge=10)], Field(description="None")] = None, int32 : Annotated[Optional[conint(strict=True, le=200, ge=20)], Field(description="None")] = None, int64 : Annotated[Optional[StrictInt], Field(description="None")] = None, float : Annotated[Optional[confloat(strict=True, ge=987.6)], Field(description="None")] = None, string : Annotated[Optional[constr(strict=True)], Field(description="None")] = None, binary : Annotated[Optional[StrictStr], Field(description="None")] = None, var_date : Annotated[Optional[date], Field(description="None")] = None, date_time : Annotated[Optional[datetime], Field(description="None")] = None, password : Annotated[Optional[constr(strict=True, max_length=64, min_length=10)], Field(description="None")] = None, param_callback : Annotated[Optional[StrictStr], Field(description="None")] = None, **kwargs) -> None: # noqa: E501 + def test_endpoint_parameters(self, number : Annotated[confloat(ge=543.2, le=32.1), Field(..., description="None")], double : Annotated[confloat(ge=123.4, le=67.8), Field(..., description="None")], pattern_without_delimiter : Annotated[constr(strict=True), Field(..., description="None")], byte : Annotated[StrictStr, Field(..., description="None")], integer : Annotated[Optional[conint(strict=True, le=100, ge=10)], Field(description="None")] = None, int32 : Annotated[Optional[conint(strict=True, le=200, ge=20)], Field(description="None")] = None, int64 : Annotated[Optional[StrictInt], Field(description="None")] = None, float : Annotated[Optional[confloat(ge=987.6)], Field(description="None")] = None, string : Annotated[Optional[constr(strict=True)], Field(description="None")] = None, binary : Annotated[Optional[StrictStr], Field(description="None")] = None, var_date : Annotated[Optional[date], Field(description="None")] = None, date_time : Annotated[Optional[datetime], Field(description="None")] = None, password : Annotated[Optional[constr(strict=True, max_length=64, min_length=10)], Field(description="None")] = None, param_callback : Annotated[Optional[StrictStr], Field(description="None")] = None, **kwargs) -> None: # noqa: E501 """Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 @@ -1735,7 +1735,7 @@ def test_endpoint_parameters(self, number : Annotated[confloat(strict=True, ge=5 return self.test_endpoint_parameters_with_http_info(number, double, pattern_without_delimiter, byte, integer, int32, int64, float, string, binary, var_date, date_time, password, param_callback, **kwargs) # noqa: E501 @validate_arguments - def test_endpoint_parameters_with_http_info(self, number : Annotated[confloat(strict=True, ge=543.2, le=32.1), Field(..., description="None")], double : Annotated[confloat(strict=True, ge=123.4, le=67.8), Field(..., description="None")], pattern_without_delimiter : Annotated[constr(strict=True), Field(..., description="None")], byte : Annotated[StrictStr, Field(..., description="None")], integer : Annotated[Optional[conint(strict=True, le=100, ge=10)], Field(description="None")] = None, int32 : Annotated[Optional[conint(strict=True, le=200, ge=20)], Field(description="None")] = None, int64 : Annotated[Optional[StrictInt], Field(description="None")] = None, float : Annotated[Optional[confloat(strict=True, ge=987.6)], Field(description="None")] = None, string : Annotated[Optional[constr(strict=True)], Field(description="None")] = None, binary : Annotated[Optional[StrictStr], Field(description="None")] = None, var_date : Annotated[Optional[date], Field(description="None")] = None, date_time : Annotated[Optional[datetime], Field(description="None")] = None, password : Annotated[Optional[constr(strict=True, max_length=64, min_length=10)], Field(description="None")] = None, param_callback : Annotated[Optional[StrictStr], Field(description="None")] = None, **kwargs): # noqa: E501 + def test_endpoint_parameters_with_http_info(self, number : Annotated[confloat(ge=543.2, le=32.1), Field(..., description="None")], double : Annotated[confloat(ge=123.4, le=67.8), Field(..., description="None")], pattern_without_delimiter : Annotated[constr(strict=True), Field(..., description="None")], byte : Annotated[StrictStr, Field(..., description="None")], integer : Annotated[Optional[conint(strict=True, le=100, ge=10)], Field(description="None")] = None, int32 : Annotated[Optional[conint(strict=True, le=200, ge=20)], Field(description="None")] = None, int64 : Annotated[Optional[StrictInt], Field(description="None")] = None, float : Annotated[Optional[confloat(ge=987.6)], Field(description="None")] = None, string : Annotated[Optional[constr(strict=True)], Field(description="None")] = None, binary : Annotated[Optional[StrictStr], Field(description="None")] = None, var_date : Annotated[Optional[date], Field(description="None")] = None, date_time : Annotated[Optional[datetime], Field(description="None")] = None, password : Annotated[Optional[constr(strict=True, max_length=64, min_length=10)], Field(description="None")] = None, param_callback : Annotated[Optional[StrictStr], Field(description="None")] = None, **kwargs): # noqa: E501 """Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/array_of_array_of_number_only.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/array_of_array_of_number_only.py index bec2f93d2309..c284f35caaf6 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/array_of_array_of_number_only.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/array_of_array_of_number_only.py @@ -18,7 +18,7 @@ from typing import List, Optional -from pydantic import BaseModel, Field, StrictFloat +from pydantic import BaseModel, Field class ArrayOfArrayOfNumberOnly(BaseModel): """NOTE: This class is auto generated by OpenAPI Generator. @@ -26,7 +26,7 @@ class ArrayOfArrayOfNumberOnly(BaseModel): Do not edit the class manually. """ - array_array_number: Optional[List[List[StrictFloat]]] = Field(None, alias="ArrayArrayNumber") + array_array_number: Optional[List[List[float]]] = Field(None, alias="ArrayArrayNumber") __properties = ["ArrayArrayNumber"] class Config: diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/array_of_number_only.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/array_of_number_only.py index 779e5b176709..c349a9e2ff33 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/array_of_number_only.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/array_of_number_only.py @@ -18,7 +18,7 @@ from typing import List, Optional -from pydantic import BaseModel, Field, StrictFloat +from pydantic import BaseModel, Field class ArrayOfNumberOnly(BaseModel): """NOTE: This class is auto generated by OpenAPI Generator. @@ -26,7 +26,7 @@ class ArrayOfNumberOnly(BaseModel): Do not edit the class manually. """ - array_number: Optional[List[StrictFloat]] = Field(None, alias="ArrayNumber") + array_number: Optional[List[float]] = Field(None, alias="ArrayNumber") __properties = ["ArrayNumber"] class Config: diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/enum_test.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/enum_test.py index 6166ab6414d7..b6a08b4df7fe 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/enum_test.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/enum_test.py @@ -18,7 +18,7 @@ from typing import Optional -from pydantic import BaseModel, Field, StrictFloat, StrictInt, StrictStr, validator +from pydantic import BaseModel, Field, StrictInt, StrictStr, validator from petstore_api.models.outer_enum import OuterEnum from petstore_api.models.outer_enum_default_value import OuterEnumDefaultValue from petstore_api.models.outer_enum_integer import OuterEnumInteger @@ -33,7 +33,7 @@ class EnumTest(BaseModel): enum_string: Optional[StrictStr] = None enum_string_required: StrictStr = ... enum_integer: Optional[StrictInt] = None - enum_number: Optional[StrictFloat] = None + enum_number: Optional[float] = None outer_enum: Optional[OuterEnum] = Field(None, alias="outerEnum") outer_enum_integer: Optional[OuterEnumInteger] = Field(None, alias="outerEnumInteger") outer_enum_default_value: Optional[OuterEnumDefaultValue] = Field(None, alias="outerEnumDefaultValue") diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/format_test.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/format_test.py index f0801d5ec9d8..2d71fcfca2a7 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/format_test.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/format_test.py @@ -29,12 +29,12 @@ class FormatTest(BaseModel): integer: Optional[conint(strict=True, le=100, ge=10)] = None int32: Optional[conint(strict=True, le=200, ge=20)] = None int64: Optional[StrictInt] = None - number: confloat(strict=True, le=543.2, ge=32.1) = ... - float: Optional[confloat(strict=True, le=987.6, ge=54.3)] = None - double: Optional[confloat(strict=True, le=123.4, ge=67.8)] = None + number: confloat(le=543.2, ge=32.1) = ... + float: Optional[confloat(le=987.6, ge=54.3)] = None + double: Optional[confloat(le=123.4, ge=67.8)] = None decimal: Optional[condecimal()] = None string: Optional[constr(strict=True)] = None - byte: StrictBytes = ... + byte: Optional[StrictBytes] = None binary: Optional[StrictBytes] = None var_date: date = Field(..., alias="date") date_time: Optional[datetime] = Field(None, alias="dateTime") diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/nullable_class.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/nullable_class.py index 449bb066f724..4965f314b0fb 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/nullable_class.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/nullable_class.py @@ -18,7 +18,7 @@ from datetime import date, datetime from typing import Any, Dict, List, Optional -from pydantic import BaseModel, StrictBool, StrictFloat, StrictInt, StrictStr +from pydantic import BaseModel, StrictBool, StrictInt, StrictStr class NullableClass(BaseModel): """NOTE: This class is auto generated by OpenAPI Generator. @@ -28,7 +28,7 @@ class NullableClass(BaseModel): """ required_integer_prop: Optional[StrictInt] = ... integer_prop: Optional[StrictInt] = None - number_prop: Optional[StrictFloat] = None + number_prop: Optional[float] = None boolean_prop: Optional[StrictBool] = None string_prop: Optional[StrictStr] = None date_prop: Optional[date] = None diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/number_only.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/number_only.py index 978b8c3da625..c3a7dbaedde5 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/number_only.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/number_only.py @@ -18,7 +18,7 @@ from typing import Optional -from pydantic import BaseModel, Field, StrictFloat +from pydantic import BaseModel, Field class NumberOnly(BaseModel): """NOTE: This class is auto generated by OpenAPI Generator. @@ -26,7 +26,7 @@ class NumberOnly(BaseModel): Do not edit the class manually. """ - just_number: Optional[StrictFloat] = Field(None, alias="JustNumber") + just_number: Optional[float] = Field(None, alias="JustNumber") __properties = ["JustNumber"] class Config: diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/object_with_deprecated_fields.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/object_with_deprecated_fields.py index 6ec29e2c908c..a9f26f44256b 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/object_with_deprecated_fields.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/object_with_deprecated_fields.py @@ -18,7 +18,7 @@ from typing import List, Optional -from pydantic import BaseModel, Field, StrictFloat, StrictStr +from pydantic import BaseModel, Field, StrictStr from petstore_api.models.deprecated_object import DeprecatedObject class ObjectWithDeprecatedFields(BaseModel): @@ -28,7 +28,7 @@ class ObjectWithDeprecatedFields(BaseModel): Do not edit the class manually. """ uuid: Optional[StrictStr] = None - id: Optional[StrictFloat] = None + id: Optional[float] = None deprecated_ref: Optional[DeprecatedObject] = Field(None, alias="deprecatedRef") bars: Optional[List[StrictStr]] = None __properties = ["uuid", "id", "deprecatedRef", "bars"] diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/outer_composite.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/outer_composite.py index 70606abd65f3..ee896ed54ab5 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/outer_composite.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/outer_composite.py @@ -18,7 +18,7 @@ from typing import Optional -from pydantic import BaseModel, StrictBool, StrictFloat, StrictStr +from pydantic import BaseModel, StrictBool, StrictStr class OuterComposite(BaseModel): """NOTE: This class is auto generated by OpenAPI Generator. @@ -26,7 +26,7 @@ class OuterComposite(BaseModel): Do not edit the class manually. """ - my_number: Optional[StrictFloat] = None + my_number: Optional[float] = None my_string: Optional[StrictStr] = None my_boolean: Optional[StrictBool] = None __properties = ["my_number", "my_string", "my_boolean"] diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/tests/test_model.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/tests/test_model.py index 5abbb35ca0c5..b2954d10e0ab 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/tests/test_model.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/tests/test_model.py @@ -204,6 +204,16 @@ def test_enum_ref_property(self): self.assertEqual(d3.value, petstore_api.OuterEnumInteger.NUMBER_1) self.assertEqual(d3.to_json(), '{"str_value": "delivered", "value": 1}') + def test_float_strict_type(self): + # assigning 123 to float shouldn't throw an exception + a = petstore_api.FormatTest(number=39.8, float=123, byte=bytes("string", 'utf-8'), date="2013-09-17", password="testing09876") + self.assertEqual(a.float, 123.0) + + json_str = '{"number": 34.5, "float": "456", "date": "2013-12-08", "password": "empty1234567", "pattern_with_digits": "1234567890", "pattern_with_digits_and_delimiter": "image_123" , "string": "string"}' + # no exception thrown when assigning 456 (integer) to float type since strict is set to false + f = petstore_api.FormatTest.from_json(json_str) + self.assertEqual(f.float, 456.0) + 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") @@ -211,7 +221,7 @@ def test_valdiator(self): a.pattern_with_digits_and_delimiter = "123" self.assertTrue(False) # this line shouldn't execute except ValueError as e: - self.assertTrue("must validate the regular expression /^image_\d{1,3}$/i" in str(e)) + self.assertTrue(r"must validate the regular expression /^image_\d{1,3}$/i" in str(e)) a.pattern_with_digits_and_delimiter = "IMAGE_123" self.assertEqual(a.pattern_with_digits_and_delimiter, "IMAGE_123") diff --git a/samples/openapi3/client/petstore/python-nextgen/docs/FormatTest.md b/samples/openapi3/client/petstore/python-nextgen/docs/FormatTest.md index e42fa1ea0199..5ea09e1908a0 100755 --- a/samples/openapi3/client/petstore/python-nextgen/docs/FormatTest.md +++ b/samples/openapi3/client/petstore/python-nextgen/docs/FormatTest.md @@ -12,7 +12,7 @@ Name | Type | Description | Notes **double** | **float** | | [optional] **decimal** | **decimal.Decimal** | | [optional] **string** | **str** | | [optional] -**byte** | **str** | | +**byte** | **str** | | [optional] **binary** | **str** | | [optional] **var_date** | **date** | | **date_time** | **datetime** | | [optional] diff --git a/samples/openapi3/client/petstore/python-nextgen/petstore_api/api/fake_api.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/api/fake_api.py index 11fdde834715..166d6ec0d950 100755 --- a/samples/openapi3/client/petstore/python-nextgen/petstore_api/api/fake_api.py +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/api/fake_api.py @@ -1678,7 +1678,7 @@ def test_client_model_with_http_info(self, client : Annotated[Client, Field(..., _request_auth=_params.get('_request_auth')) @validate_arguments - def test_endpoint_parameters(self, number : Annotated[confloat(strict=True, ge=543.2, le=32.1), Field(..., description="None")], double : Annotated[confloat(strict=True, ge=123.4, le=67.8), Field(..., description="None")], pattern_without_delimiter : Annotated[constr(strict=True), Field(..., description="None")], byte : Annotated[StrictStr, Field(..., description="None")], integer : Annotated[Optional[conint(strict=True, le=100, ge=10)], Field(description="None")] = None, int32 : Annotated[Optional[conint(strict=True, le=200, ge=20)], Field(description="None")] = None, int64 : Annotated[Optional[StrictInt], Field(description="None")] = None, float : Annotated[Optional[confloat(strict=True, ge=987.6)], Field(description="None")] = None, string : Annotated[Optional[constr(strict=True)], Field(description="None")] = None, binary : Annotated[Optional[StrictStr], Field(description="None")] = None, var_date : Annotated[Optional[date], Field(description="None")] = None, date_time : Annotated[Optional[datetime], Field(description="None")] = None, password : Annotated[Optional[constr(strict=True, max_length=64, min_length=10)], Field(description="None")] = None, param_callback : Annotated[Optional[StrictStr], Field(description="None")] = None, **kwargs) -> None: # noqa: E501 + def test_endpoint_parameters(self, number : Annotated[confloat(ge=543.2, le=32.1, strict=True), Field(..., description="None")], double : Annotated[confloat(ge=123.4, le=67.8, strict=True), Field(..., description="None")], pattern_without_delimiter : Annotated[constr(strict=True), Field(..., description="None")], byte : Annotated[StrictStr, Field(..., description="None")], integer : Annotated[Optional[conint(strict=True, le=100, ge=10)], Field(description="None")] = None, int32 : Annotated[Optional[conint(strict=True, le=200, ge=20)], Field(description="None")] = None, int64 : Annotated[Optional[StrictInt], Field(description="None")] = None, float : Annotated[Optional[confloat(ge=987.6, strict=True)], Field(description="None")] = None, string : Annotated[Optional[constr(strict=True)], Field(description="None")] = None, binary : Annotated[Optional[StrictStr], Field(description="None")] = None, var_date : Annotated[Optional[date], Field(description="None")] = None, date_time : Annotated[Optional[datetime], Field(description="None")] = None, password : Annotated[Optional[constr(strict=True, max_length=64, min_length=10)], Field(description="None")] = None, param_callback : Annotated[Optional[StrictStr], Field(description="None")] = None, **kwargs) -> None: # noqa: E501 """Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 @@ -1735,7 +1735,7 @@ def test_endpoint_parameters(self, number : Annotated[confloat(strict=True, ge=5 return self.test_endpoint_parameters_with_http_info(number, double, pattern_without_delimiter, byte, integer, int32, int64, float, string, binary, var_date, date_time, password, param_callback, **kwargs) # noqa: E501 @validate_arguments - def test_endpoint_parameters_with_http_info(self, number : Annotated[confloat(strict=True, ge=543.2, le=32.1), Field(..., description="None")], double : Annotated[confloat(strict=True, ge=123.4, le=67.8), Field(..., description="None")], pattern_without_delimiter : Annotated[constr(strict=True), Field(..., description="None")], byte : Annotated[StrictStr, Field(..., description="None")], integer : Annotated[Optional[conint(strict=True, le=100, ge=10)], Field(description="None")] = None, int32 : Annotated[Optional[conint(strict=True, le=200, ge=20)], Field(description="None")] = None, int64 : Annotated[Optional[StrictInt], Field(description="None")] = None, float : Annotated[Optional[confloat(strict=True, ge=987.6)], Field(description="None")] = None, string : Annotated[Optional[constr(strict=True)], Field(description="None")] = None, binary : Annotated[Optional[StrictStr], Field(description="None")] = None, var_date : Annotated[Optional[date], Field(description="None")] = None, date_time : Annotated[Optional[datetime], Field(description="None")] = None, password : Annotated[Optional[constr(strict=True, max_length=64, min_length=10)], Field(description="None")] = None, param_callback : Annotated[Optional[StrictStr], Field(description="None")] = None, **kwargs): # noqa: E501 + def test_endpoint_parameters_with_http_info(self, number : Annotated[confloat(ge=543.2, le=32.1, strict=True), Field(..., description="None")], double : Annotated[confloat(ge=123.4, le=67.8, strict=True), Field(..., description="None")], pattern_without_delimiter : Annotated[constr(strict=True), Field(..., description="None")], byte : Annotated[StrictStr, Field(..., description="None")], integer : Annotated[Optional[conint(strict=True, le=100, ge=10)], Field(description="None")] = None, int32 : Annotated[Optional[conint(strict=True, le=200, ge=20)], Field(description="None")] = None, int64 : Annotated[Optional[StrictInt], Field(description="None")] = None, float : Annotated[Optional[confloat(ge=987.6, strict=True)], Field(description="None")] = None, string : Annotated[Optional[constr(strict=True)], Field(description="None")] = None, binary : Annotated[Optional[StrictStr], Field(description="None")] = None, var_date : Annotated[Optional[date], Field(description="None")] = None, date_time : Annotated[Optional[datetime], Field(description="None")] = None, password : Annotated[Optional[constr(strict=True, max_length=64, min_length=10)], Field(description="None")] = None, param_callback : Annotated[Optional[StrictStr], Field(description="None")] = None, **kwargs): # noqa: E501 """Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 diff --git a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/format_test.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/format_test.py index 32793444b591..30a49901824f 100644 --- a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/format_test.py +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/format_test.py @@ -29,12 +29,12 @@ class FormatTest(BaseModel): integer: Optional[conint(strict=True, le=100, ge=10)] = None int32: Optional[conint(strict=True, le=200, ge=20)] = None int64: Optional[StrictInt] = None - number: confloat(strict=True, le=543.2, ge=32.1) = ... - float: Optional[confloat(strict=True, le=987.6, ge=54.3)] = None - double: Optional[confloat(strict=True, le=123.4, ge=67.8)] = None + number: confloat(le=543.2, ge=32.1, strict=True) = ... + float: Optional[confloat(le=987.6, ge=54.3, strict=True)] = None + double: Optional[confloat(le=123.4, ge=67.8, strict=True)] = None decimal: Optional[condecimal()] = None string: Optional[constr(strict=True)] = None - byte: StrictBytes = ... + byte: Optional[StrictBytes] = None binary: Optional[StrictBytes] = None var_date: date = Field(..., alias="date") date_time: Optional[datetime] = Field(None, alias="dateTime")