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 8656502e27eb5ab02997536111a0340ae0336117..06d05a3a50a7eac60f0835726d14d1360d8ff45d 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 @@ -403,8 +403,23 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements } if (cp.isArray) { - typingImports.add("List"); - return String.format(Locale.ROOT, "List[%s]", getPydanticType(cp.items, typingImports, pydanticImports, datetimeImports, modelImports)); + if (cp.maxItems != null || cp.minItems != null) { + String maxOrMinItems = ""; + if (cp.maxItems != null) { + maxOrMinItems += String.format(Locale.ROOT, ", max_items=%d", cp.maxItems); + } + if (cp.minItems != null) { + maxOrMinItems += String.format(Locale.ROOT, ", min_items=%d", cp.minItems); + } + pydanticImports.add("conlist"); + return String.format(Locale.ROOT, "conlist(%s%s)", + getPydanticType(cp.items, typingImports, pydanticImports, datetimeImports, modelImports), + maxOrMinItems); + + } else { + typingImports.add("List"); + return String.format(Locale.ROOT, "List[%s]", getPydanticType(cp.items, typingImports, pydanticImports, datetimeImports, modelImports)); + } } else if (cp.isMap) { typingImports.add("Dict"); return String.format(Locale.ROOT, "Dict[str, %s]", getPydanticType(cp.items, typingImports, pydanticImports, datetimeImports, modelImports)); @@ -638,8 +653,22 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements return String.format(Locale.ROOT, "%sEnum", cp.nameInCamelCase); } else*/ if (cp.isArray) { - typingImports.add("List"); - return String.format(Locale.ROOT, "List[%s]", getPydanticType(cp.items, typingImports, pydanticImports, datetimeImports, modelImports)); + if (cp.maxItems != null || cp.minItems != null) { + String maxOrMinItems = ""; + if (cp.maxItems != null) { + maxOrMinItems += String.format(Locale.ROOT, ", max_items=%d", cp.maxItems); + } + if (cp.minItems != null) { + maxOrMinItems += String.format(Locale.ROOT, ", min_items=%d", cp.minItems); + } + pydanticImports.add("conlist"); + return String.format(Locale.ROOT, "conlist(%s%s)", + getPydanticType(cp.items, typingImports, pydanticImports, datetimeImports, modelImports), + maxOrMinItems); + } else { + typingImports.add("List"); + return String.format(Locale.ROOT, "List[%s]", getPydanticType(cp.items, typingImports, pydanticImports, datetimeImports, modelImports)); + } } else if (cp.isMap) { typingImports.add("Dict"); return String.format(Locale.ROOT, "Dict[str, %s]", getPydanticType(cp.items, typingImports, pydanticImports, datetimeImports, modelImports)); @@ -1077,9 +1106,9 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements // setup x-py-name for each oneOf/anyOf schema if (!model.oneOf.isEmpty()) { // oneOf - cp.vendorExtensions.put("x-py-name", String.format(Locale.ROOT, "__oneof_schema_%d", property_count++)); + cp.vendorExtensions.put("x-py-name", String.format(Locale.ROOT, "oneof_schema_%d_validator", property_count++)); } else if (!model.anyOf.isEmpty()) { // anyOf - cp.vendorExtensions.put("x-py-name", String.format(Locale.ROOT, "__anyof_schema_%d", property_count++)); + cp.vendorExtensions.put("x-py-name", String.format(Locale.ROOT, "anyof_schema_%d_validator", property_count++)); } } diff --git a/modules/openapi-generator/src/main/resources/python-nextgen/model_anyof.mustache b/modules/openapi-generator/src/main/resources/python-nextgen/model_anyof.mustache index 9149f15fd51ea2fdc18ee8b247494869771388bb..8e1ebdd711cb358138e58d64cce724de693af594 100644 --- a/modules/openapi-generator/src/main/resources/python-nextgen/model_anyof.mustache +++ b/modules/openapi-generator/src/main/resources/python-nextgen/model_anyof.mustache @@ -1,5 +1,6 @@ from __future__ import annotations from inspect import getfullargspec +import json import pprint import re # noqa: F401 {{#vendorExtensions.x-py-datetime-imports}}{{#-first}}from datetime import{{/-first}} {{{.}}}{{^-last}},{{/-last}}{{/vendorExtensions.x-py-datetime-imports}} @@ -39,14 +40,38 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} @validator('actual_instance') def actual_instance_must_validate_anyof(cls, v): + {{#isNullable}} + if v is None: + return v + + {{/isNullable}} + instance = cls() error_messages = [] {{#composedSchemas.anyOf}} # validate data type: {{{dataType}}} - if type(v) is not {{^isPrimitiveType}}{{/isPrimitiveType}}{{{dataType}}}: + {{#isContainer}} + try: + instance.{{vendorExtensions.x-py-name}} = v + return v + except ValidationError as e: + error_messages.append(str(e)) + {{/isContainer}} + {{^isContainer}} + {{#isPrimitiveType}} + try: + instance.{{vendorExtensions.x-py-name}} = v + return v + except ValidationError as e: + error_messages.append(str(e)) + {{/isPrimitiveType}} + {{^isPrimitiveType}} + if type(v) is not {{{dataType}}}: error_messages.append(f"Error! Input type `{type(v)}` is not `{{{dataType}}}`") else: return v + {{/isPrimitiveType}} + {{/isContainer}} {{/composedSchemas.anyOf}} if error_messages: # no match @@ -58,8 +83,36 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} def from_json(cls, json_str: str) -> {{{classname}}}: """Returns the object represented by the json string""" instance = cls() + {{#isNullable}} + if json_str is None: + return instance + + {{/isNullable}} error_messages = [] {{#composedSchemas.anyOf}} + {{#isContainer}} + # deserialize data into {{{dataType}}} + try: + # validation + instance.{{vendorExtensions.x-py-name}} = json.loads(json_str) + # assign value to actual_instance + instance.actual_instance = instance.{{vendorExtensions.x-py-name}} + return instance + except ValidationError as e: + error_messages.append(str(e)) + {{/isContainer}} + {{^isContainer}} + {{#isPrimitiveType}} + # deserialize data into {{{dataType}}} + try: + # validation + instance.{{vendorExtensions.x-py-name}} = json.loads(json_str) + # assign value to actual_instance + instance.actual_instance = instance.{{vendorExtensions.x-py-name}} + return instance + except ValidationError as e: + error_messages.append(str(e)) + {{/isPrimitiveType}} {{^isPrimitiveType}} # {{vendorExtensions.x-py-name}}: {{{vendorExtensions.x-py-typing}}} try: @@ -68,6 +121,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} except ValidationError as e: error_messages.append(str(e)) {{/isPrimitiveType}} + {{/isContainer}} {{/composedSchemas.anyOf}} if error_messages: diff --git a/modules/openapi-generator/src/main/resources/python-nextgen/model_oneof.mustache b/modules/openapi-generator/src/main/resources/python-nextgen/model_oneof.mustache index 94cf5a0fd22659ea243a53e2e0cb03e19a790011..7e1b110e2b0cdcfda479429831ec6853f2782639 100644 --- a/modules/openapi-generator/src/main/resources/python-nextgen/model_oneof.mustache +++ b/modules/openapi-generator/src/main/resources/python-nextgen/model_oneof.mustache @@ -1,7 +1,7 @@ from __future__ import annotations from inspect import getfullargspec -import pprint import json +import pprint import re # noqa: F401 {{#vendorExtensions.x-py-datetime-imports}}{{#-first}}from datetime import{{/-first}} {{{.}}}{{^-last}},{{/-last}}{{/vendorExtensions.x-py-datetime-imports}} {{#vendorExtensions.x-py-typing-imports}}{{#-first}}from typing import{{/-first}} {{{.}}}{{^-last}},{{/-last}}{{/vendorExtensions.x-py-typing-imports}} @@ -40,15 +40,39 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} @validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): + {{#isNullable}} + if v is None: + return v + + {{/isNullable}} + instance = cls() error_messages = [] match = 0 {{#composedSchemas.oneOf}} # validate data type: {{{dataType}}} - if type(v) is not {{^isPrimitiveType}}{{/isPrimitiveType}}{{{dataType}}}: + {{#isContainer}} + try: + instance.{{vendorExtensions.x-py-name}} = v + match += 1 + except ValidationError as e: + error_messages.append(str(e)) + {{/isContainer}} + {{^isContainer}} + {{#isPrimitiveType}} + try: + instance.{{vendorExtensions.x-py-name}} = v + match += 1 + except ValidationError as e: + error_messages.append(str(e)) + {{/isPrimitiveType}} + {{^isPrimitiveType}} + if type(v) is not {{{dataType}}}: error_messages.append(f"Error! Input type `{type(v)}` is not `{{{dataType}}}`") else: match += 1 + {{/isPrimitiveType}} + {{/isContainer}} {{/composedSchemas.oneOf}} if match > 1: # more than 1 match @@ -67,6 +91,11 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} def from_json(cls, json_str: str) -> {{{classname}}}: """Returns the object represented by the json string""" instance = cls() + {{#isNullable}} + if json_str is None: + return instance + + {{/isNullable}} error_messages = [] match = 0 @@ -89,6 +118,29 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{/discriminator}} {{/useOneOfDiscriminatorLookup}} {{#composedSchemas.oneOf}} + {{#isContainer}} + # deserialize data into {{{dataType}}} + try: + # validation + instance.{{vendorExtensions.x-py-name}} = json.loads(json_str) + # assign value to actual_instance + instance.actual_instance = instance.{{vendorExtensions.x-py-name}} + match += 1 + except ValidationError as e: + error_messages.append(str(e)) + {{/isContainer}} + {{^isContainer}} + {{#isPrimitiveType}} + # deserialize data into {{{dataType}}} + try: + # validation + instance.{{vendorExtensions.x-py-name}} = json.loads(json_str) + # assign value to actual_instance + instance.actual_instance = instance.{{vendorExtensions.x-py-name}} + match += 1 + except ValidationError as e: + error_messages.append(str(e)) + {{/isPrimitiveType}} {{^isPrimitiveType}} # deserialize data into {{{dataType}}} try: @@ -97,6 +149,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} except ValidationError as e: error_messages.append(str(e)) {{/isPrimitiveType}} + {{/isContainer}} {{/composedSchemas.oneOf}} if match > 1: @@ -125,7 +178,3 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} def to_str(self) -> str: """Returns the string representation of the actual instance""" return pprint.pformat(self.dict()) - - - - diff --git a/modules/openapi-generator/src/main/resources/python-nextgen/rest.mustache b/modules/openapi-generator/src/main/resources/python-nextgen/rest.mustache index 37646f94f21b716bd2bc29bbb9cab1cfdb875f28..0e76f4eb996537020c8ed96a0d7a2f6fe5001720 100644 --- a/modules/openapi-generator/src/main/resources/python-nextgen/rest.mustache +++ b/modules/openapi-generator/src/main/resources/python-nextgen/rest.mustache @@ -29,11 +29,11 @@ class RESTResponse(io.IOBase): def getheaders(self): """Returns a dictionary of the response headers.""" - return self.urllib3_response.getheaders() + return self.urllib3_response.headers def getheader(self, name, default=None): """Returns a given response header.""" - return self.urllib3_response.getheader(name, default) + return self.urllib3_response.headers.get(name, default) class RESTClientObject(object): 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 143a7f8a83b4e05c571fb06911065e2c1df84a73..512030a976b9cd8e269c86318aa4dd3b36f805fe 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 @@ -2035,3 +2035,41 @@ components: type: string self_ref: $ref: '#/components/schemas/Self-Reference-Model' + RgbColor: + description: RGB three element array with values 0-255. + type: array + items: + type: integer + minimum: 0 + maximum: 255 + minItems: 3 + maxItems: 3 + RgbaColor: + description: RGBA four element array with values 0-255. + type: array + items: + type: integer + minimum: 0 + maximum: 255 + minItems: 4 + maxItems: 4 + HexColor: + description: 'Hex color string, such as #00FF00.' + type: string + pattern: ^#(?:[0-9a-fA-F]{3}){1,2}$ + minLength: 7 + maxLength: 7 + Color: + nullable: true + description: RGB array, RGBA array, or hex string. + oneOf: + - $ref: '#/components/schemas/RgbColor' + - $ref: '#/components/schemas/RgbaColor' + - $ref: '#/components/schemas/HexColor' + #- type: "null" + AnyOfColor: + description: Any of RGB array, RGBA array, or hex string. + anyOf: + - $ref: '#/components/schemas/RgbColor' + - $ref: '#/components/schemas/RgbaColor' + - $ref: '#/components/schemas/HexColor' diff --git a/samples/client/echo_api/python-nextgen/openapi_client/rest.py b/samples/client/echo_api/python-nextgen/openapi_client/rest.py index cb198913019d67c30024af3322b9227654ddf06b..10adb46f83e4e80cdbc18304742addc83731d214 100644 --- a/samples/client/echo_api/python-nextgen/openapi_client/rest.py +++ b/samples/client/echo_api/python-nextgen/openapi_client/rest.py @@ -38,11 +38,11 @@ class RESTResponse(io.IOBase): def getheaders(self): """Returns a dictionary of the response headers.""" - return self.urllib3_response.getheaders() + return self.urllib3_response.headers def getheader(self, name, default=None): """Returns a given response header.""" - return self.urllib3_response.getheader(name, default) + return self.urllib3_response.headers.get(name, default) class RESTClientObject(object): diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-nextgen-aiohttp/.openapi-generator/FILES index 7bb4db01ebfcb843410d3a2de1ba6a5738ec201b..16c7ff73ab466ab49e5432777d668e7477e7a3b8 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/.openapi-generator/FILES @@ -7,6 +7,7 @@ docs/AdditionalPropertiesClass.md docs/AllOfWithSingleRef.md docs/Animal.md docs/AnotherFakeApi.md +docs/AnyOfColor.md docs/AnyOfPig.md docs/ApiResponse.md docs/ArrayOfArrayOfNumberOnly.md @@ -19,6 +20,7 @@ docs/CatAllOf.md docs/Category.md docs/ClassModel.md docs/Client.md +docs/Color.md docs/DanishPig.md docs/DefaultApi.md docs/DeprecatedObject.md @@ -83,6 +85,7 @@ petstore_api/models/__init__.py petstore_api/models/additional_properties_class.py petstore_api/models/all_of_with_single_ref.py petstore_api/models/animal.py +petstore_api/models/any_of_color.py petstore_api/models/any_of_pig.py petstore_api/models/api_response.py petstore_api/models/array_of_array_of_number_only.py @@ -95,6 +98,7 @@ petstore_api/models/cat_all_of.py petstore_api/models/category.py petstore_api/models/class_model.py petstore_api/models/client.py +petstore_api/models/color.py petstore_api/models/danish_pig.py petstore_api/models/deprecated_object.py petstore_api/models/dog.py diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/README.md b/samples/openapi3/client/petstore/python-nextgen-aiohttp/README.md index 75ca6b713715a9049e18e1266284688b13d7d814..61d98d5c6225ee0d7a280dae1eeaf9c51c012cbf 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/README.md +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/README.md @@ -130,6 +130,7 @@ Class | Method | HTTP request | Description - [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md) - [AllOfWithSingleRef](docs/AllOfWithSingleRef.md) - [Animal](docs/Animal.md) + - [AnyOfColor](docs/AnyOfColor.md) - [AnyOfPig](docs/AnyOfPig.md) - [ApiResponse](docs/ApiResponse.md) - [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md) @@ -142,6 +143,7 @@ Class | Method | HTTP request | Description - [Category](docs/Category.md) - [ClassModel](docs/ClassModel.md) - [Client](docs/Client.md) + - [Color](docs/Color.md) - [DanishPig](docs/DanishPig.md) - [DeprecatedObject](docs/DeprecatedObject.md) - [Dog](docs/Dog.md) diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/AnyOfColor.md b/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/AnyOfColor.md new file mode 100644 index 0000000000000000000000000000000000000000..9b161ccba1c0c55e7a8eb2d72df4460d434215fc --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/AnyOfColor.md @@ -0,0 +1,28 @@ +# AnyOfColor + +Any of RGB array, RGBA array, or hex string. + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- + +## Example + +```python +from petstore_api.models.any_of_color import AnyOfColor + +# TODO update the JSON string below +json = "{}" +# create an instance of AnyOfColor from a JSON string +any_of_color_instance = AnyOfColor.from_json(json) +# print the JSON string representation of the object +print AnyOfColor.to_json() + +# convert the object into a dict +any_of_color_dict = any_of_color_instance.to_dict() +# create an instance of AnyOfColor from a dict +any_of_color_form_dict = any_of_color.from_dict(any_of_color_dict) +``` +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/Color.md b/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/Color.md new file mode 100644 index 0000000000000000000000000000000000000000..07fcd01991ac3367e59b2d91c3ccae84bf87952a --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/Color.md @@ -0,0 +1,28 @@ +# Color + +RGB array, RGBA array, or hex string. + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- + +## Example + +```python +from petstore_api.models.color import Color + +# TODO update the JSON string below +json = "{}" +# create an instance of Color from a JSON string +color_instance = Color.from_json(json) +# print the JSON string representation of the object +print Color.to_json() + +# convert the object into a dict +color_dict = color_instance.to_dict() +# create an instance of Color from a dict +color_form_dict = color.from_dict(color_dict) +``` +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/__init__.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/__init__.py index 6bc4148a4e1e365ef8517a60968b54db1481be39..ff667b0dd140db26c38aa44fdf6d62dd050f91a6 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/__init__.py @@ -38,6 +38,7 @@ from petstore_api.exceptions import ApiException from petstore_api.models.additional_properties_class import AdditionalPropertiesClass from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef from petstore_api.models.animal import Animal +from petstore_api.models.any_of_color import AnyOfColor from petstore_api.models.any_of_pig import AnyOfPig from petstore_api.models.api_response import ApiResponse from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly @@ -50,6 +51,7 @@ from petstore_api.models.cat_all_of import CatAllOf from petstore_api.models.category import Category from petstore_api.models.class_model import ClassModel from petstore_api.models.client import Client +from petstore_api.models.color import Color from petstore_api.models.danish_pig import DanishPig from petstore_api.models.deprecated_object import DeprecatedObject from petstore_api.models.dog import Dog diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/__init__.py index b2660c977b9025a7ac4d7df253d25f38f778d06d..47c33519b11bf9aa918fe45af1b7a85cc8be68ba 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/__init__.py @@ -17,6 +17,7 @@ from __future__ import absolute_import from petstore_api.models.additional_properties_class import AdditionalPropertiesClass from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef from petstore_api.models.animal import Animal +from petstore_api.models.any_of_color import AnyOfColor from petstore_api.models.any_of_pig import AnyOfPig from petstore_api.models.api_response import ApiResponse from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly @@ -29,6 +30,7 @@ from petstore_api.models.cat_all_of import CatAllOf from petstore_api.models.category import Category from petstore_api.models.class_model import ClassModel from petstore_api.models.client import Client +from petstore_api.models.color import Color from petstore_api.models.danish_pig import DanishPig from petstore_api.models.deprecated_object import DeprecatedObject from petstore_api.models.dog import Dog diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/any_of_color.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/any_of_color.py new file mode 100644 index 0000000000000000000000000000000000000000..5f1c71d30b92913d3a726a46b90a7e7655a0803e --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/any_of_color.py @@ -0,0 +1,128 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +from __future__ import annotations +from inspect import getfullargspec +import json +import pprint +import re # noqa: F401 + +from typing import Optional +from pydantic import BaseModel, Field, StrictStr, ValidationError, conint, conlist, constr, validator +from typing import Any, List +from pydantic import StrictStr, Field + +ANYOFCOLOR_ANY_OF_SCHEMAS = ["List[int]", "str"] + +class AnyOfColor(BaseModel): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + # data type: List[int] + anyof_schema_1_validator: Optional[conlist(conint(strict=True, le=255, ge=0), max_items=3, min_items=3)] = Field(None, description="RGB three element array with values 0-255.") + # data type: List[int] + 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.") + actual_instance: Any + any_of_schemas: List[str] = Field(ANYOFCOLOR_ANY_OF_SCHEMAS, const=True) + + class Config: + validate_assignment = True + + @validator('actual_instance') + def actual_instance_must_validate_anyof(cls, v): + instance = cls() + error_messages = [] + # validate data type: List[int] + try: + instance.anyof_schema_1_validator = v + return v + except ValidationError as e: + error_messages.append(str(e)) + # validate data type: List[int] + try: + instance.anyof_schema_2_validator = v + return v + except ValidationError as e: + error_messages.append(str(e)) + # validate data type: str + try: + instance.anyof_schema_3_validator = v + return v + except ValidationError as e: + error_messages.append(str(e)) + if error_messages: + # no match + raise ValueError("No match found when deserializing the JSON string into AnyOfColor with anyOf schemas: List[int], str. Details: " + ", ".join(error_messages)) + else: + return v + + @classmethod + def from_json(cls, json_str: str) -> AnyOfColor: + """Returns the object represented by the json string""" + instance = cls() + error_messages = [] + # deserialize data into List[int] + try: + # validation + instance.anyof_schema_1_validator = json.loads(json_str) + # assign value to actual_instance + instance.actual_instance = instance.anyof_schema_1_validator + return instance + except ValidationError as e: + error_messages.append(str(e)) + # deserialize data into List[int] + try: + # validation + instance.anyof_schema_2_validator = json.loads(json_str) + # assign value to actual_instance + instance.actual_instance = instance.anyof_schema_2_validator + return instance + except ValidationError as e: + error_messages.append(str(e)) + # deserialize data into str + try: + # validation + instance.anyof_schema_3_validator = json.loads(json_str) + # assign value to actual_instance + instance.actual_instance = instance.anyof_schema_3_validator + return instance + except ValidationError as e: + error_messages.append(str(e)) + + if error_messages: + # no match + raise ValueError("No match found when deserializing the JSON string into AnyOfColor with anyOf schemas: List[int], str. Details: " + ", ".join(error_messages)) + else: + return instance + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + if self.actual_instance is not None: + return self.actual_instance.to_json() + else: + return "null" + + def to_dict(self) -> dict: + """Returns the dict representation of the actual instance""" + if self.actual_instance is not None: + return self.actual_instance.to_dict() + else: + return dict() + + def to_str(self) -> str: + """Returns the string representation of the actual instance""" + return pprint.pformat(self.dict()) + diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/any_of_pig.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/any_of_pig.py index 0841de932034ab1886b19a9e84a20684cf2cf567..1a3e364ea71fe5d1a93d8998daa6e53c0242277e 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/any_of_pig.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/any_of_pig.py @@ -12,6 +12,7 @@ from __future__ import annotations from inspect import getfullargspec +import json import pprint import re # noqa: F401 @@ -31,9 +32,9 @@ class AnyOfPig(BaseModel): Do not edit the class manually. """ # data type: BasquePig - __anyof_schema_1: Optional[BasquePig] = None + anyof_schema_1_validator: Optional[BasquePig] = None # data type: DanishPig - __anyof_schema_2: Optional[DanishPig] = None + anyof_schema_2_validator: Optional[DanishPig] = None actual_instance: Any any_of_schemas: List[str] = Field(ANYOFPIG_ANY_OF_SCHEMAS, const=True) @@ -42,6 +43,7 @@ class AnyOfPig(BaseModel): @validator('actual_instance') def actual_instance_must_validate_anyof(cls, v): + instance = cls() error_messages = [] # validate data type: BasquePig if type(v) is not BasquePig: @@ -66,13 +68,13 @@ class AnyOfPig(BaseModel): """Returns the object represented by the json string""" instance = cls() error_messages = [] - # __anyof_schema_1: Optional[BasquePig] = None + # anyof_schema_1_validator: Optional[BasquePig] = None try: instance.actual_instance = BasquePig.from_json(json_str) return instance except ValidationError as e: error_messages.append(str(e)) - # __anyof_schema_2: Optional[DanishPig] = None + # anyof_schema_2_validator: Optional[DanishPig] = None try: instance.actual_instance = DanishPig.from_json(json_str) return instance diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/array_test.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/array_test.py index 6c640b42278a8c405465cba60c5b8092f1d837a8..71506cb522bd7a9e9c656b7d03d63c141c6a25a6 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/array_test.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/array_test.py @@ -18,7 +18,7 @@ import json from typing import List, Optional -from pydantic import BaseModel, StrictInt, StrictStr +from pydantic import BaseModel, StrictInt, StrictStr, conlist from petstore_api.models.read_only_first import ReadOnlyFirst class ArrayTest(BaseModel): @@ -27,7 +27,7 @@ class ArrayTest(BaseModel): Do not edit the class manually. """ - array_of_string: Optional[List[StrictStr]] = None + array_of_string: Optional[conlist(StrictStr, max_items=3, min_items=0)] = None array_array_of_integer: Optional[List[List[StrictInt]]] = None array_array_of_model: Optional[List[List[ReadOnlyFirst]]] = None __properties = ["array_of_string", "array_array_of_integer", "array_array_of_model"] diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/color.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/color.py new file mode 100644 index 0000000000000000000000000000000000000000..45d2d0d8f435a1cc2cd28455da6e8b13173ed000 --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/color.py @@ -0,0 +1,147 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +from __future__ import annotations +from inspect import getfullargspec +import json +import pprint +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 pydantic import StrictStr, Field + +COLOR_ONE_OF_SCHEMAS = ["List[int]", "str"] + +class Color(BaseModel): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + # data type: List[int] + oneof_schema_1_validator: Optional[conlist(conint(strict=True, le=255, ge=0), max_items=3, min_items=3)] = Field(None, description="RGB three element array with values 0-255.") + # data type: List[int] + 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.") + actual_instance: Any + one_of_schemas: List[str] = Field(COLOR_ONE_OF_SCHEMAS, const=True) + + class Config: + validate_assignment = True + + @validator('actual_instance') + def actual_instance_must_validate_oneof(cls, v): + if v is None: + return v + + instance = cls() + error_messages = [] + match = 0 + # validate data type: List[int] + try: + instance.oneof_schema_1_validator = v + match += 1 + except ValidationError as e: + error_messages.append(str(e)) + # validate data type: List[int] + try: + instance.oneof_schema_2_validator = v + match += 1 + except ValidationError as e: + error_messages.append(str(e)) + # validate data type: str + try: + instance.oneof_schema_3_validator = v + match += 1 + except ValidationError as e: + error_messages.append(str(e)) + if match > 1: + # more than 1 match + raise ValueError("Multiple matches found when deserializing the JSON string into Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) + elif match == 0: + # no match + raise ValueError("No match found when deserializing the JSON string into Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) + else: + return v + + @classmethod + def from_dict(cls, obj: dict) -> Color: + return cls.from_json(json.dumps(obj)) + + @classmethod + def from_json(cls, json_str: str) -> Color: + """Returns the object represented by the json string""" + instance = cls() + if json_str is None: + return instance + + error_messages = [] + match = 0 + + # deserialize data into List[int] + try: + # validation + instance.oneof_schema_1_validator = json.loads(json_str) + # assign value to actual_instance + instance.actual_instance = instance.oneof_schema_1_validator + match += 1 + except ValidationError as e: + error_messages.append(str(e)) + # deserialize data into List[int] + try: + # validation + instance.oneof_schema_2_validator = json.loads(json_str) + # assign value to actual_instance + instance.actual_instance = instance.oneof_schema_2_validator + match += 1 + except ValidationError as e: + error_messages.append(str(e)) + # deserialize data into str + try: + # validation + instance.oneof_schema_3_validator = json.loads(json_str) + # assign value to actual_instance + instance.actual_instance = instance.oneof_schema_3_validator + match += 1 + except ValidationError as e: + error_messages.append(str(e)) + + if match > 1: + # more than 1 match + raise ValueError("Multiple matches found when deserializing the JSON string into Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) + elif match == 0: + # no match + raise ValueError("No match found when deserializing the JSON string into Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) + else: + return instance + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + if self.actual_instance is not None: + return self.actual_instance.to_json() + else: + return "null" + + def to_dict(self) -> dict: + """Returns the dict representation of the actual instance""" + if self.actual_instance is not None: + return self.actual_instance.to_dict() + else: + return dict() + + def to_str(self) -> str: + """Returns the string representation of the actual instance""" + return pprint.pformat(self.dict()) + diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/pig.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/pig.py index 7e98106feae204bd04adee8d3bd12c59080f5b38..77abb2d6703cf0d8f48a14da50a1aceb9f693ba0 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/pig.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/pig.py @@ -12,8 +12,8 @@ from __future__ import annotations from inspect import getfullargspec -import pprint import json +import pprint import re # noqa: F401 from typing import Any, List, Optional @@ -32,9 +32,9 @@ class Pig(BaseModel): Do not edit the class manually. """ # data type: BasquePig - __oneof_schema_1: Optional[BasquePig] = None + oneof_schema_1_validator: Optional[BasquePig] = None # data type: DanishPig - __oneof_schema_2: Optional[DanishPig] = None + oneof_schema_2_validator: Optional[DanishPig] = None actual_instance: Any one_of_schemas: List[str] = Field(PIG_ONE_OF_SCHEMAS, const=True) @@ -46,6 +46,7 @@ class Pig(BaseModel): @validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): + instance = cls() error_messages = [] match = 0 # validate data type: BasquePig @@ -120,7 +121,3 @@ class Pig(BaseModel): """Returns the string representation of the actual instance""" return pprint.pformat(self.dict()) - - - - diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/test/test_any_of_color.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/test/test_any_of_color.py new file mode 100644 index 0000000000000000000000000000000000000000..2a97cfef7526b494eb60668e7430964784eaf113 --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/test/test_any_of_color.py @@ -0,0 +1,53 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +import unittest +import datetime + +import petstore_api +from petstore_api.models.any_of_color import AnyOfColor # noqa: E501 +from petstore_api.rest import ApiException + +class TestAnyOfColor(unittest.TestCase): + """AnyOfColor unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional): + """Test AnyOfColor + include_option is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `AnyOfColor` + """ + model = petstore_api.models.any_of_color.AnyOfColor() # noqa: E501 + if include_optional : + return AnyOfColor( + ) + else : + return AnyOfColor( + ) + """ + + def testAnyOfColor(self): + """Test AnyOfColor""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/test/test_color.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/test/test_color.py new file mode 100644 index 0000000000000000000000000000000000000000..9a7aabfea2534f3552266ed5d51c43d3c39b836f --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/test/test_color.py @@ -0,0 +1,53 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +import unittest +import datetime + +import petstore_api +from petstore_api.models.color import Color # noqa: E501 +from petstore_api.rest import ApiException + +class TestColor(unittest.TestCase): + """Color unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional): + """Test Color + include_option is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `Color` + """ + model = petstore_api.models.color.Color() # noqa: E501 + if include_optional : + return Color( + ) + else : + return Color( + ) + """ + + def testColor(self): + """Test Color""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-nextgen/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-nextgen/.openapi-generator/FILES index 6de662a87b4163ba3e7bd52d34fedd0637ca2508..b8e0a20aec67bc20aec6f719cbbaf7cdb89205b1 100755 --- a/samples/openapi3/client/petstore/python-nextgen/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-nextgen/.openapi-generator/FILES @@ -7,6 +7,7 @@ docs/AdditionalPropertiesClass.md docs/AllOfWithSingleRef.md docs/Animal.md docs/AnotherFakeApi.md +docs/AnyOfColor.md docs/AnyOfPig.md docs/ApiResponse.md docs/ArrayOfArrayOfNumberOnly.md @@ -19,6 +20,7 @@ docs/CatAllOf.md docs/Category.md docs/ClassModel.md docs/Client.md +docs/Color.md docs/DanishPig.md docs/DefaultApi.md docs/DeprecatedObject.md @@ -83,6 +85,7 @@ petstore_api/models/__init__.py petstore_api/models/additional_properties_class.py petstore_api/models/all_of_with_single_ref.py petstore_api/models/animal.py +petstore_api/models/any_of_color.py petstore_api/models/any_of_pig.py petstore_api/models/api_response.py petstore_api/models/array_of_array_of_number_only.py @@ -95,6 +98,7 @@ petstore_api/models/cat_all_of.py petstore_api/models/category.py petstore_api/models/class_model.py petstore_api/models/client.py +petstore_api/models/color.py petstore_api/models/danish_pig.py petstore_api/models/deprecated_object.py petstore_api/models/dog.py diff --git a/samples/openapi3/client/petstore/python-nextgen/README.md b/samples/openapi3/client/petstore/python-nextgen/README.md index 75129c61f4d18adf9d13fb4877eee56fd6b6ef2a..595e187329e3d6f87a61ede3b622f4d5f3d4e6e7 100755 --- a/samples/openapi3/client/petstore/python-nextgen/README.md +++ b/samples/openapi3/client/petstore/python-nextgen/README.md @@ -130,6 +130,7 @@ Class | Method | HTTP request | Description - [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md) - [AllOfWithSingleRef](docs/AllOfWithSingleRef.md) - [Animal](docs/Animal.md) + - [AnyOfColor](docs/AnyOfColor.md) - [AnyOfPig](docs/AnyOfPig.md) - [ApiResponse](docs/ApiResponse.md) - [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md) @@ -142,6 +143,7 @@ Class | Method | HTTP request | Description - [Category](docs/Category.md) - [ClassModel](docs/ClassModel.md) - [Client](docs/Client.md) + - [Color](docs/Color.md) - [DanishPig](docs/DanishPig.md) - [DeprecatedObject](docs/DeprecatedObject.md) - [Dog](docs/Dog.md) diff --git a/samples/openapi3/client/petstore/python-nextgen/docs/AnyOfColor.md b/samples/openapi3/client/petstore/python-nextgen/docs/AnyOfColor.md new file mode 100644 index 0000000000000000000000000000000000000000..9b161ccba1c0c55e7a8eb2d72df4460d434215fc --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/docs/AnyOfColor.md @@ -0,0 +1,28 @@ +# AnyOfColor + +Any of RGB array, RGBA array, or hex string. + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- + +## Example + +```python +from petstore_api.models.any_of_color import AnyOfColor + +# TODO update the JSON string below +json = "{}" +# create an instance of AnyOfColor from a JSON string +any_of_color_instance = AnyOfColor.from_json(json) +# print the JSON string representation of the object +print AnyOfColor.to_json() + +# convert the object into a dict +any_of_color_dict = any_of_color_instance.to_dict() +# create an instance of AnyOfColor from a dict +any_of_color_form_dict = any_of_color.from_dict(any_of_color_dict) +``` +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/python-nextgen/docs/Color.md b/samples/openapi3/client/petstore/python-nextgen/docs/Color.md new file mode 100644 index 0000000000000000000000000000000000000000..07fcd01991ac3367e59b2d91c3ccae84bf87952a --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/docs/Color.md @@ -0,0 +1,28 @@ +# Color + +RGB array, RGBA array, or hex string. + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- + +## Example + +```python +from petstore_api.models.color import Color + +# TODO update the JSON string below +json = "{}" +# create an instance of Color from a JSON string +color_instance = Color.from_json(json) +# print the JSON string representation of the object +print Color.to_json() + +# convert the object into a dict +color_dict = color_instance.to_dict() +# create an instance of Color from a dict +color_form_dict = color.from_dict(color_dict) +``` +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/python-nextgen/petstore_api/__init__.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/__init__.py index 6bc4148a4e1e365ef8517a60968b54db1481be39..ff667b0dd140db26c38aa44fdf6d62dd050f91a6 100755 --- a/samples/openapi3/client/petstore/python-nextgen/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/__init__.py @@ -38,6 +38,7 @@ from petstore_api.exceptions import ApiException from petstore_api.models.additional_properties_class import AdditionalPropertiesClass from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef from petstore_api.models.animal import Animal +from petstore_api.models.any_of_color import AnyOfColor from petstore_api.models.any_of_pig import AnyOfPig from petstore_api.models.api_response import ApiResponse from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly @@ -50,6 +51,7 @@ from petstore_api.models.cat_all_of import CatAllOf from petstore_api.models.category import Category from petstore_api.models.class_model import ClassModel from petstore_api.models.client import Client +from petstore_api.models.color import Color from petstore_api.models.danish_pig import DanishPig from petstore_api.models.deprecated_object import DeprecatedObject from petstore_api.models.dog import Dog diff --git a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/__init__.py index b2660c977b9025a7ac4d7df253d25f38f778d06d..47c33519b11bf9aa918fe45af1b7a85cc8be68ba 100644 --- a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/__init__.py @@ -17,6 +17,7 @@ from __future__ import absolute_import from petstore_api.models.additional_properties_class import AdditionalPropertiesClass from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef from petstore_api.models.animal import Animal +from petstore_api.models.any_of_color import AnyOfColor from petstore_api.models.any_of_pig import AnyOfPig from petstore_api.models.api_response import ApiResponse from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly @@ -29,6 +30,7 @@ from petstore_api.models.cat_all_of import CatAllOf from petstore_api.models.category import Category from petstore_api.models.class_model import ClassModel from petstore_api.models.client import Client +from petstore_api.models.color import Color from petstore_api.models.danish_pig import DanishPig from petstore_api.models.deprecated_object import DeprecatedObject from petstore_api.models.dog import Dog diff --git a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/any_of_color.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/any_of_color.py new file mode 100644 index 0000000000000000000000000000000000000000..5f1c71d30b92913d3a726a46b90a7e7655a0803e --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/any_of_color.py @@ -0,0 +1,128 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +from __future__ import annotations +from inspect import getfullargspec +import json +import pprint +import re # noqa: F401 + +from typing import Optional +from pydantic import BaseModel, Field, StrictStr, ValidationError, conint, conlist, constr, validator +from typing import Any, List +from pydantic import StrictStr, Field + +ANYOFCOLOR_ANY_OF_SCHEMAS = ["List[int]", "str"] + +class AnyOfColor(BaseModel): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + # data type: List[int] + anyof_schema_1_validator: Optional[conlist(conint(strict=True, le=255, ge=0), max_items=3, min_items=3)] = Field(None, description="RGB three element array with values 0-255.") + # data type: List[int] + 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.") + actual_instance: Any + any_of_schemas: List[str] = Field(ANYOFCOLOR_ANY_OF_SCHEMAS, const=True) + + class Config: + validate_assignment = True + + @validator('actual_instance') + def actual_instance_must_validate_anyof(cls, v): + instance = cls() + error_messages = [] + # validate data type: List[int] + try: + instance.anyof_schema_1_validator = v + return v + except ValidationError as e: + error_messages.append(str(e)) + # validate data type: List[int] + try: + instance.anyof_schema_2_validator = v + return v + except ValidationError as e: + error_messages.append(str(e)) + # validate data type: str + try: + instance.anyof_schema_3_validator = v + return v + except ValidationError as e: + error_messages.append(str(e)) + if error_messages: + # no match + raise ValueError("No match found when deserializing the JSON string into AnyOfColor with anyOf schemas: List[int], str. Details: " + ", ".join(error_messages)) + else: + return v + + @classmethod + def from_json(cls, json_str: str) -> AnyOfColor: + """Returns the object represented by the json string""" + instance = cls() + error_messages = [] + # deserialize data into List[int] + try: + # validation + instance.anyof_schema_1_validator = json.loads(json_str) + # assign value to actual_instance + instance.actual_instance = instance.anyof_schema_1_validator + return instance + except ValidationError as e: + error_messages.append(str(e)) + # deserialize data into List[int] + try: + # validation + instance.anyof_schema_2_validator = json.loads(json_str) + # assign value to actual_instance + instance.actual_instance = instance.anyof_schema_2_validator + return instance + except ValidationError as e: + error_messages.append(str(e)) + # deserialize data into str + try: + # validation + instance.anyof_schema_3_validator = json.loads(json_str) + # assign value to actual_instance + instance.actual_instance = instance.anyof_schema_3_validator + return instance + except ValidationError as e: + error_messages.append(str(e)) + + if error_messages: + # no match + raise ValueError("No match found when deserializing the JSON string into AnyOfColor with anyOf schemas: List[int], str. Details: " + ", ".join(error_messages)) + else: + return instance + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + if self.actual_instance is not None: + return self.actual_instance.to_json() + else: + return "null" + + def to_dict(self) -> dict: + """Returns the dict representation of the actual instance""" + if self.actual_instance is not None: + return self.actual_instance.to_dict() + else: + return dict() + + def to_str(self) -> str: + """Returns the string representation of the actual instance""" + return pprint.pformat(self.dict()) + diff --git a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/any_of_pig.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/any_of_pig.py index 0841de932034ab1886b19a9e84a20684cf2cf567..1a3e364ea71fe5d1a93d8998daa6e53c0242277e 100644 --- a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/any_of_pig.py +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/any_of_pig.py @@ -12,6 +12,7 @@ from __future__ import annotations from inspect import getfullargspec +import json import pprint import re # noqa: F401 @@ -31,9 +32,9 @@ class AnyOfPig(BaseModel): Do not edit the class manually. """ # data type: BasquePig - __anyof_schema_1: Optional[BasquePig] = None + anyof_schema_1_validator: Optional[BasquePig] = None # data type: DanishPig - __anyof_schema_2: Optional[DanishPig] = None + anyof_schema_2_validator: Optional[DanishPig] = None actual_instance: Any any_of_schemas: List[str] = Field(ANYOFPIG_ANY_OF_SCHEMAS, const=True) @@ -42,6 +43,7 @@ class AnyOfPig(BaseModel): @validator('actual_instance') def actual_instance_must_validate_anyof(cls, v): + instance = cls() error_messages = [] # validate data type: BasquePig if type(v) is not BasquePig: @@ -66,13 +68,13 @@ class AnyOfPig(BaseModel): """Returns the object represented by the json string""" instance = cls() error_messages = [] - # __anyof_schema_1: Optional[BasquePig] = None + # anyof_schema_1_validator: Optional[BasquePig] = None try: instance.actual_instance = BasquePig.from_json(json_str) return instance except ValidationError as e: error_messages.append(str(e)) - # __anyof_schema_2: Optional[DanishPig] = None + # anyof_schema_2_validator: Optional[DanishPig] = None try: instance.actual_instance = DanishPig.from_json(json_str) return instance diff --git a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/array_test.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/array_test.py index c113981470ea6099accae9e6e62c181f5297d9fb..0158ab990d27c10fd1499fc5a3dcded1e90a8d74 100644 --- a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/array_test.py +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/array_test.py @@ -18,7 +18,7 @@ import json from typing import List, Optional -from pydantic import BaseModel, StrictInt, StrictStr +from pydantic import BaseModel, StrictInt, StrictStr, conlist from petstore_api.models.read_only_first import ReadOnlyFirst class ArrayTest(BaseModel): @@ -27,7 +27,7 @@ class ArrayTest(BaseModel): Do not edit the class manually. """ - array_of_string: Optional[List[StrictStr]] = None + array_of_string: Optional[conlist(StrictStr, max_items=3, min_items=0)] = None array_array_of_integer: Optional[List[List[StrictInt]]] = None array_array_of_model: Optional[List[List[ReadOnlyFirst]]] = None additional_properties: Dict[str, Any] = {} diff --git a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/color.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/color.py new file mode 100644 index 0000000000000000000000000000000000000000..45d2d0d8f435a1cc2cd28455da6e8b13173ed000 --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/color.py @@ -0,0 +1,147 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +from __future__ import annotations +from inspect import getfullargspec +import json +import pprint +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 pydantic import StrictStr, Field + +COLOR_ONE_OF_SCHEMAS = ["List[int]", "str"] + +class Color(BaseModel): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + # data type: List[int] + oneof_schema_1_validator: Optional[conlist(conint(strict=True, le=255, ge=0), max_items=3, min_items=3)] = Field(None, description="RGB three element array with values 0-255.") + # data type: List[int] + 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.") + actual_instance: Any + one_of_schemas: List[str] = Field(COLOR_ONE_OF_SCHEMAS, const=True) + + class Config: + validate_assignment = True + + @validator('actual_instance') + def actual_instance_must_validate_oneof(cls, v): + if v is None: + return v + + instance = cls() + error_messages = [] + match = 0 + # validate data type: List[int] + try: + instance.oneof_schema_1_validator = v + match += 1 + except ValidationError as e: + error_messages.append(str(e)) + # validate data type: List[int] + try: + instance.oneof_schema_2_validator = v + match += 1 + except ValidationError as e: + error_messages.append(str(e)) + # validate data type: str + try: + instance.oneof_schema_3_validator = v + match += 1 + except ValidationError as e: + error_messages.append(str(e)) + if match > 1: + # more than 1 match + raise ValueError("Multiple matches found when deserializing the JSON string into Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) + elif match == 0: + # no match + raise ValueError("No match found when deserializing the JSON string into Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) + else: + return v + + @classmethod + def from_dict(cls, obj: dict) -> Color: + return cls.from_json(json.dumps(obj)) + + @classmethod + def from_json(cls, json_str: str) -> Color: + """Returns the object represented by the json string""" + instance = cls() + if json_str is None: + return instance + + error_messages = [] + match = 0 + + # deserialize data into List[int] + try: + # validation + instance.oneof_schema_1_validator = json.loads(json_str) + # assign value to actual_instance + instance.actual_instance = instance.oneof_schema_1_validator + match += 1 + except ValidationError as e: + error_messages.append(str(e)) + # deserialize data into List[int] + try: + # validation + instance.oneof_schema_2_validator = json.loads(json_str) + # assign value to actual_instance + instance.actual_instance = instance.oneof_schema_2_validator + match += 1 + except ValidationError as e: + error_messages.append(str(e)) + # deserialize data into str + try: + # validation + instance.oneof_schema_3_validator = json.loads(json_str) + # assign value to actual_instance + instance.actual_instance = instance.oneof_schema_3_validator + match += 1 + except ValidationError as e: + error_messages.append(str(e)) + + if match > 1: + # more than 1 match + raise ValueError("Multiple matches found when deserializing the JSON string into Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) + elif match == 0: + # no match + raise ValueError("No match found when deserializing the JSON string into Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) + else: + return instance + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + if self.actual_instance is not None: + return self.actual_instance.to_json() + else: + return "null" + + def to_dict(self) -> dict: + """Returns the dict representation of the actual instance""" + if self.actual_instance is not None: + return self.actual_instance.to_dict() + else: + return dict() + + def to_str(self) -> str: + """Returns the string representation of the actual instance""" + return pprint.pformat(self.dict()) + diff --git a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/pig.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/pig.py index e4ec570fe82b21a72556c723d53de01875347100..0799371faa488648c686435cb3626dbbaffdd12d 100644 --- a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/pig.py +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/pig.py @@ -12,8 +12,8 @@ from __future__ import annotations from inspect import getfullargspec -import pprint import json +import pprint import re # noqa: F401 from typing import Any, List, Optional @@ -32,9 +32,9 @@ class Pig(BaseModel): Do not edit the class manually. """ # data type: BasquePig - __oneof_schema_1: Optional[BasquePig] = None + oneof_schema_1_validator: Optional[BasquePig] = None # data type: DanishPig - __oneof_schema_2: Optional[DanishPig] = None + oneof_schema_2_validator: Optional[DanishPig] = None actual_instance: Any one_of_schemas: List[str] = Field(PIG_ONE_OF_SCHEMAS, const=True) @@ -46,6 +46,7 @@ class Pig(BaseModel): @validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): + instance = cls() error_messages = [] match = 0 # validate data type: BasquePig @@ -135,7 +136,3 @@ class Pig(BaseModel): """Returns the string representation of the actual instance""" return pprint.pformat(self.dict()) - - - - diff --git a/samples/openapi3/client/petstore/python-nextgen/petstore_api/rest.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/rest.py index 707cbc01288d25428c916b2d43ef16956e19fd8e..c2c0630f61fa1b250f290b81c5d8baa2f429c350 100755 --- a/samples/openapi3/client/petstore/python-nextgen/petstore_api/rest.py +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/rest.py @@ -37,11 +37,11 @@ class RESTResponse(io.IOBase): def getheaders(self): """Returns a dictionary of the response headers.""" - return self.urllib3_response.getheaders() + return self.urllib3_response.headers def getheader(self, name, default=None): """Returns a given response header.""" - return self.urllib3_response.getheader(name, default) + return self.urllib3_response.headers.get(name, default) class RESTClientObject(object): diff --git a/samples/openapi3/client/petstore/python-nextgen/test/test_any_of_color.py b/samples/openapi3/client/petstore/python-nextgen/test/test_any_of_color.py new file mode 100644 index 0000000000000000000000000000000000000000..2a97cfef7526b494eb60668e7430964784eaf113 --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/test/test_any_of_color.py @@ -0,0 +1,53 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +import unittest +import datetime + +import petstore_api +from petstore_api.models.any_of_color import AnyOfColor # noqa: E501 +from petstore_api.rest import ApiException + +class TestAnyOfColor(unittest.TestCase): + """AnyOfColor unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional): + """Test AnyOfColor + include_option is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `AnyOfColor` + """ + model = petstore_api.models.any_of_color.AnyOfColor() # noqa: E501 + if include_optional : + return AnyOfColor( + ) + else : + return AnyOfColor( + ) + """ + + def testAnyOfColor(self): + """Test AnyOfColor""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-nextgen/test/test_color.py b/samples/openapi3/client/petstore/python-nextgen/test/test_color.py new file mode 100644 index 0000000000000000000000000000000000000000..9a7aabfea2534f3552266ed5d51c43d3c39b836f --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/test/test_color.py @@ -0,0 +1,53 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +import unittest +import datetime + +import petstore_api +from petstore_api.models.color import Color # noqa: E501 +from petstore_api.rest import ApiException + +class TestColor(unittest.TestCase): + """Color unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional): + """Test Color + include_option is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `Color` + """ + model = petstore_api.models.color.Color() # noqa: E501 + if include_optional : + return Color( + ) + else : + return Color( + ) + """ + + def testColor(self): + """Test Color""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-nextgen/tests/test_model.py b/samples/openapi3/client/petstore/python-nextgen/tests/test_model.py index 7afbb9c4ecf852c3fcd7953e6c95a36fdbfc7f3b..0048461b52af517d07b19ed6370c40eb05cb7b03 100644 --- a/samples/openapi3/client/petstore/python-nextgen/tests/test_model.py +++ b/samples/openapi3/client/petstore/python-nextgen/tests/test_model.py @@ -2,7 +2,7 @@ # flake8: noqa - +import json import os import time import unittest @@ -73,6 +73,83 @@ class ModelTests(unittest.TestCase): self.pet1.tags = [] self.assertFalse(self.pet1 == self.pet2) + def test_oneOf_array_of_integers(self): + # test new Color + new_color = petstore_api.Color() + self.assertEqual("null", new_color.to_json()) + self.assertEqual(None, new_color.actual_instance) + + # test the oneof schema validator + json_str = '[12,34,56]' + array_of_integers = json.loads(json_str) + # no error should be thrown + new_color.oneof_schema_1_validator = array_of_integers + new_color.actual_instance = array_of_integers + new_color.actual_instance = None + + # test the oneof schema validator with invalid input + json_str = '[12,34,56120938]' + array_of_integers = json.loads(json_str) + try: + new_color.oneof_schema_1_validator = array_of_integers + except ValueError as e: + self.assertTrue("ensure this value is less than or equal to 255" in str(e)) + + try: + new_color.actual_instance = array_of_integers + except ValueError as e: + self.assertTrue("ensure this value is less than or equal to 255" in str(e)) + + # test from_josn + json_str = '[12,34,56]' + p = petstore_api.Color.from_json(json_str) + self.assertEqual(p.actual_instance, [12, 34,56]) + + try: + p = petstore_api.Color.from_json('[2342112,0,0,0]') + except ValueError as e: + self.assertTrue("ensure this value is less than or equal to 255" in str(e)) + + # test nullable + p = petstore_api.Color.from_json(None) + self.assertEqual(p.actual_instance, None) + + def test_anyOf_array_of_integers(self): + # test new Color + new_color = petstore_api.AnyOfColor() + self.assertEqual("null", new_color.to_json()) + self.assertEqual(None, new_color.actual_instance) + + # test the oneof schema validator + json_str = '[12,34,56]' + array_of_integers = json.loads(json_str) + # no error should be thrown + new_color.anyof_schema_1_validator = array_of_integers + new_color.actual_instance = array_of_integers + + # test the oneof schema validator with invalid input + json_str = '[12,34,56120938]' + array_of_integers = json.loads(json_str) + try: + new_color.anyof_schema_1_validator = array_of_integers + except ValueError as e: + self.assertTrue("ensure this value is less than or equal to 255" in str(e)) + + try: + new_color.actual_instance = array_of_integers + except ValueError as e: + self.assertTrue("ensure this value is less than or equal to 255" in str(e)) + + # test from_josn + json_str = '[12,34,56]' + p = petstore_api.AnyOfColor.from_json(json_str) + self.assertEqual(p.actual_instance, [12, 34,56]) + + try: + p = petstore_api.AnyOfColor.from_json('[2342112,0,0,0]') + except ValueError as e: + self.assertTrue("ensure this value is less than or equal to 255" in str(e)) + def test_oneOf(self): # test new Pig new_pig = petstore_api.Pig()