From 8994ec33e580c527906e9c85d5ce6dbdd138ff87 Mon Sep 17 00:00:00 2001 From: mtovts Date: Thu, 22 Jul 2021 11:36:15 +0300 Subject: [PATCH 01/57] Fix: `PathItem` parameters overriding in `Operation` --- openapi_python_client/parser/openapi.py | 48 ++++++++++--------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index e22b43a7c..df990417a 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -1,4 +1,3 @@ -import itertools from copy import deepcopy from dataclasses import dataclass, field from typing import Any, Dict, Iterator, List, Optional, Set, Tuple, Union @@ -9,6 +8,7 @@ from .. import schema as oai from .. import utils from ..config import Config +from ..utils import PythonIdentifier from .errors import GeneratorError, ParseError, PropertyError from .properties import Class, EnumProperty, ModelProperty, Property, Schemas, build_schemas, property_from_data from .responses import Response, response_from_data @@ -46,10 +46,17 @@ def from_data( endpoint, schemas = Endpoint.from_data( data=operation, path=path, method=method, tag=tag, schemas=schemas, config=config ) + # Add `PathItem` parameters if not isinstance(endpoint, ParseError): endpoint, schemas = Endpoint._add_parameters( endpoint=endpoint, data=path_data, schemas=schemas, config=config ) + # Add `Operation` parameters + if not isinstance(endpoint, ParseError): + endpoint, schemas = Endpoint._add_parameters( + endpoint=endpoint, data=operation, schemas=schemas, config=config + ) + if isinstance(endpoint, ParseError): endpoint.header = ( f"ERROR parsing {method.upper()} {path} within {tag}. Endpoint will not be generated." @@ -88,10 +95,10 @@ class Endpoint: tag: str summary: Optional[str] = "" relative_imports: Set[str] = field(default_factory=set) - query_parameters: List[Property] = field(default_factory=list) - path_parameters: List[Property] = field(default_factory=list) - header_parameters: List[Property] = field(default_factory=list) - cookie_parameters: List[Property] = field(default_factory=list) + query_parameters: Dict[PythonIdentifier, Property] = field(default_factory=dict) + path_parameters: Dict[PythonIdentifier, Property] = field(default_factory=dict) + header_parameters: Dict[PythonIdentifier, Property] = field(default_factory=dict) + cookie_parameters: Dict[PythonIdentifier, Property] = field(default_factory=dict) responses: List[Response] = field(default_factory=list) form_body_class: Optional[Class] = None json_body: Optional[Property] = None @@ -241,7 +248,6 @@ def _add_parameters( *, endpoint: "Endpoint", data: Union[oai.Operation, oai.PathItem], schemas: Schemas, config: Config ) -> Tuple[Union["Endpoint", ParseError], Schemas]: endpoint = deepcopy(endpoint) - used_python_names: Dict[str, Tuple[Property, oai.ParameterLocation]] = {} if data.parameters is None: return endpoint, schemas for param in data.parameters: @@ -258,38 +264,22 @@ def _add_parameters( if isinstance(prop, ParseError): return ParseError(detail=f"cannot parse parameter of endpoint {endpoint.name}", data=prop.data), schemas - if prop.python_name in used_python_names: - duplicate, duplicate_location = used_python_names[prop.python_name] - if duplicate.python_name == prop.python_name: # Existing should be converted too for consistency - duplicate.set_python_name(f"{duplicate.python_name}_{duplicate_location}", config=config) - prop.set_python_name(f"{prop.python_name}_{param.param_in}", config=config) - else: - used_python_names[prop.python_name] = (prop, param.param_in) - endpoint.relative_imports.update(prop.get_imports(prefix="...")) + prop.set_python_name(new_name=f"{param.name}_{param.param_in}", config=config) + new_prop = {prop.python_name: prop} + if param.param_in == oai.ParameterLocation.QUERY: - endpoint.query_parameters.append(prop) + endpoint.query_parameters.update(new_prop) elif param.param_in == oai.ParameterLocation.PATH: - endpoint.path_parameters.append(prop) + endpoint.path_parameters.update(new_prop) elif param.param_in == oai.ParameterLocation.HEADER: - endpoint.header_parameters.append(prop) + endpoint.header_parameters.update(new_prop) elif param.param_in == oai.ParameterLocation.COOKIE: - endpoint.cookie_parameters.append(prop) + endpoint.cookie_parameters.update(new_prop) else: return ParseError(data=param, detail="Parameter must be declared in path or query"), schemas - name_check = set() - for prop in itertools.chain( - endpoint.query_parameters, endpoint.path_parameters, endpoint.header_parameters, endpoint.cookie_parameters - ): - if prop.python_name in name_check: - return ( - ParseError(data=data, detail=f"Could not reconcile duplicate parameters named {prop.python_name}"), - schemas, - ) - name_check.add(prop.python_name) - return endpoint, schemas @staticmethod From dfc9e5a9a9c8f3ead9ad8e9aebc2bae968d32dde Mon Sep 17 00:00:00 2001 From: mtovts Date: Thu, 22 Jul 2021 11:37:33 +0300 Subject: [PATCH 02/57] Update `templates\endpoint_*` to correct work with parameters --- .../templates/endpoint_macros.py.jinja | 26 +++++++++---------- .../templates/endpoint_module.py.jinja | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/openapi_python_client/templates/endpoint_macros.py.jinja b/openapi_python_client/templates/endpoint_macros.py.jinja index add4c68b2..a7591bea6 100644 --- a/openapi_python_client/templates/endpoint_macros.py.jinja +++ b/openapi_python_client/templates/endpoint_macros.py.jinja @@ -1,6 +1,6 @@ {% macro header_params(endpoint) %} {% if endpoint.header_parameters %} - {% for parameter in endpoint.header_parameters %} + {% for _, parameter in endpoint.header_parameters.items() %} {% if parameter.required %} headers["{{ parameter.python_name | kebabcase}}"] = {{ parameter.python_name }} {% else %} @@ -13,7 +13,7 @@ if {{ parameter.python_name }} is not UNSET: {% macro cookie_params(endpoint) %} {% if endpoint.cookie_parameters %} - {% for parameter in endpoint.cookie_parameters %} + {% for _, parameter in endpoint.cookie_parameters.items() %} {% if parameter.required %} cookies["{{ parameter.name}}"] = {{ parameter.python_name }} {% else %} @@ -27,7 +27,7 @@ if {{ parameter.python_name }} is not UNSET: {% macro query_params(endpoint) %} {% if endpoint.query_parameters %} - {% for property in endpoint.query_parameters %} + {% for _, property in endpoint.query_parameters.items() %} {% set destination = "json_" + property.python_name %} {% if property.template %} {% from "property_templates/" + property.template import transform %} @@ -35,7 +35,7 @@ if {{ parameter.python_name }} is not UNSET: {% endif %} {% endfor %} params: Dict[str, Any] = { - {% for property in endpoint.query_parameters %} + {% for _, property in endpoint.query_parameters.items() %} {% if not property.json_is_dict %} {% if property.template %} "{{ property.name }}": {{ "json_" + property.python_name }}, @@ -45,7 +45,7 @@ params: Dict[str, Any] = { {% endif %} {% endfor %} } - {% for property in endpoint.query_parameters %} + {% for _, property in endpoint.query_parameters.items() %} {% if property.json_is_dict %} {% set property_name = "json_" + property.python_name %} {% if property.required and not property.nullable %} @@ -92,7 +92,7 @@ client: AuthenticatedClient, client: Client, {% endif %} {# path parameters #} -{% for parameter in endpoint.path_parameters %} +{% for _, parameter in endpoint.path_parameters.items() %} {{ parameter.to_string() }}, {% endfor %} {# Form data if any #} @@ -108,14 +108,14 @@ multipart_data: {{ endpoint.multipart_body.get_type_string() }}, json_body: {{ endpoint.json_body.get_type_string() }}, {% endif %} {# query parameters #} -{% for parameter in endpoint.query_parameters %} +{% for _, parameter in endpoint.query_parameters.items() %} {{ parameter.to_string() }}, {% endfor %} -{% for parameter in endpoint.header_parameters %} +{% for _, parameter in endpoint.header_parameters.items() %} {{ parameter.to_string() }}, {% endfor %} {# cookie parameters #} -{% for parameter in endpoint.cookie_parameters %} +{% for _, parameter in endpoint.cookie_parameters.items() %} {{ parameter.to_string() }}, {% endfor %} {% endmacro %} @@ -123,7 +123,7 @@ json_body: {{ endpoint.json_body.get_type_string() }}, {# Just lists all kwargs to endpoints as name=name for passing to other functions #} {% macro kwargs(endpoint) %} client=client, -{% for parameter in endpoint.path_parameters %} +{% for _, parameter in endpoint.path_parameters.items() %} {{ parameter.python_name }}={{ parameter.python_name }}, {% endfor %} {% if endpoint.form_body_class %} @@ -135,13 +135,13 @@ multipart_data=multipart_data, {% if endpoint.json_body %} json_body=json_body, {% endif %} -{% for parameter in endpoint.query_parameters %} +{% for _, parameter in endpoint.query_parameters.items() %} {{ parameter.python_name }}={{ parameter.python_name }}, {% endfor %} -{% for parameter in endpoint.header_parameters %} +{% for _, parameter in endpoint.header_parameters.items() %} {{ parameter.python_name }}={{ parameter.python_name }}, {% endfor %} -{% for parameter in endpoint.cookie_parameters %} +{% for _, parameter in endpoint.cookie_parameters.items() %} {{ parameter.python_name }}={{ parameter.python_name }}, {% endfor %} {% endmacro %} diff --git a/openapi_python_client/templates/endpoint_module.py.jinja b/openapi_python_client/templates/endpoint_module.py.jinja index 0624394f0..ec4d123fc 100644 --- a/openapi_python_client/templates/endpoint_module.py.jinja +++ b/openapi_python_client/templates/endpoint_module.py.jinja @@ -19,7 +19,7 @@ def _get_kwargs( ) -> Dict[str, Any]: url = "{}{{ endpoint.path }}".format( client.base_url - {%- for parameter in endpoint.path_parameters -%} + {%- for _, parameter in endpoint.path_parameters.items() -%} ,{{parameter.name}}={{parameter.python_name}} {%- endfor -%} ) From 1776c891eab6298c8a8c1ff3d3e86608bb7c7d97 Mon Sep 17 00:00:00 2001 From: mtovts Date: Thu, 22 Jul 2021 13:14:02 +0300 Subject: [PATCH 03/57] Update template to correct work with `json_body` --- openapi_python_client/templates/endpoint_module.py.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi_python_client/templates/endpoint_module.py.jinja b/openapi_python_client/templates/endpoint_module.py.jinja index ec4d123fc..221f117ad 100644 --- a/openapi_python_client/templates/endpoint_module.py.jinja +++ b/openapi_python_client/templates/endpoint_module.py.jinja @@ -47,7 +47,7 @@ def _get_kwargs( {% elif endpoint.multipart_body %} "files": {{ "multipart_" + endpoint.multipart_body.python_name }}, {% elif endpoint.json_body %} - "json": {{ "json_" + endpoint.json_body.python_name }}, + "json": {{ endpoint.json_body.python_name }}, {% endif %} {% if endpoint.query_parameters %} "params": params, From abe5144c04d3c130cc3f661134e372b6a1eb1fc4 Mon Sep 17 00:00:00 2001 From: mtovts Date: Thu, 22 Jul 2021 14:52:23 +0300 Subject: [PATCH 04/57] Update template\endpoint_macros.jinja` to correct work with headers --- openapi_python_client/templates/endpoint_macros.py.jinja | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openapi_python_client/templates/endpoint_macros.py.jinja b/openapi_python_client/templates/endpoint_macros.py.jinja index a7591bea6..c16082bae 100644 --- a/openapi_python_client/templates/endpoint_macros.py.jinja +++ b/openapi_python_client/templates/endpoint_macros.py.jinja @@ -2,10 +2,10 @@ {% if endpoint.header_parameters %} {% for _, parameter in endpoint.header_parameters.items() %} {% if parameter.required %} -headers["{{ parameter.python_name | kebabcase}}"] = {{ parameter.python_name }} +headers["{{ parameter.name | kebabcase}}"] = {{ parameter.python_name }} {% else %} if {{ parameter.python_name }} is not UNSET: - headers["{{ parameter.python_name | kebabcase}}"] = {{ parameter.python_name }} + headers["{{ parameter.name | kebabcase}}"] = {{ parameter.python_name }} {% endif %} {% endfor %} {% endif %} From 7468e4c078d03fbb123e63afde79f16599c6ba8b Mon Sep 17 00:00:00 2001 From: mtovts Date: Fri, 23 Jul 2021 11:03:28 +0300 Subject: [PATCH 05/57] Refactor: Parameters update --- openapi_python_client/parser/openapi.py | 27 +++++++++---------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index df990417a..f22dcd968 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -51,11 +51,6 @@ def from_data( endpoint, schemas = Endpoint._add_parameters( endpoint=endpoint, data=path_data, schemas=schemas, config=config ) - # Add `Operation` parameters - if not isinstance(endpoint, ParseError): - endpoint, schemas = Endpoint._add_parameters( - endpoint=endpoint, data=operation, schemas=schemas, config=config - ) if isinstance(endpoint, ParseError): endpoint.header = ( @@ -267,18 +262,16 @@ def _add_parameters( endpoint.relative_imports.update(prop.get_imports(prefix="...")) prop.set_python_name(new_name=f"{param.name}_{param.param_in}", config=config) - new_prop = {prop.python_name: prop} - - if param.param_in == oai.ParameterLocation.QUERY: - endpoint.query_parameters.update(new_prop) - elif param.param_in == oai.ParameterLocation.PATH: - endpoint.path_parameters.update(new_prop) - elif param.param_in == oai.ParameterLocation.HEADER: - endpoint.header_parameters.update(new_prop) - elif param.param_in == oai.ParameterLocation.COOKIE: - endpoint.cookie_parameters.update(new_prop) - else: - return ParseError(data=param, detail="Parameter must be declared in path or query"), schemas + + parameters_by_location = { + oai.ParameterLocation.QUERY: endpoint.query_parameters, + oai.ParameterLocation.PATH: endpoint.path_parameters, + oai.ParameterLocation.HEADER: endpoint.header_parameters, + oai.ParameterLocation.COOKIE: endpoint.cookie_parameters, + } + param_location: oai.ParameterLocation = param.param_in + param_python_name: PythonIdentifier = prop.python_name + parameters_by_location[param_location].setdefault(param_python_name, prop) return endpoint, schemas From b1e87e53d413a4ca20366a878dee2634bf131b96 Mon Sep 17 00:00:00 2001 From: mtovts Date: Fri, 23 Jul 2021 11:04:34 +0300 Subject: [PATCH 06/57] Add duplicates parameters check --- openapi_python_client/parser/openapi.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index f22dcd968..8885102be 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -245,6 +245,9 @@ def _add_parameters( endpoint = deepcopy(endpoint) if data.parameters is None: return endpoint, schemas + + used_identifiers: Set[PythonIdentifier] = set() + for param in data.parameters: if isinstance(param, oai.Reference) or param.param_schema is None: continue @@ -271,7 +274,16 @@ def _add_parameters( } param_location: oai.ParameterLocation = param.param_in param_python_name: PythonIdentifier = prop.python_name + + if param_python_name in used_identifiers: + return ( + ParseError(data=data, detail="Parameters MUST NOT duplicates. " + f"A unique parameter is defined by a combination of a name and location. " + f"Duplicated parameters detected: `{prop.name}` in `{param_location}`."), + schemas + ) parameters_by_location[param_location].setdefault(param_python_name, prop) + used_identifiers.add(param_python_name) return endpoint, schemas From 2139e38405fe70f4e6e9cded15d2f03dc6c11cc4 Mon Sep 17 00:00:00 2001 From: mtovts Date: Sun, 25 Jul 2021 15:40:59 +0300 Subject: [PATCH 07/57] code style --- openapi_python_client/parser/openapi.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index 8885102be..008624313 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -277,10 +277,13 @@ def _add_parameters( if param_python_name in used_identifiers: return ( - ParseError(data=data, detail="Parameters MUST NOT duplicates. " - f"A unique parameter is defined by a combination of a name and location. " - f"Duplicated parameters detected: `{prop.name}` in `{param_location}`."), - schemas + ParseError( + data=data, + detail="Parameters MUST NOT duplicates. " + f"A unique parameter is defined by a combination of a name and location. " + f"Duplicated parameters detected: `{prop.name}` in `{param_location}`.", + ), + schemas, ) parameters_by_location[param_location].setdefault(param_python_name, prop) used_identifiers.add(param_python_name) From 60cb64f35113c745460a2a77d69aefd880e4a71a Mon Sep 17 00:00:00 2001 From: mtovts Date: Sun, 25 Jul 2021 19:58:00 +0300 Subject: [PATCH 08/57] Refactor: use `str` instead `PythonIdentifier` in parameters dictionaries --- openapi_python_client/parser/openapi.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index 008624313..2590cd48e 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -90,10 +90,10 @@ class Endpoint: tag: str summary: Optional[str] = "" relative_imports: Set[str] = field(default_factory=set) - query_parameters: Dict[PythonIdentifier, Property] = field(default_factory=dict) - path_parameters: Dict[PythonIdentifier, Property] = field(default_factory=dict) - header_parameters: Dict[PythonIdentifier, Property] = field(default_factory=dict) - cookie_parameters: Dict[PythonIdentifier, Property] = field(default_factory=dict) + query_parameters: Dict[str, Property] = field(default_factory=dict) + path_parameters: Dict[str, Property] = field(default_factory=dict) + header_parameters: Dict[str, Property] = field(default_factory=dict) + cookie_parameters: Dict[str, Property] = field(default_factory=dict) responses: List[Response] = field(default_factory=list) form_body_class: Optional[Class] = None json_body: Optional[Property] = None @@ -272,21 +272,19 @@ def _add_parameters( oai.ParameterLocation.HEADER: endpoint.header_parameters, oai.ParameterLocation.COOKIE: endpoint.cookie_parameters, } - param_location: oai.ParameterLocation = param.param_in - param_python_name: PythonIdentifier = prop.python_name - if param_python_name in used_identifiers: + if prop.python_name in used_identifiers: return ( ParseError( data=data, detail="Parameters MUST NOT duplicates. " f"A unique parameter is defined by a combination of a name and location. " - f"Duplicated parameters detected: `{prop.name}` in `{param_location}`.", + f"Duplicated parameters named `{prop.name}` detected in `{param.param_in}`.", ), schemas, ) - parameters_by_location[param_location].setdefault(param_python_name, prop) - used_identifiers.add(param_python_name) + parameters_by_location[param.param_in].setdefault(prop.name, prop) + used_identifiers.add(prop.python_name) return endpoint, schemas From cc552209287bbc916de4f87626afb93f0c7ce1fc Mon Sep 17 00:00:00 2001 From: mtovts Date: Sun, 25 Jul 2021 20:00:14 +0300 Subject: [PATCH 09/57] Fix: update unit-tests related with `Endpoint._add_parameters()` --- tests/test_parser/test_openapi.py | 44 +++++++++++++++---------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/test_parser/test_openapi.py b/tests/test_parser/test_openapi.py index ec2ee1fde..f96dcb049 100644 --- a/tests/test_parser/test_openapi.py +++ b/tests/test_parser/test_openapi.py @@ -1,5 +1,6 @@ from unittest.mock import MagicMock +import pydantic import pytest import openapi_python_client.schema as oai @@ -527,22 +528,15 @@ def test__add_parameters_parse_error(self, mocker): property_schemas, ) - def test__add_parameters_fail_loudly_when_location_not_supported(self, mocker): - from openapi_python_client.parser.openapi import Endpoint, Schemas - - endpoint = self.make_endpoint() + def test_validation_error_when_location_not_supported(self, mocker): parsed_schemas = mocker.MagicMock() mocker.patch(f"{MODULE_NAME}.property_from_data", return_value=(mocker.MagicMock(), parsed_schemas)) - param = oai.Parameter.construct( - name="test", required=True, param_schema=mocker.MagicMock(), param_in="error_location" - ) - schemas = Schemas() - config = MagicMock() - - result = Endpoint._add_parameters( - endpoint=endpoint, data=oai.Operation.construct(parameters=[param]), schemas=schemas, config=config - ) - assert result == (ParseError(data=param, detail="Parameter must be declared in path or query"), parsed_schemas) + try: + oai.Parameter.construct( + name="test", required=True, param_schema=mocker.MagicMock(), param_in="error_location" + ) + except Exception as e: + assert e is pydantic.ValidationError def test__add_parameters_happy(self, mocker): from openapi_python_client.parser.openapi import Endpoint @@ -622,11 +616,14 @@ def test__add_parameters_happy(self, mocker): query_prop.get_imports.assert_called_once_with(prefix="...") header_prop.get_imports.assert_called_once_with(prefix="...") assert endpoint.relative_imports == {"import_3", path_prop_import, query_prop_import, header_prop_import} - assert endpoint.path_parameters == [path_prop] - assert endpoint.query_parameters == [query_prop] - assert endpoint.header_parameters == [header_prop] + assert endpoint.path_parameters == {path_prop.name: path_prop} + assert endpoint.query_parameters == {query_prop.name: query_prop} + assert endpoint.header_parameters == {header_prop.name: header_prop} assert schemas == schemas_3 + def test__add_parameters_override_properties(self, mocker): + pass # TODO + def test__add_parameters_duplicate_properties(self, mocker): from openapi_python_client.parser.openapi import Endpoint, Schemas @@ -640,7 +637,9 @@ def test__add_parameters_duplicate_properties(self, mocker): result = Endpoint._add_parameters(endpoint=endpoint, data=data, schemas=schemas, config=config) assert result == ( - ParseError(data=data, detail="Could not reconcile duplicate parameters named test_path"), + ParseError(data=data, detail="Parameters MUST NOT duplicates. " + "A unique parameter is defined by a combination of a name and location. " + "Duplicated parameters named `test` detected in `path`."), schemas, ) @@ -664,10 +663,8 @@ def test__add_parameters_duplicate_properties_different_location(self): config=config, )[0] assert isinstance(result, Endpoint) - assert result.path_parameters[0].python_name == "test_path" - assert result.path_parameters[0].name == "test" - assert result.query_parameters[0].python_name == "test_query" - assert result.query_parameters[0].name == "test" + assert result.path_parameters["test"].name == "test" + assert result.query_parameters["test"].name == "test" def test_from_data_bad_params(self, mocker): from openapi_python_client.parser.openapi import Endpoint @@ -954,6 +951,9 @@ def test_from_data(self, mocker): schemas_3, ) + def test_from_data_overriding_common_parameters(self, mocker): + pass # TODO + def test_from_data_errors(self, mocker): from openapi_python_client.parser.openapi import Endpoint, EndpointCollection, ParseError From 2247a9a7f40d05fbe52f84c5e77488388f6ce023 Mon Sep 17 00:00:00 2001 From: mtovts Date: Sun, 25 Jul 2021 21:46:34 +0300 Subject: [PATCH 10/57] Add: `common_parameters_overriding` endpoint to e2e tests --- end_to_end_tests/openapi.json | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/end_to_end_tests/openapi.json b/end_to_end_tests/openapi.json index 5e8c2cbe8..78d67e05c 100644 --- a/end_to_end_tests/openapi.json +++ b/end_to_end_tests/openapi.json @@ -850,6 +850,57 @@ } } }, + "/common_parameters_overriding/{param}": { + "description": "Test that if you have an overriding property from `PathItem` in `Operation`, it produces valid code", + "get": { + "tags": [ + "parameters" + ], + "parameters": [ + { + "name": "param", + "in": "query", + "required": true, + "schema": { + "type": "string", + "default": "overriden_in_GET" + } + } + ], + "responses": { + "200": { + "description": "" + } + } + }, + "delete": { + "tags": [ + "parameters" + ], + "responses": { + "200": { + "description": "" + } + } + }, + "parameters": [ + { + "name": "param", + "in": "query", + "schema": { + "type": "string" + } + }, + { + "name": "param", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ] + }, "/same-name-multiple-locations/{param}": { "description": "Test that if you have a property of the same name in multiple locations, it produces valid code", "get": { From 86a9f53eb9d428acbe66faf9a1a6efdf6457436e Mon Sep 17 00:00:00 2001 From: mtovts Date: Sun, 25 Jul 2021 21:48:22 +0300 Subject: [PATCH 11/57] Add parameters locations: `header`, `cookie` in `same-name-multiple-locations` e2e OpenAPI --- end_to_end_tests/openapi.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/end_to_end_tests/openapi.json b/end_to_end_tests/openapi.json index 78d67e05c..7faa7b9d5 100644 --- a/end_to_end_tests/openapi.json +++ b/end_to_end_tests/openapi.json @@ -915,9 +915,24 @@ "type": "string" } }, + { + "name": "param", + "in": "header", + "schema": { + "type": "string" + } + }, + { + "name": "param", + "in": "cookie", + "schema": { + "type": "string" + } + }, { "name": "param", "in": "path", + "required": true, "schema": { "type": "string" } From 7e340881c134e81906b63b1282267df53a64b754 Mon Sep 17 00:00:00 2001 From: mtovts Date: Sun, 25 Jul 2021 21:50:09 +0300 Subject: [PATCH 12/57] Add generated `common_parameters_overriding` edpoints to e2e tests --- ...lete_common_parameters_overriding_param.py | 77 +++++++++++++++++++ .../get_common_parameters_overriding_param.py | 77 +++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py create mode 100644 end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py new file mode 100644 index 000000000..91ea6fd5f --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py @@ -0,0 +1,77 @@ +from typing import Any, Dict, Union + +import httpx + +from ...client import Client +from ...types import UNSET, Response, Unset + + +def _get_kwargs( + *, + client: Client, + param_path: str, + param_query: Union[Unset, str] = UNSET, +) -> Dict[str, Any]: + url = "{}/common_parameters_overriding/{param}".format(client.base_url, param=param_path) + + headers: Dict[str, Any] = client.get_headers() + cookies: Dict[str, Any] = client.get_cookies() + + params: Dict[str, Any] = { + "param": param_query, + } + params = {k: v for k, v in params.items() if v is not UNSET and v is not None} + + return { + "url": url, + "headers": headers, + "cookies": cookies, + "timeout": client.get_timeout(), + "params": params, + } + + +def _build_response(*, response: httpx.Response) -> Response[Any]: + return Response( + status_code=response.status_code, + content=response.content, + headers=response.headers, + parsed=None, + ) + + +def sync_detailed( + *, + client: Client, + param_path: str, + param_query: Union[Unset, str] = UNSET, +) -> Response[Any]: + kwargs = _get_kwargs( + client=client, + param_path=param_path, + param_query=param_query, + ) + + response = httpx.delete( + **kwargs, + ) + + return _build_response(response=response) + + +async def asyncio_detailed( + *, + client: Client, + param_path: str, + param_query: Union[Unset, str] = UNSET, +) -> Response[Any]: + kwargs = _get_kwargs( + client=client, + param_path=param_path, + param_query=param_query, + ) + + async with httpx.AsyncClient() as _client: + response = await _client.delete(**kwargs) + + return _build_response(response=response) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py new file mode 100644 index 000000000..2fb194af7 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py @@ -0,0 +1,77 @@ +from typing import Any, Dict + +import httpx + +from ...client import Client +from ...types import UNSET, Response + + +def _get_kwargs( + *, + client: Client, + param_path: str, + param_query: str = "overriden_in_GET", +) -> Dict[str, Any]: + url = "{}/common_parameters_overriding/{param}".format(client.base_url, param=param_path) + + headers: Dict[str, Any] = client.get_headers() + cookies: Dict[str, Any] = client.get_cookies() + + params: Dict[str, Any] = { + "param": param_query, + } + params = {k: v for k, v in params.items() if v is not UNSET and v is not None} + + return { + "url": url, + "headers": headers, + "cookies": cookies, + "timeout": client.get_timeout(), + "params": params, + } + + +def _build_response(*, response: httpx.Response) -> Response[Any]: + return Response( + status_code=response.status_code, + content=response.content, + headers=response.headers, + parsed=None, + ) + + +def sync_detailed( + *, + client: Client, + param_path: str, + param_query: str = "overriden_in_GET", +) -> Response[Any]: + kwargs = _get_kwargs( + client=client, + param_path=param_path, + param_query=param_query, + ) + + response = httpx.get( + **kwargs, + ) + + return _build_response(response=response) + + +async def asyncio_detailed( + *, + client: Client, + param_path: str, + param_query: str = "overriden_in_GET", +) -> Response[Any]: + kwargs = _get_kwargs( + client=client, + param_path=param_path, + param_query=param_query, + ) + + async with httpx.AsyncClient() as _client: + response = await _client.get(**kwargs) + + return _build_response(response=response) From 32e94a18ae380f450679a1a6c3ae7ee89da984b8 Mon Sep 17 00:00:00 2001 From: mtovts Date: Sun, 25 Jul 2021 21:51:38 +0300 Subject: [PATCH 13/57] Update `same_name_multiple_locations_param` generated endpoint in e2e tests --- .../get_same_name_multiple_locations_param.py | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py index 2013768aa..3f01bc592 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py @@ -9,14 +9,22 @@ def _get_kwargs( *, client: Client, - param_path: Union[Unset, str] = UNSET, + param_path: str, param_query: Union[Unset, str] = UNSET, + param_header: Union[Unset, str] = UNSET, + param_cookie: Union[Unset, str] = UNSET, ) -> Dict[str, Any]: url = "{}/same-name-multiple-locations/{param}".format(client.base_url, param=param_path) headers: Dict[str, Any] = client.get_headers() cookies: Dict[str, Any] = client.get_cookies() + if param_header is not UNSET: + headers["param"] = param_header + + if param_cookie is not UNSET: + cookies["param"] = param_cookie + params: Dict[str, Any] = { "param": param_query, } @@ -43,13 +51,17 @@ def _build_response(*, response: httpx.Response) -> Response[Any]: def sync_detailed( *, client: Client, - param_path: Union[Unset, str] = UNSET, + param_path: str, param_query: Union[Unset, str] = UNSET, + param_header: Union[Unset, str] = UNSET, + param_cookie: Union[Unset, str] = UNSET, ) -> Response[Any]: kwargs = _get_kwargs( client=client, param_path=param_path, param_query=param_query, + param_header=param_header, + param_cookie=param_cookie, ) response = httpx.get( @@ -62,13 +74,17 @@ def sync_detailed( async def asyncio_detailed( *, client: Client, - param_path: Union[Unset, str] = UNSET, + param_path: str, param_query: Union[Unset, str] = UNSET, + param_header: Union[Unset, str] = UNSET, + param_cookie: Union[Unset, str] = UNSET, ) -> Response[Any]: kwargs = _get_kwargs( client=client, param_path=param_path, param_query=param_query, + param_header=param_header, + param_cookie=param_cookie, ) async with httpx.AsyncClient() as _client: From a4f645874478c5f0eafe90cd7cca691397afc294 Mon Sep 17 00:00:00 2001 From: mtovts Date: Sun, 25 Jul 2021 21:53:51 +0300 Subject: [PATCH 14/57] Update generated endpoints in `common_parameters`: add location postfix --- .../api/default/get_common_parameters.py | 12 ++++++------ .../api/default/post_common_parameters.py | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py b/end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py index 96487587d..21af63e0b 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py @@ -9,7 +9,7 @@ def _get_kwargs( *, client: Client, - common: Union[Unset, str] = UNSET, + common_query: Union[Unset, str] = UNSET, ) -> Dict[str, Any]: url = "{}/common_parameters".format(client.base_url) @@ -17,7 +17,7 @@ def _get_kwargs( cookies: Dict[str, Any] = client.get_cookies() params: Dict[str, Any] = { - "common": common, + "common": common_query, } params = {k: v for k, v in params.items() if v is not UNSET and v is not None} @@ -42,11 +42,11 @@ def _build_response(*, response: httpx.Response) -> Response[Any]: def sync_detailed( *, client: Client, - common: Union[Unset, str] = UNSET, + common_query: Union[Unset, str] = UNSET, ) -> Response[Any]: kwargs = _get_kwargs( client=client, - common=common, + common_query=common_query, ) response = httpx.get( @@ -59,11 +59,11 @@ def sync_detailed( async def asyncio_detailed( *, client: Client, - common: Union[Unset, str] = UNSET, + common_query: Union[Unset, str] = UNSET, ) -> Response[Any]: kwargs = _get_kwargs( client=client, - common=common, + common_query=common_query, ) async with httpx.AsyncClient() as _client: diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py b/end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py index 3283f4830..7987dd9ea 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py @@ -9,7 +9,7 @@ def _get_kwargs( *, client: Client, - common: Union[Unset, str] = UNSET, + common_query: Union[Unset, str] = UNSET, ) -> Dict[str, Any]: url = "{}/common_parameters".format(client.base_url) @@ -17,7 +17,7 @@ def _get_kwargs( cookies: Dict[str, Any] = client.get_cookies() params: Dict[str, Any] = { - "common": common, + "common": common_query, } params = {k: v for k, v in params.items() if v is not UNSET and v is not None} @@ -42,11 +42,11 @@ def _build_response(*, response: httpx.Response) -> Response[Any]: def sync_detailed( *, client: Client, - common: Union[Unset, str] = UNSET, + common_query: Union[Unset, str] = UNSET, ) -> Response[Any]: kwargs = _get_kwargs( client=client, - common=common, + common_query=common_query, ) response = httpx.post( @@ -59,11 +59,11 @@ def sync_detailed( async def asyncio_detailed( *, client: Client, - common: Union[Unset, str] = UNSET, + common_query: Union[Unset, str] = UNSET, ) -> Response[Any]: kwargs = _get_kwargs( client=client, - common=common, + common_query=common_query, ) async with httpx.AsyncClient() as _client: From 38f341b6d85ec07f53d00d4cc15feb2f4eb6da92 Mon Sep 17 00:00:00 2001 From: mtovts Date: Mon, 26 Jul 2021 11:25:08 +0300 Subject: [PATCH 15/57] Update `end_to_end_tests\golden-record\*` --- .../my_test_api_client/api/__init__.py | 8 +- .../api/default/__init__.py | 2 +- .../api/parameters/__init__.py | 14 +- .../my_test_api_client/api/tag1/__init__.py | 2 +- .../my_test_api_client/api/tests/__init__.py | 2 +- .../api/tests/defaults_tests_defaults_post.py | 430 +++++++++--------- .../api/tests/get_user_list.py | 52 +-- .../api/tests/int_enum_tests_int_enum_post.py | 22 +- .../tests/json_body_tests_json_body_post.py | 4 +- ...tional_value_tests_optional_query_param.py | 26 +- .../api/tests/test_inline_objects.py | 4 +- ..._with_cookie_auth_token_with_cookie_get.py | 12 +- .../tests/upload_file_tests_upload_post.py | 22 +- ...upload_multiple_files_tests_upload_post.py | 22 +- 14 files changed, 318 insertions(+), 304 deletions(-) diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/__init__.py b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/__init__.py index e5f9a66ed..f516aefcf 100644 --- a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/__init__.py +++ b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/__init__.py @@ -2,10 +2,10 @@ from typing import Type -from my_test_api_client.api.default import DefaultEndpoints -from my_test_api_client.api.parameters import ParametersEndpoints -from my_test_api_client.api.tag1 import Tag1Endpoints -from my_test_api_client.api.tests import TestsEndpoints +from .default import DefaultEndpoints +from .parameters import ParametersEndpoints +from .tag1 import Tag1Endpoints +from .tests import TestsEndpoints class MyTestApiClientApi: diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/default/__init__.py b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/default/__init__.py index 4d0eb4fb5..a4580103f 100644 --- a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/default/__init__.py +++ b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/default/__init__.py @@ -2,7 +2,7 @@ import types -from my_test_api_client.api.default import get_common_parameters, post_common_parameters +from . import get_common_parameters, post_common_parameters class DefaultEndpoints: diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/parameters/__init__.py b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/parameters/__init__.py index b92c6d96b..0d34e1f2d 100644 --- a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/parameters/__init__.py +++ b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/parameters/__init__.py @@ -2,10 +2,22 @@ import types -from my_test_api_client.api.parameters import get_same_name_multiple_locations_param +from . import ( + delete_common_parameters_overriding_param, + get_common_parameters_overriding_param, + get_same_name_multiple_locations_param, +) class ParametersEndpoints: + @classmethod + def get_common_parameters_overriding_param(cls) -> types.ModuleType: + return get_common_parameters_overriding_param + + @classmethod + def delete_common_parameters_overriding_param(cls) -> types.ModuleType: + return delete_common_parameters_overriding_param + @classmethod def get_same_name_multiple_locations_param(cls) -> types.ModuleType: return get_same_name_multiple_locations_param diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tag1/__init__.py b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tag1/__init__.py index b91db35b0..556ca84e8 100644 --- a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tag1/__init__.py +++ b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tag1/__init__.py @@ -2,7 +2,7 @@ import types -from my_test_api_client.api.tag1 import get_tag_with_number +from . import get_tag_with_number class Tag1Endpoints: diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tests/__init__.py b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tests/__init__.py index 28a4f10c1..8fc547a66 100644 --- a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tests/__init__.py +++ b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tests/__init__.py @@ -2,7 +2,7 @@ import types -from my_test_api_client.api.tests import ( +from . import ( defaults_tests_defaults_post, get_basic_list_of_booleans, get_basic_list_of_floats, diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py index f22ec0153..cdf259e7f 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py @@ -14,112 +14,114 @@ def _get_kwargs( *, client: Client, - string_prop: Union[Unset, str] = "the default string", - not_required_not_nullable_datetime_prop: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), - not_required_nullable_datetime_prop: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), - required_not_nullable_datetime_prop: datetime.datetime = isoparse("1010-10-10T00:00:00"), - required_nullable_datetime_prop: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), - date_prop: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), - float_prop: Union[Unset, float] = 3.14, - int_prop: Union[Unset, int] = 7, - boolean_prop: Union[Unset, bool] = False, - list_prop: Union[Unset, List[AnEnum]] = UNSET, - union_prop: Union[Unset, float, str] = "not a float", - union_prop_with_ref: Union[AnEnum, Unset, float] = 0.6, - enum_prop: Union[Unset, AnEnum] = UNSET, - model_prop: Union[Unset, ModelWithUnionProperty] = UNSET, - required_model_prop: ModelWithUnionProperty, - nullable_model_prop: Union[Unset, None, ModelWithUnionProperty] = UNSET, - nullable_required_model_prop: Optional[ModelWithUnionProperty], + string_prop_query: Union[Unset, str] = "the default string", + not_required_not_nullable_datetime_prop_query: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), + not_required_nullable_datetime_prop_query: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), + required_not_nullable_datetime_prop_query: datetime.datetime = isoparse("1010-10-10T00:00:00"), + required_nullable_datetime_prop_query: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), + date_prop_query: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), + float_prop_query: Union[Unset, float] = 3.14, + int_prop_query: Union[Unset, int] = 7, + boolean_prop_query: Union[Unset, bool] = False, + list_prop_query: Union[Unset, List[AnEnum]] = UNSET, + union_prop_query: Union[Unset, float, str] = "not a float", + union_prop_with_ref_query: Union[AnEnum, Unset, float] = 0.6, + enum_prop_query: Union[Unset, AnEnum] = UNSET, + model_prop_query: Union[Unset, ModelWithUnionProperty] = UNSET, + required_model_prop_query: ModelWithUnionProperty, + nullable_model_prop_query: Union[Unset, None, ModelWithUnionProperty] = UNSET, + nullable_required_model_prop_query: Optional[ModelWithUnionProperty], ) -> Dict[str, Any]: url = "{}/tests/defaults".format(client.base_url) headers: Dict[str, Any] = client.get_headers() cookies: Dict[str, Any] = client.get_cookies() - json_not_required_not_nullable_datetime_prop: Union[Unset, str] = UNSET - if not isinstance(not_required_not_nullable_datetime_prop, Unset): - json_not_required_not_nullable_datetime_prop = not_required_not_nullable_datetime_prop.isoformat() + json_not_required_not_nullable_datetime_prop_query: Union[Unset, str] = UNSET + if not isinstance(not_required_not_nullable_datetime_prop_query, Unset): + json_not_required_not_nullable_datetime_prop_query = not_required_not_nullable_datetime_prop_query.isoformat() - json_not_required_nullable_datetime_prop: Union[Unset, None, str] = UNSET - if not isinstance(not_required_nullable_datetime_prop, Unset): - json_not_required_nullable_datetime_prop = ( - not_required_nullable_datetime_prop.isoformat() if not_required_nullable_datetime_prop else None + json_not_required_nullable_datetime_prop_query: Union[Unset, None, str] = UNSET + if not isinstance(not_required_nullable_datetime_prop_query, Unset): + json_not_required_nullable_datetime_prop_query = ( + not_required_nullable_datetime_prop_query.isoformat() if not_required_nullable_datetime_prop_query else None ) - json_required_not_nullable_datetime_prop = required_not_nullable_datetime_prop.isoformat() + json_required_not_nullable_datetime_prop_query = required_not_nullable_datetime_prop_query.isoformat() - json_required_nullable_datetime_prop = ( - required_nullable_datetime_prop.isoformat() if required_nullable_datetime_prop else None + json_required_nullable_datetime_prop_query = ( + required_nullable_datetime_prop_query.isoformat() if required_nullable_datetime_prop_query else None ) - json_date_prop: Union[Unset, str] = UNSET - if not isinstance(date_prop, Unset): - json_date_prop = date_prop.isoformat() + json_date_prop_query: Union[Unset, str] = UNSET + if not isinstance(date_prop_query, Unset): + json_date_prop_query = date_prop_query.isoformat() - json_list_prop: Union[Unset, List[str]] = UNSET - if not isinstance(list_prop, Unset): - json_list_prop = [] - for list_prop_item_data in list_prop: + json_list_prop_query: Union[Unset, List[str]] = UNSET + if not isinstance(list_prop_query, Unset): + json_list_prop_query = [] + for list_prop_item_data in list_prop_query: list_prop_item = list_prop_item_data.value - json_list_prop.append(list_prop_item) + json_list_prop_query.append(list_prop_item) - json_union_prop: Union[Unset, float, str] - if isinstance(union_prop, Unset): - json_union_prop = UNSET + json_union_prop_query: Union[Unset, float, str] + if isinstance(union_prop_query, Unset): + json_union_prop_query = UNSET else: - json_union_prop = union_prop + json_union_prop_query = union_prop_query - json_union_prop_with_ref: Union[Unset, float, str] - if isinstance(union_prop_with_ref, Unset): - json_union_prop_with_ref = UNSET - elif isinstance(union_prop_with_ref, AnEnum): - json_union_prop_with_ref = UNSET - if not isinstance(union_prop_with_ref, Unset): - json_union_prop_with_ref = union_prop_with_ref.value + json_union_prop_with_ref_query: Union[Unset, float, str] + if isinstance(union_prop_with_ref_query, Unset): + json_union_prop_with_ref_query = UNSET + elif isinstance(union_prop_with_ref_query, AnEnum): + json_union_prop_with_ref_query = UNSET + if not isinstance(union_prop_with_ref_query, Unset): + json_union_prop_with_ref_query = union_prop_with_ref_query.value else: - json_union_prop_with_ref = union_prop_with_ref + json_union_prop_with_ref_query = union_prop_with_ref_query - json_enum_prop: Union[Unset, str] = UNSET - if not isinstance(enum_prop, Unset): - json_enum_prop = enum_prop.value + json_enum_prop_query: Union[Unset, str] = UNSET + if not isinstance(enum_prop_query, Unset): + json_enum_prop_query = enum_prop_query.value - json_model_prop: Union[Unset, Dict[str, Any]] = UNSET - if not isinstance(model_prop, Unset): - json_model_prop = model_prop.to_dict() + json_model_prop_query: Union[Unset, Dict[str, Any]] = UNSET + if not isinstance(model_prop_query, Unset): + json_model_prop_query = model_prop_query.to_dict() - json_required_model_prop = required_model_prop.to_dict() + json_required_model_prop_query = required_model_prop_query.to_dict() - json_nullable_model_prop: Union[Unset, None, Dict[str, Any]] = UNSET - if not isinstance(nullable_model_prop, Unset): - json_nullable_model_prop = nullable_model_prop.to_dict() if nullable_model_prop else None + json_nullable_model_prop_query: Union[Unset, None, Dict[str, Any]] = UNSET + if not isinstance(nullable_model_prop_query, Unset): + json_nullable_model_prop_query = nullable_model_prop_query.to_dict() if nullable_model_prop_query else None - json_nullable_required_model_prop = nullable_required_model_prop.to_dict() if nullable_required_model_prop else None + json_nullable_required_model_prop_query = ( + nullable_required_model_prop_query.to_dict() if nullable_required_model_prop_query else None + ) params: Dict[str, Any] = { - "string_prop": string_prop, - "not_required_not_nullable_datetime_prop": json_not_required_not_nullable_datetime_prop, - "not_required_nullable_datetime_prop": json_not_required_nullable_datetime_prop, - "required_not_nullable_datetime_prop": json_required_not_nullable_datetime_prop, - "required_nullable_datetime_prop": json_required_nullable_datetime_prop, - "date_prop": json_date_prop, - "float_prop": float_prop, - "int_prop": int_prop, - "boolean_prop": boolean_prop, - "list_prop": json_list_prop, - "union_prop": json_union_prop, - "union_prop_with_ref": json_union_prop_with_ref, - "enum_prop": json_enum_prop, + "string_prop": string_prop_query, + "not_required_not_nullable_datetime_prop": json_not_required_not_nullable_datetime_prop_query, + "not_required_nullable_datetime_prop": json_not_required_nullable_datetime_prop_query, + "required_not_nullable_datetime_prop": json_required_not_nullable_datetime_prop_query, + "required_nullable_datetime_prop": json_required_nullable_datetime_prop_query, + "date_prop": json_date_prop_query, + "float_prop": float_prop_query, + "int_prop": int_prop_query, + "boolean_prop": boolean_prop_query, + "list_prop": json_list_prop_query, + "union_prop": json_union_prop_query, + "union_prop_with_ref": json_union_prop_with_ref_query, + "enum_prop": json_enum_prop_query, } - if not isinstance(json_model_prop, Unset): - params.update(json_model_prop) - params.update(json_required_model_prop) - if not isinstance(json_nullable_model_prop, Unset) and json_nullable_model_prop is not None: - params.update(json_nullable_model_prop) - if json_nullable_required_model_prop is not None: - params.update(json_nullable_required_model_prop) + if not isinstance(json_model_prop_query, Unset): + params.update(json_model_prop_query) + params.update(json_required_model_prop_query) + if not isinstance(json_nullable_model_prop_query, Unset) and json_nullable_model_prop_query is not None: + params.update(json_nullable_model_prop_query) + if json_nullable_required_model_prop_query is not None: + params.update(json_nullable_required_model_prop_query) params = {k: v for k, v in params.items() if v is not UNSET and v is not None} return { @@ -155,43 +157,43 @@ def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPVali def sync_detailed( *, client: Client, - string_prop: Union[Unset, str] = "the default string", - not_required_not_nullable_datetime_prop: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), - not_required_nullable_datetime_prop: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), - required_not_nullable_datetime_prop: datetime.datetime = isoparse("1010-10-10T00:00:00"), - required_nullable_datetime_prop: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), - date_prop: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), - float_prop: Union[Unset, float] = 3.14, - int_prop: Union[Unset, int] = 7, - boolean_prop: Union[Unset, bool] = False, - list_prop: Union[Unset, List[AnEnum]] = UNSET, - union_prop: Union[Unset, float, str] = "not a float", - union_prop_with_ref: Union[AnEnum, Unset, float] = 0.6, - enum_prop: Union[Unset, AnEnum] = UNSET, - model_prop: Union[Unset, ModelWithUnionProperty] = UNSET, - required_model_prop: ModelWithUnionProperty, - nullable_model_prop: Union[Unset, None, ModelWithUnionProperty] = UNSET, - nullable_required_model_prop: Optional[ModelWithUnionProperty], + string_prop_query: Union[Unset, str] = "the default string", + not_required_not_nullable_datetime_prop_query: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), + not_required_nullable_datetime_prop_query: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), + required_not_nullable_datetime_prop_query: datetime.datetime = isoparse("1010-10-10T00:00:00"), + required_nullable_datetime_prop_query: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), + date_prop_query: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), + float_prop_query: Union[Unset, float] = 3.14, + int_prop_query: Union[Unset, int] = 7, + boolean_prop_query: Union[Unset, bool] = False, + list_prop_query: Union[Unset, List[AnEnum]] = UNSET, + union_prop_query: Union[Unset, float, str] = "not a float", + union_prop_with_ref_query: Union[AnEnum, Unset, float] = 0.6, + enum_prop_query: Union[Unset, AnEnum] = UNSET, + model_prop_query: Union[Unset, ModelWithUnionProperty] = UNSET, + required_model_prop_query: ModelWithUnionProperty, + nullable_model_prop_query: Union[Unset, None, ModelWithUnionProperty] = UNSET, + nullable_required_model_prop_query: Optional[ModelWithUnionProperty], ) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, - string_prop=string_prop, - not_required_not_nullable_datetime_prop=not_required_not_nullable_datetime_prop, - not_required_nullable_datetime_prop=not_required_nullable_datetime_prop, - required_not_nullable_datetime_prop=required_not_nullable_datetime_prop, - required_nullable_datetime_prop=required_nullable_datetime_prop, - date_prop=date_prop, - float_prop=float_prop, - int_prop=int_prop, - boolean_prop=boolean_prop, - list_prop=list_prop, - union_prop=union_prop, - union_prop_with_ref=union_prop_with_ref, - enum_prop=enum_prop, - model_prop=model_prop, - required_model_prop=required_model_prop, - nullable_model_prop=nullable_model_prop, - nullable_required_model_prop=nullable_required_model_prop, + string_prop_query=string_prop_query, + not_required_not_nullable_datetime_prop_query=not_required_not_nullable_datetime_prop_query, + not_required_nullable_datetime_prop_query=not_required_nullable_datetime_prop_query, + required_not_nullable_datetime_prop_query=required_not_nullable_datetime_prop_query, + required_nullable_datetime_prop_query=required_nullable_datetime_prop_query, + date_prop_query=date_prop_query, + float_prop_query=float_prop_query, + int_prop_query=int_prop_query, + boolean_prop_query=boolean_prop_query, + list_prop_query=list_prop_query, + union_prop_query=union_prop_query, + union_prop_with_ref_query=union_prop_with_ref_query, + enum_prop_query=enum_prop_query, + model_prop_query=model_prop_query, + required_model_prop_query=required_model_prop_query, + nullable_model_prop_query=nullable_model_prop_query, + nullable_required_model_prop_query=nullable_required_model_prop_query, ) response = httpx.post( @@ -204,88 +206,88 @@ def sync_detailed( def sync( *, client: Client, - string_prop: Union[Unset, str] = "the default string", - not_required_not_nullable_datetime_prop: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), - not_required_nullable_datetime_prop: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), - required_not_nullable_datetime_prop: datetime.datetime = isoparse("1010-10-10T00:00:00"), - required_nullable_datetime_prop: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), - date_prop: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), - float_prop: Union[Unset, float] = 3.14, - int_prop: Union[Unset, int] = 7, - boolean_prop: Union[Unset, bool] = False, - list_prop: Union[Unset, List[AnEnum]] = UNSET, - union_prop: Union[Unset, float, str] = "not a float", - union_prop_with_ref: Union[AnEnum, Unset, float] = 0.6, - enum_prop: Union[Unset, AnEnum] = UNSET, - model_prop: Union[Unset, ModelWithUnionProperty] = UNSET, - required_model_prop: ModelWithUnionProperty, - nullable_model_prop: Union[Unset, None, ModelWithUnionProperty] = UNSET, - nullable_required_model_prop: Optional[ModelWithUnionProperty], + string_prop_query: Union[Unset, str] = "the default string", + not_required_not_nullable_datetime_prop_query: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), + not_required_nullable_datetime_prop_query: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), + required_not_nullable_datetime_prop_query: datetime.datetime = isoparse("1010-10-10T00:00:00"), + required_nullable_datetime_prop_query: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), + date_prop_query: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), + float_prop_query: Union[Unset, float] = 3.14, + int_prop_query: Union[Unset, int] = 7, + boolean_prop_query: Union[Unset, bool] = False, + list_prop_query: Union[Unset, List[AnEnum]] = UNSET, + union_prop_query: Union[Unset, float, str] = "not a float", + union_prop_with_ref_query: Union[AnEnum, Unset, float] = 0.6, + enum_prop_query: Union[Unset, AnEnum] = UNSET, + model_prop_query: Union[Unset, ModelWithUnionProperty] = UNSET, + required_model_prop_query: ModelWithUnionProperty, + nullable_model_prop_query: Union[Unset, None, ModelWithUnionProperty] = UNSET, + nullable_required_model_prop_query: Optional[ModelWithUnionProperty], ) -> Optional[Union[Any, HTTPValidationError]]: """ """ return sync_detailed( client=client, - string_prop=string_prop, - not_required_not_nullable_datetime_prop=not_required_not_nullable_datetime_prop, - not_required_nullable_datetime_prop=not_required_nullable_datetime_prop, - required_not_nullable_datetime_prop=required_not_nullable_datetime_prop, - required_nullable_datetime_prop=required_nullable_datetime_prop, - date_prop=date_prop, - float_prop=float_prop, - int_prop=int_prop, - boolean_prop=boolean_prop, - list_prop=list_prop, - union_prop=union_prop, - union_prop_with_ref=union_prop_with_ref, - enum_prop=enum_prop, - model_prop=model_prop, - required_model_prop=required_model_prop, - nullable_model_prop=nullable_model_prop, - nullable_required_model_prop=nullable_required_model_prop, + string_prop_query=string_prop_query, + not_required_not_nullable_datetime_prop_query=not_required_not_nullable_datetime_prop_query, + not_required_nullable_datetime_prop_query=not_required_nullable_datetime_prop_query, + required_not_nullable_datetime_prop_query=required_not_nullable_datetime_prop_query, + required_nullable_datetime_prop_query=required_nullable_datetime_prop_query, + date_prop_query=date_prop_query, + float_prop_query=float_prop_query, + int_prop_query=int_prop_query, + boolean_prop_query=boolean_prop_query, + list_prop_query=list_prop_query, + union_prop_query=union_prop_query, + union_prop_with_ref_query=union_prop_with_ref_query, + enum_prop_query=enum_prop_query, + model_prop_query=model_prop_query, + required_model_prop_query=required_model_prop_query, + nullable_model_prop_query=nullable_model_prop_query, + nullable_required_model_prop_query=nullable_required_model_prop_query, ).parsed async def asyncio_detailed( *, client: Client, - string_prop: Union[Unset, str] = "the default string", - not_required_not_nullable_datetime_prop: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), - not_required_nullable_datetime_prop: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), - required_not_nullable_datetime_prop: datetime.datetime = isoparse("1010-10-10T00:00:00"), - required_nullable_datetime_prop: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), - date_prop: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), - float_prop: Union[Unset, float] = 3.14, - int_prop: Union[Unset, int] = 7, - boolean_prop: Union[Unset, bool] = False, - list_prop: Union[Unset, List[AnEnum]] = UNSET, - union_prop: Union[Unset, float, str] = "not a float", - union_prop_with_ref: Union[AnEnum, Unset, float] = 0.6, - enum_prop: Union[Unset, AnEnum] = UNSET, - model_prop: Union[Unset, ModelWithUnionProperty] = UNSET, - required_model_prop: ModelWithUnionProperty, - nullable_model_prop: Union[Unset, None, ModelWithUnionProperty] = UNSET, - nullable_required_model_prop: Optional[ModelWithUnionProperty], + string_prop_query: Union[Unset, str] = "the default string", + not_required_not_nullable_datetime_prop_query: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), + not_required_nullable_datetime_prop_query: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), + required_not_nullable_datetime_prop_query: datetime.datetime = isoparse("1010-10-10T00:00:00"), + required_nullable_datetime_prop_query: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), + date_prop_query: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), + float_prop_query: Union[Unset, float] = 3.14, + int_prop_query: Union[Unset, int] = 7, + boolean_prop_query: Union[Unset, bool] = False, + list_prop_query: Union[Unset, List[AnEnum]] = UNSET, + union_prop_query: Union[Unset, float, str] = "not a float", + union_prop_with_ref_query: Union[AnEnum, Unset, float] = 0.6, + enum_prop_query: Union[Unset, AnEnum] = UNSET, + model_prop_query: Union[Unset, ModelWithUnionProperty] = UNSET, + required_model_prop_query: ModelWithUnionProperty, + nullable_model_prop_query: Union[Unset, None, ModelWithUnionProperty] = UNSET, + nullable_required_model_prop_query: Optional[ModelWithUnionProperty], ) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, - string_prop=string_prop, - not_required_not_nullable_datetime_prop=not_required_not_nullable_datetime_prop, - not_required_nullable_datetime_prop=not_required_nullable_datetime_prop, - required_not_nullable_datetime_prop=required_not_nullable_datetime_prop, - required_nullable_datetime_prop=required_nullable_datetime_prop, - date_prop=date_prop, - float_prop=float_prop, - int_prop=int_prop, - boolean_prop=boolean_prop, - list_prop=list_prop, - union_prop=union_prop, - union_prop_with_ref=union_prop_with_ref, - enum_prop=enum_prop, - model_prop=model_prop, - required_model_prop=required_model_prop, - nullable_model_prop=nullable_model_prop, - nullable_required_model_prop=nullable_required_model_prop, + string_prop_query=string_prop_query, + not_required_not_nullable_datetime_prop_query=not_required_not_nullable_datetime_prop_query, + not_required_nullable_datetime_prop_query=not_required_nullable_datetime_prop_query, + required_not_nullable_datetime_prop_query=required_not_nullable_datetime_prop_query, + required_nullable_datetime_prop_query=required_nullable_datetime_prop_query, + date_prop_query=date_prop_query, + float_prop_query=float_prop_query, + int_prop_query=int_prop_query, + boolean_prop_query=boolean_prop_query, + list_prop_query=list_prop_query, + union_prop_query=union_prop_query, + union_prop_with_ref_query=union_prop_with_ref_query, + enum_prop_query=enum_prop_query, + model_prop_query=model_prop_query, + required_model_prop_query=required_model_prop_query, + nullable_model_prop_query=nullable_model_prop_query, + nullable_required_model_prop_query=nullable_required_model_prop_query, ) async with httpx.AsyncClient() as _client: @@ -297,45 +299,45 @@ async def asyncio_detailed( async def asyncio( *, client: Client, - string_prop: Union[Unset, str] = "the default string", - not_required_not_nullable_datetime_prop: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), - not_required_nullable_datetime_prop: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), - required_not_nullable_datetime_prop: datetime.datetime = isoparse("1010-10-10T00:00:00"), - required_nullable_datetime_prop: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), - date_prop: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), - float_prop: Union[Unset, float] = 3.14, - int_prop: Union[Unset, int] = 7, - boolean_prop: Union[Unset, bool] = False, - list_prop: Union[Unset, List[AnEnum]] = UNSET, - union_prop: Union[Unset, float, str] = "not a float", - union_prop_with_ref: Union[AnEnum, Unset, float] = 0.6, - enum_prop: Union[Unset, AnEnum] = UNSET, - model_prop: Union[Unset, ModelWithUnionProperty] = UNSET, - required_model_prop: ModelWithUnionProperty, - nullable_model_prop: Union[Unset, None, ModelWithUnionProperty] = UNSET, - nullable_required_model_prop: Optional[ModelWithUnionProperty], + string_prop_query: Union[Unset, str] = "the default string", + not_required_not_nullable_datetime_prop_query: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), + not_required_nullable_datetime_prop_query: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), + required_not_nullable_datetime_prop_query: datetime.datetime = isoparse("1010-10-10T00:00:00"), + required_nullable_datetime_prop_query: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), + date_prop_query: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), + float_prop_query: Union[Unset, float] = 3.14, + int_prop_query: Union[Unset, int] = 7, + boolean_prop_query: Union[Unset, bool] = False, + list_prop_query: Union[Unset, List[AnEnum]] = UNSET, + union_prop_query: Union[Unset, float, str] = "not a float", + union_prop_with_ref_query: Union[AnEnum, Unset, float] = 0.6, + enum_prop_query: Union[Unset, AnEnum] = UNSET, + model_prop_query: Union[Unset, ModelWithUnionProperty] = UNSET, + required_model_prop_query: ModelWithUnionProperty, + nullable_model_prop_query: Union[Unset, None, ModelWithUnionProperty] = UNSET, + nullable_required_model_prop_query: Optional[ModelWithUnionProperty], ) -> Optional[Union[Any, HTTPValidationError]]: """ """ return ( await asyncio_detailed( client=client, - string_prop=string_prop, - not_required_not_nullable_datetime_prop=not_required_not_nullable_datetime_prop, - not_required_nullable_datetime_prop=not_required_nullable_datetime_prop, - required_not_nullable_datetime_prop=required_not_nullable_datetime_prop, - required_nullable_datetime_prop=required_nullable_datetime_prop, - date_prop=date_prop, - float_prop=float_prop, - int_prop=int_prop, - boolean_prop=boolean_prop, - list_prop=list_prop, - union_prop=union_prop, - union_prop_with_ref=union_prop_with_ref, - enum_prop=enum_prop, - model_prop=model_prop, - required_model_prop=required_model_prop, - nullable_model_prop=nullable_model_prop, - nullable_required_model_prop=nullable_required_model_prop, + string_prop_query=string_prop_query, + not_required_not_nullable_datetime_prop_query=not_required_not_nullable_datetime_prop_query, + not_required_nullable_datetime_prop_query=not_required_nullable_datetime_prop_query, + required_not_nullable_datetime_prop_query=required_not_nullable_datetime_prop_query, + required_nullable_datetime_prop_query=required_nullable_datetime_prop_query, + date_prop_query=date_prop_query, + float_prop_query=float_prop_query, + int_prop_query=int_prop_query, + boolean_prop_query=boolean_prop_query, + list_prop_query=list_prop_query, + union_prop_query=union_prop_query, + union_prop_with_ref_query=union_prop_with_ref_query, + enum_prop_query=enum_prop_query, + model_prop_query=model_prop_query, + required_model_prop_query=required_model_prop_query, + nullable_model_prop_query=nullable_model_prop_query, + nullable_required_model_prop_query=nullable_required_model_prop_query, ) ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py index 96ca18884..e8b9223ed 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py @@ -13,28 +13,28 @@ def _get_kwargs( *, client: Client, - an_enum_value: List[AnEnum], - some_date: Union[datetime.date, datetime.datetime], + an_enum_value_query: List[AnEnum], + some_date_query: Union[datetime.date, datetime.datetime], ) -> Dict[str, Any]: url = "{}/tests/".format(client.base_url) headers: Dict[str, Any] = client.get_headers() cookies: Dict[str, Any] = client.get_cookies() - json_an_enum_value = [] - for an_enum_value_item_data in an_enum_value: + json_an_enum_value_query = [] + for an_enum_value_item_data in an_enum_value_query: an_enum_value_item = an_enum_value_item_data.value - json_an_enum_value.append(an_enum_value_item) + json_an_enum_value_query.append(an_enum_value_item) - if isinstance(some_date, datetime.date): - json_some_date = some_date.isoformat() + if isinstance(some_date_query, datetime.date): + json_some_date_query = some_date_query.isoformat() else: - json_some_date = some_date.isoformat() + json_some_date_query = some_date_query.isoformat() params: Dict[str, Any] = { - "an_enum_value": json_an_enum_value, - "some_date": json_some_date, + "an_enum_value": json_an_enum_value_query, + "some_date": json_some_date_query, } params = {k: v for k, v in params.items() if v is not UNSET and v is not None} @@ -80,13 +80,13 @@ def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidatio def sync_detailed( *, client: Client, - an_enum_value: List[AnEnum], - some_date: Union[datetime.date, datetime.datetime], + an_enum_value_query: List[AnEnum], + some_date_query: Union[datetime.date, datetime.datetime], ) -> Response[Union[HTTPValidationError, List[AModel]]]: kwargs = _get_kwargs( client=client, - an_enum_value=an_enum_value, - some_date=some_date, + an_enum_value_query=an_enum_value_query, + some_date_query=some_date_query, ) response = httpx.get( @@ -99,28 +99,28 @@ def sync_detailed( def sync( *, client: Client, - an_enum_value: List[AnEnum], - some_date: Union[datetime.date, datetime.datetime], + an_enum_value_query: List[AnEnum], + some_date_query: Union[datetime.date, datetime.datetime], ) -> Optional[Union[HTTPValidationError, List[AModel]]]: """Get a list of things""" return sync_detailed( client=client, - an_enum_value=an_enum_value, - some_date=some_date, + an_enum_value_query=an_enum_value_query, + some_date_query=some_date_query, ).parsed async def asyncio_detailed( *, client: Client, - an_enum_value: List[AnEnum], - some_date: Union[datetime.date, datetime.datetime], + an_enum_value_query: List[AnEnum], + some_date_query: Union[datetime.date, datetime.datetime], ) -> Response[Union[HTTPValidationError, List[AModel]]]: kwargs = _get_kwargs( client=client, - an_enum_value=an_enum_value, - some_date=some_date, + an_enum_value_query=an_enum_value_query, + some_date_query=some_date_query, ) async with httpx.AsyncClient() as _client: @@ -132,15 +132,15 @@ async def asyncio_detailed( async def asyncio( *, client: Client, - an_enum_value: List[AnEnum], - some_date: Union[datetime.date, datetime.datetime], + an_enum_value_query: List[AnEnum], + some_date_query: Union[datetime.date, datetime.datetime], ) -> Optional[Union[HTTPValidationError, List[AModel]]]: """Get a list of things""" return ( await asyncio_detailed( client=client, - an_enum_value=an_enum_value, - some_date=some_date, + an_enum_value_query=an_enum_value_query, + some_date_query=some_date_query, ) ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py index d295ddaab..1c8f9465b 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py @@ -11,17 +11,17 @@ def _get_kwargs( *, client: Client, - int_enum: AnIntEnum, + int_enum_query: AnIntEnum, ) -> Dict[str, Any]: url = "{}/tests/int_enum".format(client.base_url) headers: Dict[str, Any] = client.get_headers() cookies: Dict[str, Any] = client.get_cookies() - json_int_enum = int_enum.value + json_int_enum_query = int_enum_query.value params: Dict[str, Any] = { - "int_enum": json_int_enum, + "int_enum": json_int_enum_query, } params = {k: v for k, v in params.items() if v is not UNSET and v is not None} @@ -58,11 +58,11 @@ def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPVali def sync_detailed( *, client: Client, - int_enum: AnIntEnum, + int_enum_query: AnIntEnum, ) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, - int_enum=int_enum, + int_enum_query=int_enum_query, ) response = httpx.post( @@ -75,24 +75,24 @@ def sync_detailed( def sync( *, client: Client, - int_enum: AnIntEnum, + int_enum_query: AnIntEnum, ) -> Optional[Union[Any, HTTPValidationError]]: """ """ return sync_detailed( client=client, - int_enum=int_enum, + int_enum_query=int_enum_query, ).parsed async def asyncio_detailed( *, client: Client, - int_enum: AnIntEnum, + int_enum_query: AnIntEnum, ) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, - int_enum=int_enum, + int_enum_query=int_enum_query, ) async with httpx.AsyncClient() as _client: @@ -104,13 +104,13 @@ async def asyncio_detailed( async def asyncio( *, client: Client, - int_enum: AnIntEnum, + int_enum_query: AnIntEnum, ) -> Optional[Union[Any, HTTPValidationError]]: """ """ return ( await asyncio_detailed( client=client, - int_enum=int_enum, + int_enum_query=int_enum_query, ) ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py index eba1f9615..a3b418775 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py @@ -18,14 +18,14 @@ def _get_kwargs( headers: Dict[str, Any] = client.get_headers() cookies: Dict[str, Any] = client.get_cookies() - json_json_body = json_body.to_dict() + json_body.to_dict() return { "url": url, "headers": headers, "cookies": cookies, "timeout": client.get_timeout(), - "json": json_json_body, + "json": json_body, } diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py index 370ba1d45..f6b3f9846 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py @@ -10,19 +10,19 @@ def _get_kwargs( *, client: Client, - query_param: Union[Unset, List[str]] = UNSET, + query_param_query: Union[Unset, List[str]] = UNSET, ) -> Dict[str, Any]: url = "{}/tests/optional_query_param/".format(client.base_url) headers: Dict[str, Any] = client.get_headers() cookies: Dict[str, Any] = client.get_cookies() - json_query_param: Union[Unset, List[str]] = UNSET - if not isinstance(query_param, Unset): - json_query_param = query_param + json_query_param_query: Union[Unset, List[str]] = UNSET + if not isinstance(query_param_query, Unset): + json_query_param_query = query_param_query params: Dict[str, Any] = { - "query_param": json_query_param, + "query_param": json_query_param_query, } params = {k: v for k, v in params.items() if v is not UNSET and v is not None} @@ -59,11 +59,11 @@ def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPVali def sync_detailed( *, client: Client, - query_param: Union[Unset, List[str]] = UNSET, + query_param_query: Union[Unset, List[str]] = UNSET, ) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, - query_param=query_param, + query_param_query=query_param_query, ) response = httpx.get( @@ -76,24 +76,24 @@ def sync_detailed( def sync( *, client: Client, - query_param: Union[Unset, List[str]] = UNSET, + query_param_query: Union[Unset, List[str]] = UNSET, ) -> Optional[Union[Any, HTTPValidationError]]: """Test optional query parameters""" return sync_detailed( client=client, - query_param=query_param, + query_param_query=query_param_query, ).parsed async def asyncio_detailed( *, client: Client, - query_param: Union[Unset, List[str]] = UNSET, + query_param_query: Union[Unset, List[str]] = UNSET, ) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, - query_param=query_param, + query_param_query=query_param_query, ) async with httpx.AsyncClient() as _client: @@ -105,13 +105,13 @@ async def asyncio_detailed( async def asyncio( *, client: Client, - query_param: Union[Unset, List[str]] = UNSET, + query_param_query: Union[Unset, List[str]] = UNSET, ) -> Optional[Union[Any, HTTPValidationError]]: """Test optional query parameters""" return ( await asyncio_detailed( client=client, - query_param=query_param, + query_param_query=query_param_query, ) ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py index 59d12f3d6..323472ce7 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py @@ -18,14 +18,14 @@ def _get_kwargs( headers: Dict[str, Any] = client.get_headers() cookies: Dict[str, Any] = client.get_cookies() - json_json_body = json_body.to_dict() + json_body.to_dict() return { "url": url, "headers": headers, "cookies": cookies, "timeout": client.get_timeout(), - "json": json_json_body, + "json": json_body, } diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py index 90cf20b07..c5bcbc084 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py @@ -9,14 +9,14 @@ def _get_kwargs( *, client: Client, - my_token: str, + my_token_cookie: str, ) -> Dict[str, Any]: url = "{}/auth/token_with_cookie".format(client.base_url) headers: Dict[str, Any] = client.get_headers() cookies: Dict[str, Any] = client.get_cookies() - cookies["MyToken"] = my_token + cookies["MyToken"] = my_token_cookie return { "url": url, @@ -38,11 +38,11 @@ def _build_response(*, response: httpx.Response) -> Response[Any]: def sync_detailed( *, client: Client, - my_token: str, + my_token_cookie: str, ) -> Response[Any]: kwargs = _get_kwargs( client=client, - my_token=my_token, + my_token_cookie=my_token_cookie, ) response = httpx.get( @@ -55,11 +55,11 @@ def sync_detailed( async def asyncio_detailed( *, client: Client, - my_token: str, + my_token_cookie: str, ) -> Response[Any]: kwargs = _get_kwargs( client=client, - my_token=my_token, + my_token_cookie=my_token_cookie, ) async with httpx.AsyncClient() as _client: diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py index d72aaae4d..9eb1b4e64 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py @@ -12,15 +12,15 @@ def _get_kwargs( *, client: Client, multipart_data: BodyUploadFileTestsUploadPost, - keep_alive: Union[Unset, bool] = UNSET, + keep_alive_header: Union[Unset, bool] = UNSET, ) -> Dict[str, Any]: url = "{}/tests/upload".format(client.base_url) headers: Dict[str, Any] = client.get_headers() cookies: Dict[str, Any] = client.get_cookies() - if keep_alive is not UNSET: - headers["keep-alive"] = keep_alive + if keep_alive_header is not UNSET: + headers["keep-alive"] = keep_alive_header multipart_multipart_data = multipart_data.to_multipart() @@ -58,12 +58,12 @@ def sync_detailed( *, client: Client, multipart_data: BodyUploadFileTestsUploadPost, - keep_alive: Union[Unset, bool] = UNSET, + keep_alive_header: Union[Unset, bool] = UNSET, ) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, multipart_data=multipart_data, - keep_alive=keep_alive, + keep_alive_header=keep_alive_header, ) response = httpx.post( @@ -77,14 +77,14 @@ def sync( *, client: Client, multipart_data: BodyUploadFileTestsUploadPost, - keep_alive: Union[Unset, bool] = UNSET, + keep_alive_header: Union[Unset, bool] = UNSET, ) -> Optional[Union[Any, HTTPValidationError]]: """Upload a file""" return sync_detailed( client=client, multipart_data=multipart_data, - keep_alive=keep_alive, + keep_alive_header=keep_alive_header, ).parsed @@ -92,12 +92,12 @@ async def asyncio_detailed( *, client: Client, multipart_data: BodyUploadFileTestsUploadPost, - keep_alive: Union[Unset, bool] = UNSET, + keep_alive_header: Union[Unset, bool] = UNSET, ) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, multipart_data=multipart_data, - keep_alive=keep_alive, + keep_alive_header=keep_alive_header, ) async with httpx.AsyncClient() as _client: @@ -110,7 +110,7 @@ async def asyncio( *, client: Client, multipart_data: BodyUploadFileTestsUploadPost, - keep_alive: Union[Unset, bool] = UNSET, + keep_alive_header: Union[Unset, bool] = UNSET, ) -> Optional[Union[Any, HTTPValidationError]]: """Upload a file""" @@ -118,6 +118,6 @@ async def asyncio( await asyncio_detailed( client=client, multipart_data=multipart_data, - keep_alive=keep_alive, + keep_alive_header=keep_alive_header, ) ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py index e5e42d546..21bbf43c9 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py @@ -11,15 +11,15 @@ def _get_kwargs( *, client: Client, multipart_data: List[File], - keep_alive: Union[Unset, bool] = UNSET, + keep_alive_header: Union[Unset, bool] = UNSET, ) -> Dict[str, Any]: url = "{}/tests/upload/multiple".format(client.base_url) headers: Dict[str, Any] = client.get_headers() cookies: Dict[str, Any] = client.get_cookies() - if keep_alive is not UNSET: - headers["keep-alive"] = keep_alive + if keep_alive_header is not UNSET: + headers["keep-alive"] = keep_alive_header multipart_multipart_data = [] for multipart_data_item_data in multipart_data: @@ -61,12 +61,12 @@ def sync_detailed( *, client: Client, multipart_data: List[File], - keep_alive: Union[Unset, bool] = UNSET, + keep_alive_header: Union[Unset, bool] = UNSET, ) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, multipart_data=multipart_data, - keep_alive=keep_alive, + keep_alive_header=keep_alive_header, ) response = httpx.post( @@ -80,14 +80,14 @@ def sync( *, client: Client, multipart_data: List[File], - keep_alive: Union[Unset, bool] = UNSET, + keep_alive_header: Union[Unset, bool] = UNSET, ) -> Optional[Union[Any, HTTPValidationError]]: """Upload several files in the same request""" return sync_detailed( client=client, multipart_data=multipart_data, - keep_alive=keep_alive, + keep_alive_header=keep_alive_header, ).parsed @@ -95,12 +95,12 @@ async def asyncio_detailed( *, client: Client, multipart_data: List[File], - keep_alive: Union[Unset, bool] = UNSET, + keep_alive_header: Union[Unset, bool] = UNSET, ) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, multipart_data=multipart_data, - keep_alive=keep_alive, + keep_alive_header=keep_alive_header, ) async with httpx.AsyncClient() as _client: @@ -113,7 +113,7 @@ async def asyncio( *, client: Client, multipart_data: List[File], - keep_alive: Union[Unset, bool] = UNSET, + keep_alive_header: Union[Unset, bool] = UNSET, ) -> Optional[Union[Any, HTTPValidationError]]: """Upload several files in the same request""" @@ -121,6 +121,6 @@ async def asyncio( await asyncio_detailed( client=client, multipart_data=multipart_data, - keep_alive=keep_alive, + keep_alive_header=keep_alive_header, ) ).parsed From 3292a38dbc292e83e1ca12d8443888bd7cebec7f Mon Sep 17 00:00:00 2001 From: mtovts Date: Mon, 26 Jul 2021 11:25:57 +0300 Subject: [PATCH 16/57] Update `\test_custom_templates\*_init.py.jinja` --- end_to_end_tests/test_custom_templates/api_init.py.jinja | 2 +- end_to_end_tests/test_custom_templates/endpoint_init.py.jinja | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/end_to_end_tests/test_custom_templates/api_init.py.jinja b/end_to_end_tests/test_custom_templates/api_init.py.jinja index 03c2a2f6f..5f6a23523 100644 --- a/end_to_end_tests/test_custom_templates/api_init.py.jinja +++ b/end_to_end_tests/test_custom_templates/api_init.py.jinja @@ -2,7 +2,7 @@ from typing import Type {% for tag in endpoint_collections_by_tag.keys() %} -from {{ package_name }}.api.{{ tag }} import {{ utils.pascal_case(tag) }}Endpoints +from .{{ tag }} import {{ utils.pascal_case(tag) }}Endpoints {% endfor %} class {{ utils.pascal_case(package_name) }}Api: diff --git a/end_to_end_tests/test_custom_templates/endpoint_init.py.jinja b/end_to_end_tests/test_custom_templates/endpoint_init.py.jinja index 57e8ba124..ca9851679 100644 --- a/end_to_end_tests/test_custom_templates/endpoint_init.py.jinja +++ b/end_to_end_tests/test_custom_templates/endpoint_init.py.jinja @@ -2,7 +2,7 @@ import types {% for endpoint in endpoint_collection.endpoints %} -from {{ package_name }}.api.{{ endpoint_collection.tag }} import {{ utils.snake_case(endpoint.name) }} +from . import {{ utils.snake_case(endpoint.name) }} {% endfor %} class {{ utils.pascal_case(endpoint_collection.tag) }}Endpoints: From 84a440ab3976b380f76388a3cc546414ac5a3b6f Mon Sep 17 00:00:00 2001 From: mtovts Date: Tue, 27 Jul 2021 13:07:29 +0300 Subject: [PATCH 17/57] Update `test__add_parameters_happy` --- .PR_note.md | 1 + tests/test_parser/test_openapi.py | 101 +++++++++++++++++++++++------- 2 files changed, 78 insertions(+), 24 deletions(-) create mode 100644 .PR_note.md diff --git a/.PR_note.md b/.PR_note.md new file mode 100644 index 000000000..fb6ca1501 --- /dev/null +++ b/.PR_note.md @@ -0,0 +1 @@ + ```python3 diff --git a/tests/test_parser/test_openapi.py b/tests/test_parser/test_openapi.py index f96dcb049..62e56d5f3 100644 --- a/tests/test_parser/test_openapi.py +++ b/tests/test_parser/test_openapi.py @@ -543,35 +543,59 @@ def test__add_parameters_happy(self, mocker): from openapi_python_client.parser.properties import Property endpoint = self.make_endpoint() + path_prop_name = 'path_prop_name' path_prop = mocker.MagicMock(autospec=Property) path_prop_import = mocker.MagicMock() path_prop.get_imports = mocker.MagicMock(return_value={path_prop_import}) + + query_prop_name = 'query_prop_name' query_prop = mocker.MagicMock(autospec=Property) query_prop_import = mocker.MagicMock() query_prop.get_imports = mocker.MagicMock(return_value={query_prop_import}) - header_prop = mocker.MagicMock(autospec=Property) - header_prop_import = mocker.MagicMock() - header_prop.get_imports = mocker.MagicMock(return_value={header_prop_import}) + + header_prop_name = 'header_prop_name' + header_prop_operation = mocker.MagicMock(autospec=Property) + header_prop_operation.name = header_prop_name + header_prop_operation.required = False + header_prop_operation_import = mocker.MagicMock() + header_prop_operation.get_imports = mocker.MagicMock(return_value={header_prop_operation_import}) + + header_prop_path = mocker.MagicMock(autospec=Property) + header_prop_path.name = header_prop_name + header_prop_path.required = True + header_prop_path_import = mocker.MagicMock() + header_prop_path.get_imports = mocker.MagicMock(return_value={header_prop_path_import}) + + cookie_prop_name = 'cookie_prop_name' + cookie_prop = mocker.MagicMock(autospec=Property) + cookie_prop_import = mocker.MagicMock() + cookie_prop.get_imports = mocker.MagicMock(return_value={cookie_prop_import}) + schemas_1 = mocker.MagicMock() schemas_2 = mocker.MagicMock() schemas_3 = mocker.MagicMock() + schemas_4 = mocker.MagicMock() + schemas_5 = mocker.MagicMock() property_from_data = mocker.patch( f"{MODULE_NAME}.property_from_data", - side_effect=[(path_prop, schemas_1), (query_prop, schemas_2), (header_prop, schemas_3)], + side_effect=[(path_prop, schemas_1), (query_prop, schemas_2), (header_prop_operation, schemas_3), (header_prop_path, schemas_4), (cookie_prop, schemas_5)], ) path_schema = mocker.MagicMock() query_schema = mocker.MagicMock() - header_schema = mocker.MagicMock() - data = oai.Operation.construct( + header_operation_schema = mocker.MagicMock() + cookie_schema = mocker.MagicMock() + header_path_schema = mocker.MagicMock() + + operation_data = oai.Operation.construct( parameters=[ oai.Parameter.construct( - name="path_prop_name", required=True, param_schema=path_schema, param_in="path" + name=path_prop_name, required=True, param_schema=path_schema, param_in="path" ), oai.Parameter.construct( - name="query_prop_name", required=False, param_schema=query_schema, param_in="query" + name=query_prop_name, required=False, param_schema=query_schema, param_in="query" ), oai.Parameter.construct( - name="header_prop_name", required=False, param_schema=header_schema, param_in="header" + name=header_prop_name, required=False, param_schema=header_operation_schema, param_in="header" ), oai.Reference.construct(), # Should be ignored oai.Parameter.construct(), # Should be ignored @@ -581,13 +605,28 @@ def test__add_parameters_happy(self, mocker): config = MagicMock() (endpoint, schemas) = Endpoint._add_parameters( - endpoint=endpoint, data=data, schemas=initial_schemas, config=config + endpoint=endpoint, data=operation_data, schemas=initial_schemas, config=config + ) + path_item_data = oai.PathItem.construct( + parameters=[ + oai.Parameter.construct( + name=header_prop_name, required=True, param_schema=header_path_schema, param_in="header" + ), + oai.Parameter.construct( + name=cookie_prop_name, required=False, param_schema=cookie_schema, param_in="cookie" + ), + oai.Reference.construct(), # Should be ignored + oai.Parameter.construct(), # Should be ignored + ] + ) + (endpoint, schemas) = Endpoint._add_parameters( + endpoint=endpoint, data=path_item_data, schemas=schemas, config=config ) property_from_data.assert_has_calls( [ mocker.call( - name="path_prop_name", + name=path_prop_name, required=True, data=path_schema, schemas=initial_schemas, @@ -595,7 +634,7 @@ def test__add_parameters_happy(self, mocker): config=config, ), mocker.call( - name="query_prop_name", + name=query_prop_name, required=False, data=query_schema, schemas=schemas_1, @@ -603,26 +642,43 @@ def test__add_parameters_happy(self, mocker): config=config, ), mocker.call( - name="header_prop_name", + name=header_prop_name, required=False, - data=header_schema, + data=header_operation_schema, schemas=schemas_2, parent_name="name", config=config, ), + mocker.call( + name=header_prop_name, + required=True, + data=header_path_schema, + schemas=schemas_3, + parent_name="name", + config=config, + ), + mocker.call( + name=cookie_prop_name, + required=False, + data=cookie_schema, + schemas=schemas_4, + parent_name="name", + config=config, + ), ] ) path_prop.get_imports.assert_called_once_with(prefix="...") query_prop.get_imports.assert_called_once_with(prefix="...") - header_prop.get_imports.assert_called_once_with(prefix="...") - assert endpoint.relative_imports == {"import_3", path_prop_import, query_prop_import, header_prop_import} + header_prop_operation.get_imports.assert_called_once_with(prefix="...") + cookie_prop.get_imports.assert_called_once_with(prefix="...") + header_prop_path.get_imports.assert_called_once_with(prefix="...") + assert endpoint.relative_imports == {"import_3", path_prop_import, query_prop_import, header_prop_operation_import, cookie_prop_import, header_prop_path_import} assert endpoint.path_parameters == {path_prop.name: path_prop} assert endpoint.query_parameters == {query_prop.name: query_prop} - assert endpoint.header_parameters == {header_prop.name: header_prop} - assert schemas == schemas_3 - - def test__add_parameters_override_properties(self, mocker): - pass # TODO + assert endpoint.header_parameters == {header_prop_operation.name: header_prop_operation} + assert endpoint.header_parameters[header_prop_operation.name].required is False + assert endpoint.cookie_parameters == {cookie_prop.name: cookie_prop} + assert schemas == schemas_5 def test__add_parameters_duplicate_properties(self, mocker): from openapi_python_client.parser.openapi import Endpoint, Schemas @@ -951,9 +1007,6 @@ def test_from_data(self, mocker): schemas_3, ) - def test_from_data_overriding_common_parameters(self, mocker): - pass # TODO - def test_from_data_errors(self, mocker): from openapi_python_client.parser.openapi import Endpoint, EndpointCollection, ParseError From c6bfea2111d61a54011a5d24fe7d98a2cba2416d Mon Sep 17 00:00:00 2001 From: mtovts Date: Tue, 27 Jul 2021 13:08:04 +0300 Subject: [PATCH 18/57] naming --- openapi_python_client/parser/openapi.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index 2590cd48e..28d5578c4 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -246,7 +246,7 @@ def _add_parameters( if data.parameters is None: return endpoint, schemas - used_identifiers: Set[PythonIdentifier] = set() + used_python_identifiers: Set[PythonIdentifier] = set() for param in data.parameters: if isinstance(param, oai.Reference) or param.param_schema is None: @@ -273,7 +273,7 @@ def _add_parameters( oai.ParameterLocation.COOKIE: endpoint.cookie_parameters, } - if prop.python_name in used_identifiers: + if prop.python_name in used_python_identifiers: return ( ParseError( data=data, @@ -284,7 +284,7 @@ def _add_parameters( schemas, ) parameters_by_location[param.param_in].setdefault(prop.name, prop) - used_identifiers.add(prop.python_name) + used_python_identifiers.add(prop.python_name) return endpoint, schemas From 6378616fb87063434748ff6d8fbb5c845817ca6d Mon Sep 17 00:00:00 2001 From: mtovts Date: Tue, 27 Jul 2021 13:35:47 +0300 Subject: [PATCH 19/57] Delete .PR_note.md --- .PR_note.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .PR_note.md diff --git a/.PR_note.md b/.PR_note.md deleted file mode 100644 index fb6ca1501..000000000 --- a/.PR_note.md +++ /dev/null @@ -1 +0,0 @@ - ```python3 From 4080f8946d9569294aa21173d0d6263d408afd8a Mon Sep 17 00:00:00 2001 From: mtovts Date: Fri, 30 Jul 2021 17:10:57 +0300 Subject: [PATCH 20/57] return: Set parameter identifier `{param.name} _ {param.param_in}` only if got the parameters with the same name --- openapi_python_client/parser/openapi.py | 49 ++++++++++++++----------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index 28d5578c4..1b796bcf8 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -99,6 +99,7 @@ class Endpoint: json_body: Optional[Property] = None multipart_body: Optional[Property] = None errors: List[ParseError] = field(default_factory=list) + used_python_identifiers: Set[PythonIdentifier] = field(default_factory=set) @staticmethod def parse_request_form_body(*, body: oai.RequestBody, config: Config) -> Optional[Class]: @@ -246,11 +247,27 @@ def _add_parameters( if data.parameters is None: return endpoint, schemas - used_python_identifiers: Set[PythonIdentifier] = set() + unique_parameters: Set[Tuple[str, oai.ParameterLocation]] = set() + parameters_by_location = { + oai.ParameterLocation.QUERY: endpoint.query_parameters, + oai.ParameterLocation.PATH: endpoint.path_parameters, + oai.ParameterLocation.HEADER: endpoint.header_parameters, + oai.ParameterLocation.COOKIE: endpoint.cookie_parameters, + } for param in data.parameters: if isinstance(param, oai.Reference) or param.param_schema is None: continue + + unique_param = (param.name, param.param_in) + if unique_param in unique_parameters: + duplication_detail = ( + "Parameters MUST NOT duplicates. A unique parameter is defined by a combination of a name and location. " + f"Duplicated parameters named `{param.name}` detected in `{param.param_in}`." + ) + return ParseError(data=data, detail=duplication_detail), schemas + unique_parameters.add(unique_param) + prop, schemas = property_from_data( name=param.name, required=param.required, @@ -262,29 +279,19 @@ def _add_parameters( if isinstance(prop, ParseError): return ParseError(detail=f"cannot parse parameter of endpoint {endpoint.name}", data=prop.data), schemas - endpoint.relative_imports.update(prop.get_imports(prefix="...")) - - prop.set_python_name(new_name=f"{param.name}_{param.param_in}", config=config) + for location, parameters_dict in parameters_by_location.items(): + if prop.name in parameters_dict: + existing_prop: Property = parameters_dict[prop.name] + # Existing should be converted too for consistency + endpoint.used_python_identifiers.remove(existing_prop.python_name) + existing_prop.set_python_name(new_name=f"{existing_prop.name}_{location}", config=config) + endpoint.used_python_identifiers.add(existing_prop.python_name) - parameters_by_location = { - oai.ParameterLocation.QUERY: endpoint.query_parameters, - oai.ParameterLocation.PATH: endpoint.path_parameters, - oai.ParameterLocation.HEADER: endpoint.header_parameters, - oai.ParameterLocation.COOKIE: endpoint.cookie_parameters, - } + prop.set_python_name(new_name=f"{param.name}_{param.param_in}", config=config) - if prop.python_name in used_python_identifiers: - return ( - ParseError( - data=data, - detail="Parameters MUST NOT duplicates. " - f"A unique parameter is defined by a combination of a name and location. " - f"Duplicated parameters named `{prop.name}` detected in `{param.param_in}`.", - ), - schemas, - ) + endpoint.relative_imports.update(prop.get_imports(prefix="...")) parameters_by_location[param.param_in].setdefault(prop.name, prop) - used_python_identifiers.add(prop.python_name) + endpoint.used_python_identifiers.add(prop.python_name) return endpoint, schemas From 237ebb32ef79e094d5de1a2fb168d03ba3a1c068 Mon Sep 17 00:00:00 2001 From: mtovts Date: Fri, 30 Jul 2021 17:11:59 +0300 Subject: [PATCH 21/57] Update test related with python identifiers for parameters --- tests/test_parser/test_openapi.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_parser/test_openapi.py b/tests/test_parser/test_openapi.py index 62e56d5f3..ea3a8a596 100644 --- a/tests/test_parser/test_openapi.py +++ b/tests/test_parser/test_openapi.py @@ -547,11 +547,13 @@ def test__add_parameters_happy(self, mocker): path_prop = mocker.MagicMock(autospec=Property) path_prop_import = mocker.MagicMock() path_prop.get_imports = mocker.MagicMock(return_value={path_prop_import}) + path_prop.python_name = 'path_prop_name' query_prop_name = 'query_prop_name' query_prop = mocker.MagicMock(autospec=Property) query_prop_import = mocker.MagicMock() query_prop.get_imports = mocker.MagicMock(return_value={query_prop_import}) + query_prop.python_name = 'query_prop_name' header_prop_name = 'header_prop_name' header_prop_operation = mocker.MagicMock(autospec=Property) @@ -559,17 +561,20 @@ def test__add_parameters_happy(self, mocker): header_prop_operation.required = False header_prop_operation_import = mocker.MagicMock() header_prop_operation.get_imports = mocker.MagicMock(return_value={header_prop_operation_import}) + header_prop_operation.python_name = 'header_prop_name' header_prop_path = mocker.MagicMock(autospec=Property) header_prop_path.name = header_prop_name header_prop_path.required = True header_prop_path_import = mocker.MagicMock() header_prop_path.get_imports = mocker.MagicMock(return_value={header_prop_path_import}) + header_prop_path.python_name = 'header_prop_name' cookie_prop_name = 'cookie_prop_name' cookie_prop = mocker.MagicMock(autospec=Property) cookie_prop_import = mocker.MagicMock() cookie_prop.get_imports = mocker.MagicMock(return_value={cookie_prop_import}) + cookie_prop.python_name = 'cookie_prop_name' schemas_1 = mocker.MagicMock() schemas_2 = mocker.MagicMock() From bbb4928aad3eab31f76b212af05e257564089e8c Mon Sep 17 00:00:00 2001 From: mtovts Date: Fri, 30 Jul 2021 17:12:55 +0300 Subject: [PATCH 22/57] Revert "Update generated endpoints in `common_parameters`: add location postfix" This reverts commit a4f645874478c5f0eafe90cd7cca691397afc294. --- .../api/default/get_common_parameters.py | 12 ++++++------ .../api/default/post_common_parameters.py | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py b/end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py index 21af63e0b..96487587d 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py @@ -9,7 +9,7 @@ def _get_kwargs( *, client: Client, - common_query: Union[Unset, str] = UNSET, + common: Union[Unset, str] = UNSET, ) -> Dict[str, Any]: url = "{}/common_parameters".format(client.base_url) @@ -17,7 +17,7 @@ def _get_kwargs( cookies: Dict[str, Any] = client.get_cookies() params: Dict[str, Any] = { - "common": common_query, + "common": common, } params = {k: v for k, v in params.items() if v is not UNSET and v is not None} @@ -42,11 +42,11 @@ def _build_response(*, response: httpx.Response) -> Response[Any]: def sync_detailed( *, client: Client, - common_query: Union[Unset, str] = UNSET, + common: Union[Unset, str] = UNSET, ) -> Response[Any]: kwargs = _get_kwargs( client=client, - common_query=common_query, + common=common, ) response = httpx.get( @@ -59,11 +59,11 @@ def sync_detailed( async def asyncio_detailed( *, client: Client, - common_query: Union[Unset, str] = UNSET, + common: Union[Unset, str] = UNSET, ) -> Response[Any]: kwargs = _get_kwargs( client=client, - common_query=common_query, + common=common, ) async with httpx.AsyncClient() as _client: diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py b/end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py index 7987dd9ea..3283f4830 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py @@ -9,7 +9,7 @@ def _get_kwargs( *, client: Client, - common_query: Union[Unset, str] = UNSET, + common: Union[Unset, str] = UNSET, ) -> Dict[str, Any]: url = "{}/common_parameters".format(client.base_url) @@ -17,7 +17,7 @@ def _get_kwargs( cookies: Dict[str, Any] = client.get_cookies() params: Dict[str, Any] = { - "common": common_query, + "common": common, } params = {k: v for k, v in params.items() if v is not UNSET and v is not None} @@ -42,11 +42,11 @@ def _build_response(*, response: httpx.Response) -> Response[Any]: def sync_detailed( *, client: Client, - common_query: Union[Unset, str] = UNSET, + common: Union[Unset, str] = UNSET, ) -> Response[Any]: kwargs = _get_kwargs( client=client, - common_query=common_query, + common=common, ) response = httpx.post( @@ -59,11 +59,11 @@ def sync_detailed( async def asyncio_detailed( *, client: Client, - common_query: Union[Unset, str] = UNSET, + common: Union[Unset, str] = UNSET, ) -> Response[Any]: kwargs = _get_kwargs( client=client, - common_query=common_query, + common=common, ) async with httpx.AsyncClient() as _client: From d59c5559e00ab2a11f4df4435b8d1ede1c40634c Mon Sep 17 00:00:00 2001 From: mtovts Date: Fri, 30 Jul 2021 17:13:32 +0300 Subject: [PATCH 23/57] Revert "Update `end_to_end_tests\golden-record\*`" This reverts commit 38f341b6d85ec07f53d00d4cc15feb2f4eb6da92. --- .../my_test_api_client/api/__init__.py | 8 +- .../api/default/__init__.py | 2 +- .../api/parameters/__init__.py | 14 +- .../my_test_api_client/api/tag1/__init__.py | 2 +- .../my_test_api_client/api/tests/__init__.py | 2 +- .../api/tests/defaults_tests_defaults_post.py | 430 +++++++++--------- .../api/tests/get_user_list.py | 52 +-- .../api/tests/int_enum_tests_int_enum_post.py | 22 +- .../tests/json_body_tests_json_body_post.py | 4 +- ...tional_value_tests_optional_query_param.py | 26 +- .../api/tests/test_inline_objects.py | 4 +- ..._with_cookie_auth_token_with_cookie_get.py | 12 +- .../tests/upload_file_tests_upload_post.py | 22 +- ...upload_multiple_files_tests_upload_post.py | 22 +- 14 files changed, 304 insertions(+), 318 deletions(-) diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/__init__.py b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/__init__.py index f516aefcf..e5f9a66ed 100644 --- a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/__init__.py +++ b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/__init__.py @@ -2,10 +2,10 @@ from typing import Type -from .default import DefaultEndpoints -from .parameters import ParametersEndpoints -from .tag1 import Tag1Endpoints -from .tests import TestsEndpoints +from my_test_api_client.api.default import DefaultEndpoints +from my_test_api_client.api.parameters import ParametersEndpoints +from my_test_api_client.api.tag1 import Tag1Endpoints +from my_test_api_client.api.tests import TestsEndpoints class MyTestApiClientApi: diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/default/__init__.py b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/default/__init__.py index a4580103f..4d0eb4fb5 100644 --- a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/default/__init__.py +++ b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/default/__init__.py @@ -2,7 +2,7 @@ import types -from . import get_common_parameters, post_common_parameters +from my_test_api_client.api.default import get_common_parameters, post_common_parameters class DefaultEndpoints: diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/parameters/__init__.py b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/parameters/__init__.py index 0d34e1f2d..b92c6d96b 100644 --- a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/parameters/__init__.py +++ b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/parameters/__init__.py @@ -2,22 +2,10 @@ import types -from . import ( - delete_common_parameters_overriding_param, - get_common_parameters_overriding_param, - get_same_name_multiple_locations_param, -) +from my_test_api_client.api.parameters import get_same_name_multiple_locations_param class ParametersEndpoints: - @classmethod - def get_common_parameters_overriding_param(cls) -> types.ModuleType: - return get_common_parameters_overriding_param - - @classmethod - def delete_common_parameters_overriding_param(cls) -> types.ModuleType: - return delete_common_parameters_overriding_param - @classmethod def get_same_name_multiple_locations_param(cls) -> types.ModuleType: return get_same_name_multiple_locations_param diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tag1/__init__.py b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tag1/__init__.py index 556ca84e8..b91db35b0 100644 --- a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tag1/__init__.py +++ b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tag1/__init__.py @@ -2,7 +2,7 @@ import types -from . import get_tag_with_number +from my_test_api_client.api.tag1 import get_tag_with_number class Tag1Endpoints: diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tests/__init__.py b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tests/__init__.py index 8fc547a66..28a4f10c1 100644 --- a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tests/__init__.py +++ b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tests/__init__.py @@ -2,7 +2,7 @@ import types -from . import ( +from my_test_api_client.api.tests import ( defaults_tests_defaults_post, get_basic_list_of_booleans, get_basic_list_of_floats, diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py index cdf259e7f..f22ec0153 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py @@ -14,114 +14,112 @@ def _get_kwargs( *, client: Client, - string_prop_query: Union[Unset, str] = "the default string", - not_required_not_nullable_datetime_prop_query: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), - not_required_nullable_datetime_prop_query: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), - required_not_nullable_datetime_prop_query: datetime.datetime = isoparse("1010-10-10T00:00:00"), - required_nullable_datetime_prop_query: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), - date_prop_query: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), - float_prop_query: Union[Unset, float] = 3.14, - int_prop_query: Union[Unset, int] = 7, - boolean_prop_query: Union[Unset, bool] = False, - list_prop_query: Union[Unset, List[AnEnum]] = UNSET, - union_prop_query: Union[Unset, float, str] = "not a float", - union_prop_with_ref_query: Union[AnEnum, Unset, float] = 0.6, - enum_prop_query: Union[Unset, AnEnum] = UNSET, - model_prop_query: Union[Unset, ModelWithUnionProperty] = UNSET, - required_model_prop_query: ModelWithUnionProperty, - nullable_model_prop_query: Union[Unset, None, ModelWithUnionProperty] = UNSET, - nullable_required_model_prop_query: Optional[ModelWithUnionProperty], + string_prop: Union[Unset, str] = "the default string", + not_required_not_nullable_datetime_prop: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), + not_required_nullable_datetime_prop: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), + required_not_nullable_datetime_prop: datetime.datetime = isoparse("1010-10-10T00:00:00"), + required_nullable_datetime_prop: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), + date_prop: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), + float_prop: Union[Unset, float] = 3.14, + int_prop: Union[Unset, int] = 7, + boolean_prop: Union[Unset, bool] = False, + list_prop: Union[Unset, List[AnEnum]] = UNSET, + union_prop: Union[Unset, float, str] = "not a float", + union_prop_with_ref: Union[AnEnum, Unset, float] = 0.6, + enum_prop: Union[Unset, AnEnum] = UNSET, + model_prop: Union[Unset, ModelWithUnionProperty] = UNSET, + required_model_prop: ModelWithUnionProperty, + nullable_model_prop: Union[Unset, None, ModelWithUnionProperty] = UNSET, + nullable_required_model_prop: Optional[ModelWithUnionProperty], ) -> Dict[str, Any]: url = "{}/tests/defaults".format(client.base_url) headers: Dict[str, Any] = client.get_headers() cookies: Dict[str, Any] = client.get_cookies() - json_not_required_not_nullable_datetime_prop_query: Union[Unset, str] = UNSET - if not isinstance(not_required_not_nullable_datetime_prop_query, Unset): - json_not_required_not_nullable_datetime_prop_query = not_required_not_nullable_datetime_prop_query.isoformat() + json_not_required_not_nullable_datetime_prop: Union[Unset, str] = UNSET + if not isinstance(not_required_not_nullable_datetime_prop, Unset): + json_not_required_not_nullable_datetime_prop = not_required_not_nullable_datetime_prop.isoformat() - json_not_required_nullable_datetime_prop_query: Union[Unset, None, str] = UNSET - if not isinstance(not_required_nullable_datetime_prop_query, Unset): - json_not_required_nullable_datetime_prop_query = ( - not_required_nullable_datetime_prop_query.isoformat() if not_required_nullable_datetime_prop_query else None + json_not_required_nullable_datetime_prop: Union[Unset, None, str] = UNSET + if not isinstance(not_required_nullable_datetime_prop, Unset): + json_not_required_nullable_datetime_prop = ( + not_required_nullable_datetime_prop.isoformat() if not_required_nullable_datetime_prop else None ) - json_required_not_nullable_datetime_prop_query = required_not_nullable_datetime_prop_query.isoformat() + json_required_not_nullable_datetime_prop = required_not_nullable_datetime_prop.isoformat() - json_required_nullable_datetime_prop_query = ( - required_nullable_datetime_prop_query.isoformat() if required_nullable_datetime_prop_query else None + json_required_nullable_datetime_prop = ( + required_nullable_datetime_prop.isoformat() if required_nullable_datetime_prop else None ) - json_date_prop_query: Union[Unset, str] = UNSET - if not isinstance(date_prop_query, Unset): - json_date_prop_query = date_prop_query.isoformat() + json_date_prop: Union[Unset, str] = UNSET + if not isinstance(date_prop, Unset): + json_date_prop = date_prop.isoformat() - json_list_prop_query: Union[Unset, List[str]] = UNSET - if not isinstance(list_prop_query, Unset): - json_list_prop_query = [] - for list_prop_item_data in list_prop_query: + json_list_prop: Union[Unset, List[str]] = UNSET + if not isinstance(list_prop, Unset): + json_list_prop = [] + for list_prop_item_data in list_prop: list_prop_item = list_prop_item_data.value - json_list_prop_query.append(list_prop_item) + json_list_prop.append(list_prop_item) - json_union_prop_query: Union[Unset, float, str] - if isinstance(union_prop_query, Unset): - json_union_prop_query = UNSET + json_union_prop: Union[Unset, float, str] + if isinstance(union_prop, Unset): + json_union_prop = UNSET else: - json_union_prop_query = union_prop_query + json_union_prop = union_prop - json_union_prop_with_ref_query: Union[Unset, float, str] - if isinstance(union_prop_with_ref_query, Unset): - json_union_prop_with_ref_query = UNSET - elif isinstance(union_prop_with_ref_query, AnEnum): - json_union_prop_with_ref_query = UNSET - if not isinstance(union_prop_with_ref_query, Unset): - json_union_prop_with_ref_query = union_prop_with_ref_query.value + json_union_prop_with_ref: Union[Unset, float, str] + if isinstance(union_prop_with_ref, Unset): + json_union_prop_with_ref = UNSET + elif isinstance(union_prop_with_ref, AnEnum): + json_union_prop_with_ref = UNSET + if not isinstance(union_prop_with_ref, Unset): + json_union_prop_with_ref = union_prop_with_ref.value else: - json_union_prop_with_ref_query = union_prop_with_ref_query + json_union_prop_with_ref = union_prop_with_ref - json_enum_prop_query: Union[Unset, str] = UNSET - if not isinstance(enum_prop_query, Unset): - json_enum_prop_query = enum_prop_query.value + json_enum_prop: Union[Unset, str] = UNSET + if not isinstance(enum_prop, Unset): + json_enum_prop = enum_prop.value - json_model_prop_query: Union[Unset, Dict[str, Any]] = UNSET - if not isinstance(model_prop_query, Unset): - json_model_prop_query = model_prop_query.to_dict() + json_model_prop: Union[Unset, Dict[str, Any]] = UNSET + if not isinstance(model_prop, Unset): + json_model_prop = model_prop.to_dict() - json_required_model_prop_query = required_model_prop_query.to_dict() + json_required_model_prop = required_model_prop.to_dict() - json_nullable_model_prop_query: Union[Unset, None, Dict[str, Any]] = UNSET - if not isinstance(nullable_model_prop_query, Unset): - json_nullable_model_prop_query = nullable_model_prop_query.to_dict() if nullable_model_prop_query else None + json_nullable_model_prop: Union[Unset, None, Dict[str, Any]] = UNSET + if not isinstance(nullable_model_prop, Unset): + json_nullable_model_prop = nullable_model_prop.to_dict() if nullable_model_prop else None - json_nullable_required_model_prop_query = ( - nullable_required_model_prop_query.to_dict() if nullable_required_model_prop_query else None - ) + json_nullable_required_model_prop = nullable_required_model_prop.to_dict() if nullable_required_model_prop else None params: Dict[str, Any] = { - "string_prop": string_prop_query, - "not_required_not_nullable_datetime_prop": json_not_required_not_nullable_datetime_prop_query, - "not_required_nullable_datetime_prop": json_not_required_nullable_datetime_prop_query, - "required_not_nullable_datetime_prop": json_required_not_nullable_datetime_prop_query, - "required_nullable_datetime_prop": json_required_nullable_datetime_prop_query, - "date_prop": json_date_prop_query, - "float_prop": float_prop_query, - "int_prop": int_prop_query, - "boolean_prop": boolean_prop_query, - "list_prop": json_list_prop_query, - "union_prop": json_union_prop_query, - "union_prop_with_ref": json_union_prop_with_ref_query, - "enum_prop": json_enum_prop_query, + "string_prop": string_prop, + "not_required_not_nullable_datetime_prop": json_not_required_not_nullable_datetime_prop, + "not_required_nullable_datetime_prop": json_not_required_nullable_datetime_prop, + "required_not_nullable_datetime_prop": json_required_not_nullable_datetime_prop, + "required_nullable_datetime_prop": json_required_nullable_datetime_prop, + "date_prop": json_date_prop, + "float_prop": float_prop, + "int_prop": int_prop, + "boolean_prop": boolean_prop, + "list_prop": json_list_prop, + "union_prop": json_union_prop, + "union_prop_with_ref": json_union_prop_with_ref, + "enum_prop": json_enum_prop, } - if not isinstance(json_model_prop_query, Unset): - params.update(json_model_prop_query) - params.update(json_required_model_prop_query) - if not isinstance(json_nullable_model_prop_query, Unset) and json_nullable_model_prop_query is not None: - params.update(json_nullable_model_prop_query) - if json_nullable_required_model_prop_query is not None: - params.update(json_nullable_required_model_prop_query) + if not isinstance(json_model_prop, Unset): + params.update(json_model_prop) + params.update(json_required_model_prop) + if not isinstance(json_nullable_model_prop, Unset) and json_nullable_model_prop is not None: + params.update(json_nullable_model_prop) + if json_nullable_required_model_prop is not None: + params.update(json_nullable_required_model_prop) params = {k: v for k, v in params.items() if v is not UNSET and v is not None} return { @@ -157,43 +155,43 @@ def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPVali def sync_detailed( *, client: Client, - string_prop_query: Union[Unset, str] = "the default string", - not_required_not_nullable_datetime_prop_query: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), - not_required_nullable_datetime_prop_query: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), - required_not_nullable_datetime_prop_query: datetime.datetime = isoparse("1010-10-10T00:00:00"), - required_nullable_datetime_prop_query: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), - date_prop_query: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), - float_prop_query: Union[Unset, float] = 3.14, - int_prop_query: Union[Unset, int] = 7, - boolean_prop_query: Union[Unset, bool] = False, - list_prop_query: Union[Unset, List[AnEnum]] = UNSET, - union_prop_query: Union[Unset, float, str] = "not a float", - union_prop_with_ref_query: Union[AnEnum, Unset, float] = 0.6, - enum_prop_query: Union[Unset, AnEnum] = UNSET, - model_prop_query: Union[Unset, ModelWithUnionProperty] = UNSET, - required_model_prop_query: ModelWithUnionProperty, - nullable_model_prop_query: Union[Unset, None, ModelWithUnionProperty] = UNSET, - nullable_required_model_prop_query: Optional[ModelWithUnionProperty], + string_prop: Union[Unset, str] = "the default string", + not_required_not_nullable_datetime_prop: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), + not_required_nullable_datetime_prop: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), + required_not_nullable_datetime_prop: datetime.datetime = isoparse("1010-10-10T00:00:00"), + required_nullable_datetime_prop: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), + date_prop: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), + float_prop: Union[Unset, float] = 3.14, + int_prop: Union[Unset, int] = 7, + boolean_prop: Union[Unset, bool] = False, + list_prop: Union[Unset, List[AnEnum]] = UNSET, + union_prop: Union[Unset, float, str] = "not a float", + union_prop_with_ref: Union[AnEnum, Unset, float] = 0.6, + enum_prop: Union[Unset, AnEnum] = UNSET, + model_prop: Union[Unset, ModelWithUnionProperty] = UNSET, + required_model_prop: ModelWithUnionProperty, + nullable_model_prop: Union[Unset, None, ModelWithUnionProperty] = UNSET, + nullable_required_model_prop: Optional[ModelWithUnionProperty], ) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, - string_prop_query=string_prop_query, - not_required_not_nullable_datetime_prop_query=not_required_not_nullable_datetime_prop_query, - not_required_nullable_datetime_prop_query=not_required_nullable_datetime_prop_query, - required_not_nullable_datetime_prop_query=required_not_nullable_datetime_prop_query, - required_nullable_datetime_prop_query=required_nullable_datetime_prop_query, - date_prop_query=date_prop_query, - float_prop_query=float_prop_query, - int_prop_query=int_prop_query, - boolean_prop_query=boolean_prop_query, - list_prop_query=list_prop_query, - union_prop_query=union_prop_query, - union_prop_with_ref_query=union_prop_with_ref_query, - enum_prop_query=enum_prop_query, - model_prop_query=model_prop_query, - required_model_prop_query=required_model_prop_query, - nullable_model_prop_query=nullable_model_prop_query, - nullable_required_model_prop_query=nullable_required_model_prop_query, + string_prop=string_prop, + not_required_not_nullable_datetime_prop=not_required_not_nullable_datetime_prop, + not_required_nullable_datetime_prop=not_required_nullable_datetime_prop, + required_not_nullable_datetime_prop=required_not_nullable_datetime_prop, + required_nullable_datetime_prop=required_nullable_datetime_prop, + date_prop=date_prop, + float_prop=float_prop, + int_prop=int_prop, + boolean_prop=boolean_prop, + list_prop=list_prop, + union_prop=union_prop, + union_prop_with_ref=union_prop_with_ref, + enum_prop=enum_prop, + model_prop=model_prop, + required_model_prop=required_model_prop, + nullable_model_prop=nullable_model_prop, + nullable_required_model_prop=nullable_required_model_prop, ) response = httpx.post( @@ -206,88 +204,88 @@ def sync_detailed( def sync( *, client: Client, - string_prop_query: Union[Unset, str] = "the default string", - not_required_not_nullable_datetime_prop_query: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), - not_required_nullable_datetime_prop_query: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), - required_not_nullable_datetime_prop_query: datetime.datetime = isoparse("1010-10-10T00:00:00"), - required_nullable_datetime_prop_query: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), - date_prop_query: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), - float_prop_query: Union[Unset, float] = 3.14, - int_prop_query: Union[Unset, int] = 7, - boolean_prop_query: Union[Unset, bool] = False, - list_prop_query: Union[Unset, List[AnEnum]] = UNSET, - union_prop_query: Union[Unset, float, str] = "not a float", - union_prop_with_ref_query: Union[AnEnum, Unset, float] = 0.6, - enum_prop_query: Union[Unset, AnEnum] = UNSET, - model_prop_query: Union[Unset, ModelWithUnionProperty] = UNSET, - required_model_prop_query: ModelWithUnionProperty, - nullable_model_prop_query: Union[Unset, None, ModelWithUnionProperty] = UNSET, - nullable_required_model_prop_query: Optional[ModelWithUnionProperty], + string_prop: Union[Unset, str] = "the default string", + not_required_not_nullable_datetime_prop: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), + not_required_nullable_datetime_prop: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), + required_not_nullable_datetime_prop: datetime.datetime = isoparse("1010-10-10T00:00:00"), + required_nullable_datetime_prop: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), + date_prop: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), + float_prop: Union[Unset, float] = 3.14, + int_prop: Union[Unset, int] = 7, + boolean_prop: Union[Unset, bool] = False, + list_prop: Union[Unset, List[AnEnum]] = UNSET, + union_prop: Union[Unset, float, str] = "not a float", + union_prop_with_ref: Union[AnEnum, Unset, float] = 0.6, + enum_prop: Union[Unset, AnEnum] = UNSET, + model_prop: Union[Unset, ModelWithUnionProperty] = UNSET, + required_model_prop: ModelWithUnionProperty, + nullable_model_prop: Union[Unset, None, ModelWithUnionProperty] = UNSET, + nullable_required_model_prop: Optional[ModelWithUnionProperty], ) -> Optional[Union[Any, HTTPValidationError]]: """ """ return sync_detailed( client=client, - string_prop_query=string_prop_query, - not_required_not_nullable_datetime_prop_query=not_required_not_nullable_datetime_prop_query, - not_required_nullable_datetime_prop_query=not_required_nullable_datetime_prop_query, - required_not_nullable_datetime_prop_query=required_not_nullable_datetime_prop_query, - required_nullable_datetime_prop_query=required_nullable_datetime_prop_query, - date_prop_query=date_prop_query, - float_prop_query=float_prop_query, - int_prop_query=int_prop_query, - boolean_prop_query=boolean_prop_query, - list_prop_query=list_prop_query, - union_prop_query=union_prop_query, - union_prop_with_ref_query=union_prop_with_ref_query, - enum_prop_query=enum_prop_query, - model_prop_query=model_prop_query, - required_model_prop_query=required_model_prop_query, - nullable_model_prop_query=nullable_model_prop_query, - nullable_required_model_prop_query=nullable_required_model_prop_query, + string_prop=string_prop, + not_required_not_nullable_datetime_prop=not_required_not_nullable_datetime_prop, + not_required_nullable_datetime_prop=not_required_nullable_datetime_prop, + required_not_nullable_datetime_prop=required_not_nullable_datetime_prop, + required_nullable_datetime_prop=required_nullable_datetime_prop, + date_prop=date_prop, + float_prop=float_prop, + int_prop=int_prop, + boolean_prop=boolean_prop, + list_prop=list_prop, + union_prop=union_prop, + union_prop_with_ref=union_prop_with_ref, + enum_prop=enum_prop, + model_prop=model_prop, + required_model_prop=required_model_prop, + nullable_model_prop=nullable_model_prop, + nullable_required_model_prop=nullable_required_model_prop, ).parsed async def asyncio_detailed( *, client: Client, - string_prop_query: Union[Unset, str] = "the default string", - not_required_not_nullable_datetime_prop_query: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), - not_required_nullable_datetime_prop_query: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), - required_not_nullable_datetime_prop_query: datetime.datetime = isoparse("1010-10-10T00:00:00"), - required_nullable_datetime_prop_query: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), - date_prop_query: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), - float_prop_query: Union[Unset, float] = 3.14, - int_prop_query: Union[Unset, int] = 7, - boolean_prop_query: Union[Unset, bool] = False, - list_prop_query: Union[Unset, List[AnEnum]] = UNSET, - union_prop_query: Union[Unset, float, str] = "not a float", - union_prop_with_ref_query: Union[AnEnum, Unset, float] = 0.6, - enum_prop_query: Union[Unset, AnEnum] = UNSET, - model_prop_query: Union[Unset, ModelWithUnionProperty] = UNSET, - required_model_prop_query: ModelWithUnionProperty, - nullable_model_prop_query: Union[Unset, None, ModelWithUnionProperty] = UNSET, - nullable_required_model_prop_query: Optional[ModelWithUnionProperty], + string_prop: Union[Unset, str] = "the default string", + not_required_not_nullable_datetime_prop: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), + not_required_nullable_datetime_prop: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), + required_not_nullable_datetime_prop: datetime.datetime = isoparse("1010-10-10T00:00:00"), + required_nullable_datetime_prop: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), + date_prop: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), + float_prop: Union[Unset, float] = 3.14, + int_prop: Union[Unset, int] = 7, + boolean_prop: Union[Unset, bool] = False, + list_prop: Union[Unset, List[AnEnum]] = UNSET, + union_prop: Union[Unset, float, str] = "not a float", + union_prop_with_ref: Union[AnEnum, Unset, float] = 0.6, + enum_prop: Union[Unset, AnEnum] = UNSET, + model_prop: Union[Unset, ModelWithUnionProperty] = UNSET, + required_model_prop: ModelWithUnionProperty, + nullable_model_prop: Union[Unset, None, ModelWithUnionProperty] = UNSET, + nullable_required_model_prop: Optional[ModelWithUnionProperty], ) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, - string_prop_query=string_prop_query, - not_required_not_nullable_datetime_prop_query=not_required_not_nullable_datetime_prop_query, - not_required_nullable_datetime_prop_query=not_required_nullable_datetime_prop_query, - required_not_nullable_datetime_prop_query=required_not_nullable_datetime_prop_query, - required_nullable_datetime_prop_query=required_nullable_datetime_prop_query, - date_prop_query=date_prop_query, - float_prop_query=float_prop_query, - int_prop_query=int_prop_query, - boolean_prop_query=boolean_prop_query, - list_prop_query=list_prop_query, - union_prop_query=union_prop_query, - union_prop_with_ref_query=union_prop_with_ref_query, - enum_prop_query=enum_prop_query, - model_prop_query=model_prop_query, - required_model_prop_query=required_model_prop_query, - nullable_model_prop_query=nullable_model_prop_query, - nullable_required_model_prop_query=nullable_required_model_prop_query, + string_prop=string_prop, + not_required_not_nullable_datetime_prop=not_required_not_nullable_datetime_prop, + not_required_nullable_datetime_prop=not_required_nullable_datetime_prop, + required_not_nullable_datetime_prop=required_not_nullable_datetime_prop, + required_nullable_datetime_prop=required_nullable_datetime_prop, + date_prop=date_prop, + float_prop=float_prop, + int_prop=int_prop, + boolean_prop=boolean_prop, + list_prop=list_prop, + union_prop=union_prop, + union_prop_with_ref=union_prop_with_ref, + enum_prop=enum_prop, + model_prop=model_prop, + required_model_prop=required_model_prop, + nullable_model_prop=nullable_model_prop, + nullable_required_model_prop=nullable_required_model_prop, ) async with httpx.AsyncClient() as _client: @@ -299,45 +297,45 @@ async def asyncio_detailed( async def asyncio( *, client: Client, - string_prop_query: Union[Unset, str] = "the default string", - not_required_not_nullable_datetime_prop_query: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), - not_required_nullable_datetime_prop_query: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), - required_not_nullable_datetime_prop_query: datetime.datetime = isoparse("1010-10-10T00:00:00"), - required_nullable_datetime_prop_query: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), - date_prop_query: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), - float_prop_query: Union[Unset, float] = 3.14, - int_prop_query: Union[Unset, int] = 7, - boolean_prop_query: Union[Unset, bool] = False, - list_prop_query: Union[Unset, List[AnEnum]] = UNSET, - union_prop_query: Union[Unset, float, str] = "not a float", - union_prop_with_ref_query: Union[AnEnum, Unset, float] = 0.6, - enum_prop_query: Union[Unset, AnEnum] = UNSET, - model_prop_query: Union[Unset, ModelWithUnionProperty] = UNSET, - required_model_prop_query: ModelWithUnionProperty, - nullable_model_prop_query: Union[Unset, None, ModelWithUnionProperty] = UNSET, - nullable_required_model_prop_query: Optional[ModelWithUnionProperty], + string_prop: Union[Unset, str] = "the default string", + not_required_not_nullable_datetime_prop: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), + not_required_nullable_datetime_prop: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), + required_not_nullable_datetime_prop: datetime.datetime = isoparse("1010-10-10T00:00:00"), + required_nullable_datetime_prop: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), + date_prop: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), + float_prop: Union[Unset, float] = 3.14, + int_prop: Union[Unset, int] = 7, + boolean_prop: Union[Unset, bool] = False, + list_prop: Union[Unset, List[AnEnum]] = UNSET, + union_prop: Union[Unset, float, str] = "not a float", + union_prop_with_ref: Union[AnEnum, Unset, float] = 0.6, + enum_prop: Union[Unset, AnEnum] = UNSET, + model_prop: Union[Unset, ModelWithUnionProperty] = UNSET, + required_model_prop: ModelWithUnionProperty, + nullable_model_prop: Union[Unset, None, ModelWithUnionProperty] = UNSET, + nullable_required_model_prop: Optional[ModelWithUnionProperty], ) -> Optional[Union[Any, HTTPValidationError]]: """ """ return ( await asyncio_detailed( client=client, - string_prop_query=string_prop_query, - not_required_not_nullable_datetime_prop_query=not_required_not_nullable_datetime_prop_query, - not_required_nullable_datetime_prop_query=not_required_nullable_datetime_prop_query, - required_not_nullable_datetime_prop_query=required_not_nullable_datetime_prop_query, - required_nullable_datetime_prop_query=required_nullable_datetime_prop_query, - date_prop_query=date_prop_query, - float_prop_query=float_prop_query, - int_prop_query=int_prop_query, - boolean_prop_query=boolean_prop_query, - list_prop_query=list_prop_query, - union_prop_query=union_prop_query, - union_prop_with_ref_query=union_prop_with_ref_query, - enum_prop_query=enum_prop_query, - model_prop_query=model_prop_query, - required_model_prop_query=required_model_prop_query, - nullable_model_prop_query=nullable_model_prop_query, - nullable_required_model_prop_query=nullable_required_model_prop_query, + string_prop=string_prop, + not_required_not_nullable_datetime_prop=not_required_not_nullable_datetime_prop, + not_required_nullable_datetime_prop=not_required_nullable_datetime_prop, + required_not_nullable_datetime_prop=required_not_nullable_datetime_prop, + required_nullable_datetime_prop=required_nullable_datetime_prop, + date_prop=date_prop, + float_prop=float_prop, + int_prop=int_prop, + boolean_prop=boolean_prop, + list_prop=list_prop, + union_prop=union_prop, + union_prop_with_ref=union_prop_with_ref, + enum_prop=enum_prop, + model_prop=model_prop, + required_model_prop=required_model_prop, + nullable_model_prop=nullable_model_prop, + nullable_required_model_prop=nullable_required_model_prop, ) ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py index e8b9223ed..96ca18884 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py @@ -13,28 +13,28 @@ def _get_kwargs( *, client: Client, - an_enum_value_query: List[AnEnum], - some_date_query: Union[datetime.date, datetime.datetime], + an_enum_value: List[AnEnum], + some_date: Union[datetime.date, datetime.datetime], ) -> Dict[str, Any]: url = "{}/tests/".format(client.base_url) headers: Dict[str, Any] = client.get_headers() cookies: Dict[str, Any] = client.get_cookies() - json_an_enum_value_query = [] - for an_enum_value_item_data in an_enum_value_query: + json_an_enum_value = [] + for an_enum_value_item_data in an_enum_value: an_enum_value_item = an_enum_value_item_data.value - json_an_enum_value_query.append(an_enum_value_item) + json_an_enum_value.append(an_enum_value_item) - if isinstance(some_date_query, datetime.date): - json_some_date_query = some_date_query.isoformat() + if isinstance(some_date, datetime.date): + json_some_date = some_date.isoformat() else: - json_some_date_query = some_date_query.isoformat() + json_some_date = some_date.isoformat() params: Dict[str, Any] = { - "an_enum_value": json_an_enum_value_query, - "some_date": json_some_date_query, + "an_enum_value": json_an_enum_value, + "some_date": json_some_date, } params = {k: v for k, v in params.items() if v is not UNSET and v is not None} @@ -80,13 +80,13 @@ def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidatio def sync_detailed( *, client: Client, - an_enum_value_query: List[AnEnum], - some_date_query: Union[datetime.date, datetime.datetime], + an_enum_value: List[AnEnum], + some_date: Union[datetime.date, datetime.datetime], ) -> Response[Union[HTTPValidationError, List[AModel]]]: kwargs = _get_kwargs( client=client, - an_enum_value_query=an_enum_value_query, - some_date_query=some_date_query, + an_enum_value=an_enum_value, + some_date=some_date, ) response = httpx.get( @@ -99,28 +99,28 @@ def sync_detailed( def sync( *, client: Client, - an_enum_value_query: List[AnEnum], - some_date_query: Union[datetime.date, datetime.datetime], + an_enum_value: List[AnEnum], + some_date: Union[datetime.date, datetime.datetime], ) -> Optional[Union[HTTPValidationError, List[AModel]]]: """Get a list of things""" return sync_detailed( client=client, - an_enum_value_query=an_enum_value_query, - some_date_query=some_date_query, + an_enum_value=an_enum_value, + some_date=some_date, ).parsed async def asyncio_detailed( *, client: Client, - an_enum_value_query: List[AnEnum], - some_date_query: Union[datetime.date, datetime.datetime], + an_enum_value: List[AnEnum], + some_date: Union[datetime.date, datetime.datetime], ) -> Response[Union[HTTPValidationError, List[AModel]]]: kwargs = _get_kwargs( client=client, - an_enum_value_query=an_enum_value_query, - some_date_query=some_date_query, + an_enum_value=an_enum_value, + some_date=some_date, ) async with httpx.AsyncClient() as _client: @@ -132,15 +132,15 @@ async def asyncio_detailed( async def asyncio( *, client: Client, - an_enum_value_query: List[AnEnum], - some_date_query: Union[datetime.date, datetime.datetime], + an_enum_value: List[AnEnum], + some_date: Union[datetime.date, datetime.datetime], ) -> Optional[Union[HTTPValidationError, List[AModel]]]: """Get a list of things""" return ( await asyncio_detailed( client=client, - an_enum_value_query=an_enum_value_query, - some_date_query=some_date_query, + an_enum_value=an_enum_value, + some_date=some_date, ) ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py index 1c8f9465b..d295ddaab 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py @@ -11,17 +11,17 @@ def _get_kwargs( *, client: Client, - int_enum_query: AnIntEnum, + int_enum: AnIntEnum, ) -> Dict[str, Any]: url = "{}/tests/int_enum".format(client.base_url) headers: Dict[str, Any] = client.get_headers() cookies: Dict[str, Any] = client.get_cookies() - json_int_enum_query = int_enum_query.value + json_int_enum = int_enum.value params: Dict[str, Any] = { - "int_enum": json_int_enum_query, + "int_enum": json_int_enum, } params = {k: v for k, v in params.items() if v is not UNSET and v is not None} @@ -58,11 +58,11 @@ def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPVali def sync_detailed( *, client: Client, - int_enum_query: AnIntEnum, + int_enum: AnIntEnum, ) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, - int_enum_query=int_enum_query, + int_enum=int_enum, ) response = httpx.post( @@ -75,24 +75,24 @@ def sync_detailed( def sync( *, client: Client, - int_enum_query: AnIntEnum, + int_enum: AnIntEnum, ) -> Optional[Union[Any, HTTPValidationError]]: """ """ return sync_detailed( client=client, - int_enum_query=int_enum_query, + int_enum=int_enum, ).parsed async def asyncio_detailed( *, client: Client, - int_enum_query: AnIntEnum, + int_enum: AnIntEnum, ) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, - int_enum_query=int_enum_query, + int_enum=int_enum, ) async with httpx.AsyncClient() as _client: @@ -104,13 +104,13 @@ async def asyncio_detailed( async def asyncio( *, client: Client, - int_enum_query: AnIntEnum, + int_enum: AnIntEnum, ) -> Optional[Union[Any, HTTPValidationError]]: """ """ return ( await asyncio_detailed( client=client, - int_enum_query=int_enum_query, + int_enum=int_enum, ) ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py index a3b418775..eba1f9615 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py @@ -18,14 +18,14 @@ def _get_kwargs( headers: Dict[str, Any] = client.get_headers() cookies: Dict[str, Any] = client.get_cookies() - json_body.to_dict() + json_json_body = json_body.to_dict() return { "url": url, "headers": headers, "cookies": cookies, "timeout": client.get_timeout(), - "json": json_body, + "json": json_json_body, } diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py index f6b3f9846..370ba1d45 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py @@ -10,19 +10,19 @@ def _get_kwargs( *, client: Client, - query_param_query: Union[Unset, List[str]] = UNSET, + query_param: Union[Unset, List[str]] = UNSET, ) -> Dict[str, Any]: url = "{}/tests/optional_query_param/".format(client.base_url) headers: Dict[str, Any] = client.get_headers() cookies: Dict[str, Any] = client.get_cookies() - json_query_param_query: Union[Unset, List[str]] = UNSET - if not isinstance(query_param_query, Unset): - json_query_param_query = query_param_query + json_query_param: Union[Unset, List[str]] = UNSET + if not isinstance(query_param, Unset): + json_query_param = query_param params: Dict[str, Any] = { - "query_param": json_query_param_query, + "query_param": json_query_param, } params = {k: v for k, v in params.items() if v is not UNSET and v is not None} @@ -59,11 +59,11 @@ def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPVali def sync_detailed( *, client: Client, - query_param_query: Union[Unset, List[str]] = UNSET, + query_param: Union[Unset, List[str]] = UNSET, ) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, - query_param_query=query_param_query, + query_param=query_param, ) response = httpx.get( @@ -76,24 +76,24 @@ def sync_detailed( def sync( *, client: Client, - query_param_query: Union[Unset, List[str]] = UNSET, + query_param: Union[Unset, List[str]] = UNSET, ) -> Optional[Union[Any, HTTPValidationError]]: """Test optional query parameters""" return sync_detailed( client=client, - query_param_query=query_param_query, + query_param=query_param, ).parsed async def asyncio_detailed( *, client: Client, - query_param_query: Union[Unset, List[str]] = UNSET, + query_param: Union[Unset, List[str]] = UNSET, ) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, - query_param_query=query_param_query, + query_param=query_param, ) async with httpx.AsyncClient() as _client: @@ -105,13 +105,13 @@ async def asyncio_detailed( async def asyncio( *, client: Client, - query_param_query: Union[Unset, List[str]] = UNSET, + query_param: Union[Unset, List[str]] = UNSET, ) -> Optional[Union[Any, HTTPValidationError]]: """Test optional query parameters""" return ( await asyncio_detailed( client=client, - query_param_query=query_param_query, + query_param=query_param, ) ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py index 323472ce7..59d12f3d6 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py @@ -18,14 +18,14 @@ def _get_kwargs( headers: Dict[str, Any] = client.get_headers() cookies: Dict[str, Any] = client.get_cookies() - json_body.to_dict() + json_json_body = json_body.to_dict() return { "url": url, "headers": headers, "cookies": cookies, "timeout": client.get_timeout(), - "json": json_body, + "json": json_json_body, } diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py index c5bcbc084..90cf20b07 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py @@ -9,14 +9,14 @@ def _get_kwargs( *, client: Client, - my_token_cookie: str, + my_token: str, ) -> Dict[str, Any]: url = "{}/auth/token_with_cookie".format(client.base_url) headers: Dict[str, Any] = client.get_headers() cookies: Dict[str, Any] = client.get_cookies() - cookies["MyToken"] = my_token_cookie + cookies["MyToken"] = my_token return { "url": url, @@ -38,11 +38,11 @@ def _build_response(*, response: httpx.Response) -> Response[Any]: def sync_detailed( *, client: Client, - my_token_cookie: str, + my_token: str, ) -> Response[Any]: kwargs = _get_kwargs( client=client, - my_token_cookie=my_token_cookie, + my_token=my_token, ) response = httpx.get( @@ -55,11 +55,11 @@ def sync_detailed( async def asyncio_detailed( *, client: Client, - my_token_cookie: str, + my_token: str, ) -> Response[Any]: kwargs = _get_kwargs( client=client, - my_token_cookie=my_token_cookie, + my_token=my_token, ) async with httpx.AsyncClient() as _client: diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py index 9eb1b4e64..d72aaae4d 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py @@ -12,15 +12,15 @@ def _get_kwargs( *, client: Client, multipart_data: BodyUploadFileTestsUploadPost, - keep_alive_header: Union[Unset, bool] = UNSET, + keep_alive: Union[Unset, bool] = UNSET, ) -> Dict[str, Any]: url = "{}/tests/upload".format(client.base_url) headers: Dict[str, Any] = client.get_headers() cookies: Dict[str, Any] = client.get_cookies() - if keep_alive_header is not UNSET: - headers["keep-alive"] = keep_alive_header + if keep_alive is not UNSET: + headers["keep-alive"] = keep_alive multipart_multipart_data = multipart_data.to_multipart() @@ -58,12 +58,12 @@ def sync_detailed( *, client: Client, multipart_data: BodyUploadFileTestsUploadPost, - keep_alive_header: Union[Unset, bool] = UNSET, + keep_alive: Union[Unset, bool] = UNSET, ) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, multipart_data=multipart_data, - keep_alive_header=keep_alive_header, + keep_alive=keep_alive, ) response = httpx.post( @@ -77,14 +77,14 @@ def sync( *, client: Client, multipart_data: BodyUploadFileTestsUploadPost, - keep_alive_header: Union[Unset, bool] = UNSET, + keep_alive: Union[Unset, bool] = UNSET, ) -> Optional[Union[Any, HTTPValidationError]]: """Upload a file""" return sync_detailed( client=client, multipart_data=multipart_data, - keep_alive_header=keep_alive_header, + keep_alive=keep_alive, ).parsed @@ -92,12 +92,12 @@ async def asyncio_detailed( *, client: Client, multipart_data: BodyUploadFileTestsUploadPost, - keep_alive_header: Union[Unset, bool] = UNSET, + keep_alive: Union[Unset, bool] = UNSET, ) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, multipart_data=multipart_data, - keep_alive_header=keep_alive_header, + keep_alive=keep_alive, ) async with httpx.AsyncClient() as _client: @@ -110,7 +110,7 @@ async def asyncio( *, client: Client, multipart_data: BodyUploadFileTestsUploadPost, - keep_alive_header: Union[Unset, bool] = UNSET, + keep_alive: Union[Unset, bool] = UNSET, ) -> Optional[Union[Any, HTTPValidationError]]: """Upload a file""" @@ -118,6 +118,6 @@ async def asyncio( await asyncio_detailed( client=client, multipart_data=multipart_data, - keep_alive_header=keep_alive_header, + keep_alive=keep_alive, ) ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py index 21bbf43c9..e5e42d546 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py @@ -11,15 +11,15 @@ def _get_kwargs( *, client: Client, multipart_data: List[File], - keep_alive_header: Union[Unset, bool] = UNSET, + keep_alive: Union[Unset, bool] = UNSET, ) -> Dict[str, Any]: url = "{}/tests/upload/multiple".format(client.base_url) headers: Dict[str, Any] = client.get_headers() cookies: Dict[str, Any] = client.get_cookies() - if keep_alive_header is not UNSET: - headers["keep-alive"] = keep_alive_header + if keep_alive is not UNSET: + headers["keep-alive"] = keep_alive multipart_multipart_data = [] for multipart_data_item_data in multipart_data: @@ -61,12 +61,12 @@ def sync_detailed( *, client: Client, multipart_data: List[File], - keep_alive_header: Union[Unset, bool] = UNSET, + keep_alive: Union[Unset, bool] = UNSET, ) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, multipart_data=multipart_data, - keep_alive_header=keep_alive_header, + keep_alive=keep_alive, ) response = httpx.post( @@ -80,14 +80,14 @@ def sync( *, client: Client, multipart_data: List[File], - keep_alive_header: Union[Unset, bool] = UNSET, + keep_alive: Union[Unset, bool] = UNSET, ) -> Optional[Union[Any, HTTPValidationError]]: """Upload several files in the same request""" return sync_detailed( client=client, multipart_data=multipart_data, - keep_alive_header=keep_alive_header, + keep_alive=keep_alive, ).parsed @@ -95,12 +95,12 @@ async def asyncio_detailed( *, client: Client, multipart_data: List[File], - keep_alive_header: Union[Unset, bool] = UNSET, + keep_alive: Union[Unset, bool] = UNSET, ) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, multipart_data=multipart_data, - keep_alive_header=keep_alive_header, + keep_alive=keep_alive, ) async with httpx.AsyncClient() as _client: @@ -113,7 +113,7 @@ async def asyncio( *, client: Client, multipart_data: List[File], - keep_alive_header: Union[Unset, bool] = UNSET, + keep_alive: Union[Unset, bool] = UNSET, ) -> Optional[Union[Any, HTTPValidationError]]: """Upload several files in the same request""" @@ -121,6 +121,6 @@ async def asyncio( await asyncio_detailed( client=client, multipart_data=multipart_data, - keep_alive_header=keep_alive_header, + keep_alive=keep_alive, ) ).parsed From 5f171b349bd272dd6dfcbffc6319ce311356b3f5 Mon Sep 17 00:00:00 2001 From: mtovts Date: Fri, 30 Jul 2021 17:54:21 +0300 Subject: [PATCH 24/57] Return relative imports in e2e tests --- .../my_test_api_client/api/__init__.py | 8 ++++---- .../my_test_api_client/api/default/__init__.py | 2 +- .../my_test_api_client/api/parameters/__init__.py | 14 +++++++++++++- .../my_test_api_client/api/tag1/__init__.py | 2 +- .../my_test_api_client/api/tests/__init__.py | 2 +- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/__init__.py b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/__init__.py index e5f9a66ed..f516aefcf 100644 --- a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/__init__.py +++ b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/__init__.py @@ -2,10 +2,10 @@ from typing import Type -from my_test_api_client.api.default import DefaultEndpoints -from my_test_api_client.api.parameters import ParametersEndpoints -from my_test_api_client.api.tag1 import Tag1Endpoints -from my_test_api_client.api.tests import TestsEndpoints +from .default import DefaultEndpoints +from .parameters import ParametersEndpoints +from .tag1 import Tag1Endpoints +from .tests import TestsEndpoints class MyTestApiClientApi: diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/default/__init__.py b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/default/__init__.py index 4d0eb4fb5..a4580103f 100644 --- a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/default/__init__.py +++ b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/default/__init__.py @@ -2,7 +2,7 @@ import types -from my_test_api_client.api.default import get_common_parameters, post_common_parameters +from . import get_common_parameters, post_common_parameters class DefaultEndpoints: diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/parameters/__init__.py b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/parameters/__init__.py index b92c6d96b..0d34e1f2d 100644 --- a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/parameters/__init__.py +++ b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/parameters/__init__.py @@ -2,10 +2,22 @@ import types -from my_test_api_client.api.parameters import get_same_name_multiple_locations_param +from . import ( + delete_common_parameters_overriding_param, + get_common_parameters_overriding_param, + get_same_name_multiple_locations_param, +) class ParametersEndpoints: + @classmethod + def get_common_parameters_overriding_param(cls) -> types.ModuleType: + return get_common_parameters_overriding_param + + @classmethod + def delete_common_parameters_overriding_param(cls) -> types.ModuleType: + return delete_common_parameters_overriding_param + @classmethod def get_same_name_multiple_locations_param(cls) -> types.ModuleType: return get_same_name_multiple_locations_param diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tag1/__init__.py b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tag1/__init__.py index b91db35b0..556ca84e8 100644 --- a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tag1/__init__.py +++ b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tag1/__init__.py @@ -2,7 +2,7 @@ import types -from my_test_api_client.api.tag1 import get_tag_with_number +from . import get_tag_with_number class Tag1Endpoints: diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tests/__init__.py b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tests/__init__.py index 28a4f10c1..8fc547a66 100644 --- a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tests/__init__.py +++ b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tests/__init__.py @@ -2,7 +2,7 @@ import types -from my_test_api_client.api.tests import ( +from . import ( defaults_tests_defaults_post, get_basic_list_of_booleans, get_basic_list_of_floats, From 7990d9a3d35e726644c53ee545e232fd89eca8c4 Mon Sep 17 00:00:00 2001 From: mtovts Date: Fri, 30 Jul 2021 17:55:00 +0300 Subject: [PATCH 25/57] Return: `"json_" + endpoint.json_body.python_name` --- openapi_python_client/templates/endpoint_module.py.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi_python_client/templates/endpoint_module.py.jinja b/openapi_python_client/templates/endpoint_module.py.jinja index 221f117ad..ec4d123fc 100644 --- a/openapi_python_client/templates/endpoint_module.py.jinja +++ b/openapi_python_client/templates/endpoint_module.py.jinja @@ -47,7 +47,7 @@ def _get_kwargs( {% elif endpoint.multipart_body %} "files": {{ "multipart_" + endpoint.multipart_body.python_name }}, {% elif endpoint.json_body %} - "json": {{ endpoint.json_body.python_name }}, + "json": {{ "json_" + endpoint.json_body.python_name }}, {% endif %} {% if endpoint.query_parameters %} "params": params, From 2b089a4fd846abeac20ebedbf2cc03602f9c22a1 Mon Sep 17 00:00:00 2001 From: mtovts Date: Sat, 31 Jul 2021 20:32:56 +0300 Subject: [PATCH 26/57] fix property `python_name` in parameter overriding --- openapi_python_client/parser/openapi.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index 1b796bcf8..d4fde0ecc 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -280,7 +280,10 @@ def _add_parameters( return ParseError(detail=f"cannot parse parameter of endpoint {endpoint.name}", data=prop.data), schemas for location, parameters_dict in parameters_by_location.items(): - if prop.name in parameters_dict: + existing_prop: Optional[Property] = parameters_dict.get(prop.name) + same_location: bool = location == param.param_in + + if existing_prop and not same_location: existing_prop: Property = parameters_dict[prop.name] # Existing should be converted too for consistency endpoint.used_python_identifiers.remove(existing_prop.python_name) From 8d2344c8542fc36e769fee2c8ee371b1b2d8169c Mon Sep 17 00:00:00 2001 From: mtovts Date: Sat, 31 Jul 2021 20:40:26 +0300 Subject: [PATCH 27/57] remove unused --- openapi_python_client/parser/openapi.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index d4fde0ecc..3c44f8286 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -284,7 +284,6 @@ def _add_parameters( same_location: bool = location == param.param_in if existing_prop and not same_location: - existing_prop: Property = parameters_dict[prop.name] # Existing should be converted too for consistency endpoint.used_python_identifiers.remove(existing_prop.python_name) existing_prop.set_python_name(new_name=f"{existing_prop.name}_{location}", config=config) From cea8189ea70c67218966b13672a04694e28b1ee9 Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sat, 7 Aug 2021 23:52:50 +0300 Subject: [PATCH 28/57] Update openapi_python_client/templates/endpoint_macros.py.jinja Replace items() with values() Co-authored-by: Dylan Anthony <43723790+dbanty@users.noreply.github.com> --- openapi_python_client/templates/endpoint_macros.py.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi_python_client/templates/endpoint_macros.py.jinja b/openapi_python_client/templates/endpoint_macros.py.jinja index c16082bae..9f9603444 100644 --- a/openapi_python_client/templates/endpoint_macros.py.jinja +++ b/openapi_python_client/templates/endpoint_macros.py.jinja @@ -1,6 +1,6 @@ {% macro header_params(endpoint) %} {% if endpoint.header_parameters %} - {% for _, parameter in endpoint.header_parameters.items() %} + {% for parameter in endpoint.header_parameters.values() %} {% if parameter.required %} headers["{{ parameter.name | kebabcase}}"] = {{ parameter.python_name }} {% else %} From a0db74120e90b81c4897f6e80958d5329d18a806 Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sat, 7 Aug 2021 23:54:11 +0300 Subject: [PATCH 29/57] Update openapi_python_client/templates/endpoint_macros.py.jinja Replace items() with values() Co-authored-by: Dylan Anthony <43723790+dbanty@users.noreply.github.com> --- openapi_python_client/templates/endpoint_macros.py.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi_python_client/templates/endpoint_macros.py.jinja b/openapi_python_client/templates/endpoint_macros.py.jinja index 9f9603444..d024cf735 100644 --- a/openapi_python_client/templates/endpoint_macros.py.jinja +++ b/openapi_python_client/templates/endpoint_macros.py.jinja @@ -13,7 +13,7 @@ if {{ parameter.python_name }} is not UNSET: {% macro cookie_params(endpoint) %} {% if endpoint.cookie_parameters %} - {% for _, parameter in endpoint.cookie_parameters.items() %} + {% for parameter in endpoint.cookie_parameters.values() %} {% if parameter.required %} cookies["{{ parameter.name}}"] = {{ parameter.python_name }} {% else %} From c465bf38e16be2f85b7600f623887382723abfd0 Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sat, 7 Aug 2021 23:54:25 +0300 Subject: [PATCH 30/57] Update openapi_python_client/templates/endpoint_macros.py.jinja Replace items() with values() Co-authored-by: Dylan Anthony <43723790+dbanty@users.noreply.github.com> --- openapi_python_client/templates/endpoint_macros.py.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi_python_client/templates/endpoint_macros.py.jinja b/openapi_python_client/templates/endpoint_macros.py.jinja index d024cf735..8f30f2ce8 100644 --- a/openapi_python_client/templates/endpoint_macros.py.jinja +++ b/openapi_python_client/templates/endpoint_macros.py.jinja @@ -27,7 +27,7 @@ if {{ parameter.python_name }} is not UNSET: {% macro query_params(endpoint) %} {% if endpoint.query_parameters %} - {% for _, property in endpoint.query_parameters.items() %} + {% for property in endpoint.query_parameters.values() %} {% set destination = "json_" + property.python_name %} {% if property.template %} {% from "property_templates/" + property.template import transform %} From 94998d18f4097ba2f7ee3775d9e28b1e08d41f3e Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sat, 7 Aug 2021 23:54:36 +0300 Subject: [PATCH 31/57] Update openapi_python_client/templates/endpoint_macros.py.jinja Replace items() with values() Co-authored-by: Dylan Anthony <43723790+dbanty@users.noreply.github.com> --- openapi_python_client/templates/endpoint_macros.py.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi_python_client/templates/endpoint_macros.py.jinja b/openapi_python_client/templates/endpoint_macros.py.jinja index 8f30f2ce8..38ade609d 100644 --- a/openapi_python_client/templates/endpoint_macros.py.jinja +++ b/openapi_python_client/templates/endpoint_macros.py.jinja @@ -141,7 +141,7 @@ json_body=json_body, {% for _, parameter in endpoint.header_parameters.items() %} {{ parameter.python_name }}={{ parameter.python_name }}, {% endfor %} -{% for _, parameter in endpoint.cookie_parameters.items() %} +{% for parameter in endpoint.cookie_parameters.values() %} {{ parameter.python_name }}={{ parameter.python_name }}, {% endfor %} {% endmacro %} From 7b82b4f0ce7a4df3b573d442fccf07e7d2698cb0 Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sat, 7 Aug 2021 23:54:47 +0300 Subject: [PATCH 32/57] Update openapi_python_client/templates/endpoint_module.py.jinja Replace items() with values() Co-authored-by: Dylan Anthony <43723790+dbanty@users.noreply.github.com> --- openapi_python_client/templates/endpoint_module.py.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi_python_client/templates/endpoint_module.py.jinja b/openapi_python_client/templates/endpoint_module.py.jinja index ec4d123fc..d347c0510 100644 --- a/openapi_python_client/templates/endpoint_module.py.jinja +++ b/openapi_python_client/templates/endpoint_module.py.jinja @@ -19,7 +19,7 @@ def _get_kwargs( ) -> Dict[str, Any]: url = "{}{{ endpoint.path }}".format( client.base_url - {%- for _, parameter in endpoint.path_parameters.items() -%} + {%- for parameter in endpoint.path_parameters.values() -%} ,{{parameter.name}}={{parameter.python_name}} {%- endfor -%} ) From db34f5f4e7b2fcae05c086adb9c1dd2b55a6a004 Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sat, 7 Aug 2021 23:57:51 +0300 Subject: [PATCH 33/57] Fix `test_validation_error_when_location_not_supported` Co-authored-by: Dylan Anthony <43723790+dbanty@users.noreply.github.com> --- tests/test_parser/test_openapi.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/test_parser/test_openapi.py b/tests/test_parser/test_openapi.py index ea3a8a596..bb48b569e 100644 --- a/tests/test_parser/test_openapi.py +++ b/tests/test_parser/test_openapi.py @@ -531,12 +531,10 @@ def test__add_parameters_parse_error(self, mocker): def test_validation_error_when_location_not_supported(self, mocker): parsed_schemas = mocker.MagicMock() mocker.patch(f"{MODULE_NAME}.property_from_data", return_value=(mocker.MagicMock(), parsed_schemas)) - try: - oai.Parameter.construct( + with pytest.raises(pydantic.ValidationError): + oai.Parameter( name="test", required=True, param_schema=mocker.MagicMock(), param_in="error_location" ) - except Exception as e: - assert e is pydantic.ValidationError def test__add_parameters_happy(self, mocker): from openapi_python_client.parser.openapi import Endpoint From 4e4ebbaa17ed61486d8ead87c3041eb7d48f0dac Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sun, 8 Aug 2021 00:00:48 +0300 Subject: [PATCH 34/57] Update openapi_python_client/templates/endpoint_macros.py.jinja Replace dict.items() with dict.values() Co-authored-by: Dylan Anthony <43723790+dbanty@users.noreply.github.com> --- openapi_python_client/templates/endpoint_macros.py.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi_python_client/templates/endpoint_macros.py.jinja b/openapi_python_client/templates/endpoint_macros.py.jinja index 38ade609d..3c5ec4648 100644 --- a/openapi_python_client/templates/endpoint_macros.py.jinja +++ b/openapi_python_client/templates/endpoint_macros.py.jinja @@ -35,7 +35,7 @@ if {{ parameter.python_name }} is not UNSET: {% endif %} {% endfor %} params: Dict[str, Any] = { - {% for _, property in endpoint.query_parameters.items() %} + {% for property in endpoint.query_parameters.values() %} {% if not property.json_is_dict %} {% if property.template %} "{{ property.name }}": {{ "json_" + property.python_name }}, From 55ab74f43785114f134a04fa211dfb2ffdd5307d Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sun, 8 Aug 2021 00:01:08 +0300 Subject: [PATCH 35/57] Update openapi_python_client/templates/endpoint_macros.py.jinja Replace dict.items() with dict.values() Co-authored-by: Dylan Anthony <43723790+dbanty@users.noreply.github.com> --- openapi_python_client/templates/endpoint_macros.py.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi_python_client/templates/endpoint_macros.py.jinja b/openapi_python_client/templates/endpoint_macros.py.jinja index 3c5ec4648..ef0769b79 100644 --- a/openapi_python_client/templates/endpoint_macros.py.jinja +++ b/openapi_python_client/templates/endpoint_macros.py.jinja @@ -92,7 +92,7 @@ client: AuthenticatedClient, client: Client, {% endif %} {# path parameters #} -{% for _, parameter in endpoint.path_parameters.items() %} +{% for parameter in endpoint.path_parameters.values() %} {{ parameter.to_string() }}, {% endfor %} {# Form data if any #} From 6029c939dd0d46cc239ef52d1f83de6cf0fd0c57 Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sun, 8 Aug 2021 00:01:26 +0300 Subject: [PATCH 36/57] Update openapi_python_client/templates/endpoint_macros.py.jinja Replace dict.items() with dict.values() Co-authored-by: Dylan Anthony <43723790+dbanty@users.noreply.github.com> --- openapi_python_client/templates/endpoint_macros.py.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi_python_client/templates/endpoint_macros.py.jinja b/openapi_python_client/templates/endpoint_macros.py.jinja index ef0769b79..edaaf51ae 100644 --- a/openapi_python_client/templates/endpoint_macros.py.jinja +++ b/openapi_python_client/templates/endpoint_macros.py.jinja @@ -45,7 +45,7 @@ params: Dict[str, Any] = { {% endif %} {% endfor %} } - {% for _, property in endpoint.query_parameters.items() %} + {% for property in endpoint.query_parameters.values() %} {% if property.json_is_dict %} {% set property_name = "json_" + property.python_name %} {% if property.required and not property.nullable %} From 9dacd140382e1b124a97c0f0a315ac73b1b06568 Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sun, 8 Aug 2021 00:03:33 +0300 Subject: [PATCH 37/57] Update openapi_python_client/templates/endpoint_macros.py.jinja Replace dict.items() with dict.values() Co-authored-by: Dylan Anthony <43723790+dbanty@users.noreply.github.com> --- openapi_python_client/templates/endpoint_macros.py.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi_python_client/templates/endpoint_macros.py.jinja b/openapi_python_client/templates/endpoint_macros.py.jinja index edaaf51ae..7f6a75499 100644 --- a/openapi_python_client/templates/endpoint_macros.py.jinja +++ b/openapi_python_client/templates/endpoint_macros.py.jinja @@ -138,7 +138,7 @@ json_body=json_body, {% for _, parameter in endpoint.query_parameters.items() %} {{ parameter.python_name }}={{ parameter.python_name }}, {% endfor %} -{% for _, parameter in endpoint.header_parameters.items() %} +{% for parameter in endpoint.header_parameters.values() %} {{ parameter.python_name }}={{ parameter.python_name }}, {% endfor %} {% for parameter in endpoint.cookie_parameters.values() %} From bc51af2d6151c997d5c3f362ac503ea9c5069d71 Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sun, 8 Aug 2021 00:04:45 +0300 Subject: [PATCH 38/57] Update openapi_python_client/templates/endpoint_macros.py.jinja Replace dict.items() with dict.values() Co-authored-by: Dylan Anthony <43723790+dbanty@users.noreply.github.com> --- openapi_python_client/templates/endpoint_macros.py.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi_python_client/templates/endpoint_macros.py.jinja b/openapi_python_client/templates/endpoint_macros.py.jinja index 7f6a75499..478d3a06e 100644 --- a/openapi_python_client/templates/endpoint_macros.py.jinja +++ b/openapi_python_client/templates/endpoint_macros.py.jinja @@ -108,7 +108,7 @@ multipart_data: {{ endpoint.multipart_body.get_type_string() }}, json_body: {{ endpoint.json_body.get_type_string() }}, {% endif %} {# query parameters #} -{% for _, parameter in endpoint.query_parameters.items() %} +{% for parameter in endpoint.query_parameters.values() %} {{ parameter.to_string() }}, {% endfor %} {% for _, parameter in endpoint.header_parameters.items() %} From fb4fcf260a72d215235138177a97a47d109a990b Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sun, 8 Aug 2021 00:05:03 +0300 Subject: [PATCH 39/57] Update openapi_python_client/templates/endpoint_macros.py.jinja Replace dict.items() with dict.values() Co-authored-by: Dylan Anthony <43723790+dbanty@users.noreply.github.com> --- openapi_python_client/templates/endpoint_macros.py.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi_python_client/templates/endpoint_macros.py.jinja b/openapi_python_client/templates/endpoint_macros.py.jinja index 478d3a06e..0862084f3 100644 --- a/openapi_python_client/templates/endpoint_macros.py.jinja +++ b/openapi_python_client/templates/endpoint_macros.py.jinja @@ -111,7 +111,7 @@ json_body: {{ endpoint.json_body.get_type_string() }}, {% for parameter in endpoint.query_parameters.values() %} {{ parameter.to_string() }}, {% endfor %} -{% for _, parameter in endpoint.header_parameters.items() %} +{% for parameter in endpoint.header_parameters.values() %} {{ parameter.to_string() }}, {% endfor %} {# cookie parameters #} From 200bd84558c650fb7f37d91525a46b45b6db1e99 Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sun, 8 Aug 2021 00:06:12 +0300 Subject: [PATCH 40/57] Update openapi_python_client/templates/endpoint_macros.py.jinja Replace dict.items() with dict.values() Co-authored-by: Dylan Anthony <43723790+dbanty@users.noreply.github.com> --- openapi_python_client/templates/endpoint_macros.py.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi_python_client/templates/endpoint_macros.py.jinja b/openapi_python_client/templates/endpoint_macros.py.jinja index 0862084f3..b18b6a069 100644 --- a/openapi_python_client/templates/endpoint_macros.py.jinja +++ b/openapi_python_client/templates/endpoint_macros.py.jinja @@ -115,7 +115,7 @@ json_body: {{ endpoint.json_body.get_type_string() }}, {{ parameter.to_string() }}, {% endfor %} {# cookie parameters #} -{% for _, parameter in endpoint.cookie_parameters.items() %} +{% for parameter in endpoint.cookie_parameters.values() %} {{ parameter.to_string() }}, {% endfor %} {% endmacro %} From 035c491605fed8e2958c9e5d5979ee087aeb69eb Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sun, 8 Aug 2021 00:06:38 +0300 Subject: [PATCH 41/57] Update openapi_python_client/templates/endpoint_macros.py.jinja Replace dict.items() with dict.values() Co-authored-by: Dylan Anthony <43723790+dbanty@users.noreply.github.com> --- openapi_python_client/templates/endpoint_macros.py.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi_python_client/templates/endpoint_macros.py.jinja b/openapi_python_client/templates/endpoint_macros.py.jinja index b18b6a069..6aedfea8a 100644 --- a/openapi_python_client/templates/endpoint_macros.py.jinja +++ b/openapi_python_client/templates/endpoint_macros.py.jinja @@ -135,7 +135,7 @@ multipart_data=multipart_data, {% if endpoint.json_body %} json_body=json_body, {% endif %} -{% for _, parameter in endpoint.query_parameters.items() %} +{% for parameter in endpoint.query_parameters.values() %} {{ parameter.python_name }}={{ parameter.python_name }}, {% endfor %} {% for parameter in endpoint.header_parameters.values() %} From d8c7cb388e3e26e6f0cb549fdb3e2437db507ac9 Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sun, 8 Aug 2021 00:06:53 +0300 Subject: [PATCH 42/57] Update openapi_python_client/templates/endpoint_macros.py.jinja Replace dict.items() with dict.values() Co-authored-by: Dylan Anthony <43723790+dbanty@users.noreply.github.com> --- openapi_python_client/templates/endpoint_macros.py.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi_python_client/templates/endpoint_macros.py.jinja b/openapi_python_client/templates/endpoint_macros.py.jinja index 6aedfea8a..3d5365bb0 100644 --- a/openapi_python_client/templates/endpoint_macros.py.jinja +++ b/openapi_python_client/templates/endpoint_macros.py.jinja @@ -123,7 +123,7 @@ json_body: {{ endpoint.json_body.get_type_string() }}, {# Just lists all kwargs to endpoints as name=name for passing to other functions #} {% macro kwargs(endpoint) %} client=client, -{% for _, parameter in endpoint.path_parameters.items() %} +{% for parameter in endpoint.path_parameters.values() %} {{ parameter.python_name }}={{ parameter.python_name }}, {% endfor %} {% if endpoint.form_body_class %} From 3e7fe110bff1190fc4030793dca7f88aa80453a5 Mon Sep 17 00:00:00 2001 From: mtovts Date: Mon, 9 Aug 2021 11:57:02 +0300 Subject: [PATCH 43/57] Fix `end_to_end_tests\openapi.json` --- end_to_end_tests/openapi.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/end_to_end_tests/openapi.json b/end_to_end_tests/openapi.json index af468054a..152351345 100644 --- a/end_to_end_tests/openapi.json +++ b/end_to_end_tests/openapi.json @@ -193,7 +193,7 @@ "tags": [ "tests" ], - "sumnary": "Post from data", + "summary": "Post from data", "description": "Post form data", "operationId": "post_form_data", "requestBody": { @@ -947,7 +947,7 @@ }, "/tag_with_number": { "get": { - "tags": [1], + "tags": ["1"], "responses": { "200": { "description": "Success" @@ -1453,7 +1453,7 @@ "type": "string" }, "type_enum": { - "type": "int", + "type": "integer", "enum": [0, 1] } } @@ -1470,7 +1470,7 @@ "enum": ["submodel"] }, "type_enum": { - "type": "int", + "type": "integer", "enum": [0] } } From b4cfa2e1b0e93080e1b38b0c2cbb0ccdfb3404cb Mon Sep 17 00:00:00 2001 From: mtovts Date: Mon, 9 Aug 2021 11:58:15 +0300 Subject: [PATCH 44/57] Add `/same_identifier_conflict/{param}/{param_path}` to `end_to_end_tests\openapi.json` --- end_to_end_tests/openapi.json | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/end_to_end_tests/openapi.json b/end_to_end_tests/openapi.json index 152351345..093752212 100644 --- a/end_to_end_tests/openapi.json +++ b/end_to_end_tests/openapi.json @@ -901,6 +901,44 @@ } ] }, + "/same_identifier_conflict/{param}/{param_path}": { + "description": "Test that if you have properties with the same Python identifier, it not produces code", + "get": { + "tags": [ + "parameters" + ], + "parameters": [ + { + "name": "param_path", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "param", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "param", + "in": "header", + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "" + } + } + } + }, "/same-name-multiple-locations/{param}": { "description": "Test that if you have a property of the same name in multiple locations, it produces valid code", "get": { From 08b54911fdf084485d4aae034fa8668006f66a88 Mon Sep 17 00:00:00 2001 From: mtovts Date: Mon, 9 Aug 2021 12:00:05 +0300 Subject: [PATCH 45/57] Lint `tests\test_parser\test_openapi.py` --- tests/test_parser/test_openapi.py | 58 +++++++++++++++++++------------ 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/tests/test_parser/test_openapi.py b/tests/test_parser/test_openapi.py index bb48b569e..d4b1e0674 100644 --- a/tests/test_parser/test_openapi.py +++ b/tests/test_parser/test_openapi.py @@ -532,47 +532,45 @@ def test_validation_error_when_location_not_supported(self, mocker): parsed_schemas = mocker.MagicMock() mocker.patch(f"{MODULE_NAME}.property_from_data", return_value=(mocker.MagicMock(), parsed_schemas)) with pytest.raises(pydantic.ValidationError): - oai.Parameter( - name="test", required=True, param_schema=mocker.MagicMock(), param_in="error_location" - ) + oai.Parameter(name="test", required=True, param_schema=mocker.MagicMock(), param_in="error_location") def test__add_parameters_happy(self, mocker): from openapi_python_client.parser.openapi import Endpoint from openapi_python_client.parser.properties import Property endpoint = self.make_endpoint() - path_prop_name = 'path_prop_name' + path_prop_name = "path_prop_name" path_prop = mocker.MagicMock(autospec=Property) path_prop_import = mocker.MagicMock() path_prop.get_imports = mocker.MagicMock(return_value={path_prop_import}) - path_prop.python_name = 'path_prop_name' + path_prop.python_name = "path_prop_name" - query_prop_name = 'query_prop_name' + query_prop_name = "query_prop_name" query_prop = mocker.MagicMock(autospec=Property) query_prop_import = mocker.MagicMock() query_prop.get_imports = mocker.MagicMock(return_value={query_prop_import}) - query_prop.python_name = 'query_prop_name' + query_prop.python_name = "query_prop_name" - header_prop_name = 'header_prop_name' + header_prop_name = "header_prop_name" header_prop_operation = mocker.MagicMock(autospec=Property) header_prop_operation.name = header_prop_name header_prop_operation.required = False header_prop_operation_import = mocker.MagicMock() header_prop_operation.get_imports = mocker.MagicMock(return_value={header_prop_operation_import}) - header_prop_operation.python_name = 'header_prop_name' + header_prop_operation.python_name = "header_prop_name" header_prop_path = mocker.MagicMock(autospec=Property) header_prop_path.name = header_prop_name header_prop_path.required = True header_prop_path_import = mocker.MagicMock() header_prop_path.get_imports = mocker.MagicMock(return_value={header_prop_path_import}) - header_prop_path.python_name = 'header_prop_name' + header_prop_path.python_name = "header_prop_name" - cookie_prop_name = 'cookie_prop_name' + cookie_prop_name = "cookie_prop_name" cookie_prop = mocker.MagicMock(autospec=Property) cookie_prop_import = mocker.MagicMock() cookie_prop.get_imports = mocker.MagicMock(return_value={cookie_prop_import}) - cookie_prop.python_name = 'cookie_prop_name' + cookie_prop.python_name = "cookie_prop_name" schemas_1 = mocker.MagicMock() schemas_2 = mocker.MagicMock() @@ -581,19 +579,23 @@ def test__add_parameters_happy(self, mocker): schemas_5 = mocker.MagicMock() property_from_data = mocker.patch( f"{MODULE_NAME}.property_from_data", - side_effect=[(path_prop, schemas_1), (query_prop, schemas_2), (header_prop_operation, schemas_3), (header_prop_path, schemas_4), (cookie_prop, schemas_5)], + side_effect=[ + (path_prop, schemas_1), + (query_prop, schemas_2), + (header_prop_operation, schemas_3), + (header_prop_path, schemas_4), + (cookie_prop, schemas_5), + ], ) path_schema = mocker.MagicMock() query_schema = mocker.MagicMock() header_operation_schema = mocker.MagicMock() cookie_schema = mocker.MagicMock() - header_path_schema = mocker.MagicMock() + header_pathitem_schema = mocker.MagicMock() operation_data = oai.Operation.construct( parameters=[ - oai.Parameter.construct( - name=path_prop_name, required=True, param_schema=path_schema, param_in="path" - ), + oai.Parameter.construct(name=path_prop_name, required=True, param_schema=path_schema, param_in="path"), oai.Parameter.construct( name=query_prop_name, required=False, param_schema=query_schema, param_in="query" ), @@ -613,7 +615,7 @@ def test__add_parameters_happy(self, mocker): path_item_data = oai.PathItem.construct( parameters=[ oai.Parameter.construct( - name=header_prop_name, required=True, param_schema=header_path_schema, param_in="header" + name=header_prop_name, required=True, param_schema=header_pathitem_schema, param_in="header" ), oai.Parameter.construct( name=cookie_prop_name, required=False, param_schema=cookie_schema, param_in="cookie" @@ -655,7 +657,7 @@ def test__add_parameters_happy(self, mocker): mocker.call( name=header_prop_name, required=True, - data=header_path_schema, + data=header_pathitem_schema, schemas=schemas_3, parent_name="name", config=config, @@ -675,7 +677,14 @@ def test__add_parameters_happy(self, mocker): header_prop_operation.get_imports.assert_called_once_with(prefix="...") cookie_prop.get_imports.assert_called_once_with(prefix="...") header_prop_path.get_imports.assert_called_once_with(prefix="...") - assert endpoint.relative_imports == {"import_3", path_prop_import, query_prop_import, header_prop_operation_import, cookie_prop_import, header_prop_path_import} + assert endpoint.relative_imports == { + "import_3", + path_prop_import, + query_prop_import, + header_prop_operation_import, + cookie_prop_import, + header_prop_path_import, + } assert endpoint.path_parameters == {path_prop.name: path_prop} assert endpoint.query_parameters == {query_prop.name: query_prop} assert endpoint.header_parameters == {header_prop_operation.name: header_prop_operation} @@ -696,9 +705,12 @@ def test__add_parameters_duplicate_properties(self, mocker): result = Endpoint._add_parameters(endpoint=endpoint, data=data, schemas=schemas, config=config) assert result == ( - ParseError(data=data, detail="Parameters MUST NOT duplicates. " - "A unique parameter is defined by a combination of a name and location. " - "Duplicated parameters named `test` detected in `path`."), + ParseError( + data=data, + detail="Parameters MUST NOT duplicates. " + "A unique parameter is defined by a combination of a name and location. " + "Duplicated parameters named `test` detected in `path`.", + ), schemas, ) From 578ddf239c4a7086fe1aaf566c18ac412fec911d Mon Sep 17 00:00:00 2001 From: mtovts Date: Mon, 9 Aug 2021 12:06:16 +0300 Subject: [PATCH 46/57] Add `test__add_parameters_with_location_postfix_conflict` --- tests/test_parser/test_openapi.py | 60 +++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/tests/test_parser/test_openapi.py b/tests/test_parser/test_openapi.py index d4b1e0674..e00b5c8a0 100644 --- a/tests/test_parser/test_openapi.py +++ b/tests/test_parser/test_openapi.py @@ -534,6 +534,66 @@ def test_validation_error_when_location_not_supported(self, mocker): with pytest.raises(pydantic.ValidationError): oai.Parameter(name="test", required=True, param_schema=mocker.MagicMock(), param_in="error_location") + def test__add_parameters_with_location_postfix_conflict(self, mocker): + from openapi_python_client.parser.openapi import Endpoint + from openapi_python_client.parser.properties import Property + + endpoint = self.make_endpoint() + path_prop_name_conflicted = "prop_name_path" + path_prop_conflicted = mocker.MagicMock(autospec=Property) + path_prop_conflicted_import = mocker.MagicMock() + path_prop_conflicted.get_imports = mocker.MagicMock(return_value={path_prop_conflicted_import}) + path_prop_conflicted.python_name = "prop_name_path" + + query_prop_name = "prop_name" + query_prop = mocker.MagicMock(autospec=Property) + query_prop_import = mocker.MagicMock() + query_prop.get_imports = mocker.MagicMock(return_value={query_prop_import}) + query_prop.python_name = "prop_name_query" + + path_prop_name = "prop_name" + path_prop = mocker.MagicMock(autospec=Property) + path_prop_import = mocker.MagicMock() + path_prop.get_imports = mocker.MagicMock(return_value={path_prop_import}) + path_prop.python_name = "prop_name_path" + + schemas_1 = mocker.MagicMock() + schemas_2 = mocker.MagicMock() + schemas_3 = mocker.MagicMock() + property_from_data = mocker.patch( + f"{MODULE_NAME}.property_from_data", + side_effect=[ + (path_prop_conflicted, schemas_1), + (query_prop, schemas_2), + (path_prop, schemas_3), + ], + ) + path_conflicted_schema = mocker.MagicMock() + query_schema = mocker.MagicMock() + path_schema = mocker.MagicMock() + + data = oai.Operation.construct( + parameters=[ + oai.Parameter.construct( + name=path_prop_name_conflicted, required=True, param_schema=path_conflicted_schema, param_in="path" + ), + oai.Parameter.construct( + name=query_prop_name, required=False, param_schema=query_schema, param_in="query" + ), + oai.Parameter.construct(name=path_prop_name, required=True, param_schema=path_schema, param_in="path"), + oai.Reference.construct(), # Should be ignored + oai.Parameter.construct(), # Should be ignored + ] + ) + initial_schemas = mocker.MagicMock() + config = MagicMock() + + result = Endpoint._add_parameters( + endpoint=endpoint, data=data, schemas=initial_schemas, config=config + )[0] + assert isinstance(result, ParseError) + assert result.detail == "Parameters with same Python identifier `prop_name_path` detected" + def test__add_parameters_happy(self, mocker): from openapi_python_client.parser.openapi import Endpoint from openapi_python_client.parser.properties import Property From 0c82680e9a8f185be627628691e522f3eb691aa3 Mon Sep 17 00:00:00 2001 From: mtovts Date: Mon, 9 Aug 2021 12:07:03 +0300 Subject: [PATCH 47/57] Add `used_python_identifiers` usage --- openapi_python_client/parser/openapi.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index 3c44f8286..dcbd0b400 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -287,13 +287,25 @@ def _add_parameters( # Existing should be converted too for consistency endpoint.used_python_identifiers.remove(existing_prop.python_name) existing_prop.set_python_name(new_name=f"{existing_prop.name}_{location}", config=config) - endpoint.used_python_identifiers.add(existing_prop.python_name) + if existing_prop.python_name in endpoint.used_python_identifiers: + return ( + ParseError(detail=f"Parameters with same Python identifier `{existing_prop.python_name}` detected", data=data), + schemas, + ) + endpoint.used_python_identifiers.add(existing_prop.python_name) prop.set_python_name(new_name=f"{param.name}_{param.param_in}", config=config) endpoint.relative_imports.update(prop.get_imports(prefix="...")) - parameters_by_location[param.param_in].setdefault(prop.name, prop) - endpoint.used_python_identifiers.add(prop.python_name) + + if prop.name not in parameters_by_location[param.param_in]: + if prop.python_name in endpoint.used_python_identifiers: + return ( + ParseError(detail=f"Parameters with same Python identifier `{prop.python_name}` detected", data=data), + schemas, + ) + endpoint.used_python_identifiers.add(prop.python_name) + parameters_by_location[param.param_in][prop.name] = prop return endpoint, schemas From 43774dde672a957cab42963a5c9fd6390fe3ef6c Mon Sep 17 00:00:00 2001 From: mtovts Date: Mon, 9 Aug 2021 12:11:31 +0300 Subject: [PATCH 48/57] Lint the code --- openapi_python_client/parser/openapi.py | 9 +++++++-- tests/test_parser/test_openapi.py | 4 +--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index dcbd0b400..579b6770e 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -290,7 +290,10 @@ def _add_parameters( if existing_prop.python_name in endpoint.used_python_identifiers: return ( - ParseError(detail=f"Parameters with same Python identifier `{existing_prop.python_name}` detected", data=data), + ParseError( + detail=f"Parameters with same Python identifier `{existing_prop.python_name}` detected", + data=data, + ), schemas, ) endpoint.used_python_identifiers.add(existing_prop.python_name) @@ -301,7 +304,9 @@ def _add_parameters( if prop.name not in parameters_by_location[param.param_in]: if prop.python_name in endpoint.used_python_identifiers: return ( - ParseError(detail=f"Parameters with same Python identifier `{prop.python_name}` detected", data=data), + ParseError( + detail=f"Parameters with same Python identifier `{prop.python_name}` detected", data=data + ), schemas, ) endpoint.used_python_identifiers.add(prop.python_name) diff --git a/tests/test_parser/test_openapi.py b/tests/test_parser/test_openapi.py index e00b5c8a0..68eef0e36 100644 --- a/tests/test_parser/test_openapi.py +++ b/tests/test_parser/test_openapi.py @@ -588,9 +588,7 @@ def test__add_parameters_with_location_postfix_conflict(self, mocker): initial_schemas = mocker.MagicMock() config = MagicMock() - result = Endpoint._add_parameters( - endpoint=endpoint, data=data, schemas=initial_schemas, config=config - )[0] + result = Endpoint._add_parameters(endpoint=endpoint, data=data, schemas=initial_schemas, config=config)[0] assert isinstance(result, ParseError) assert result.detail == "Parameters with same Python identifier `prop_name_path` detected" From d4a5cfdeb7eee6509a457005fd36f8b38eb854fe Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sat, 14 Aug 2021 21:29:06 +0300 Subject: [PATCH 49/57] Error message Co-authored-by: Dylan Anthony <43723790+dbanty@users.noreply.github.com> --- openapi_python_client/parser/openapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index 579b6770e..5d910df27 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -262,7 +262,7 @@ def _add_parameters( unique_param = (param.name, param.param_in) if unique_param in unique_parameters: duplication_detail = ( - "Parameters MUST NOT duplicates. A unique parameter is defined by a combination of a name and location. " + "Parameters MUST NOT contain duplicates. A unique parameter is defined by a combination of a name and location. " f"Duplicated parameters named `{param.name}` detected in `{param.param_in}`." ) return ParseError(data=data, detail=duplication_detail), schemas From 87debe10876e7e450e1a34d1f55f584010a3a77d Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sat, 14 Aug 2021 21:36:37 +0300 Subject: [PATCH 50/57] Refactor: skip `PathItem` parameter if `Operation` parameter exists Co-authored-by: Dylan Anthony <43723790+dbanty@users.noreply.github.com> --- openapi_python_client/parser/openapi.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index 5d910df27..4e308f634 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -278,7 +278,9 @@ def _add_parameters( ) if isinstance(prop, ParseError): return ParseError(detail=f"cannot parse parameter of endpoint {endpoint.name}", data=prop.data), schemas - +if prop.name in parameters_by_location[param.param_in]: + # This parameter was defined in the operation, so ignore the PathItem definition + continue for location, parameters_dict in parameters_by_location.items(): existing_prop: Optional[Property] = parameters_dict.get(prop.name) same_location: bool = location == param.param_in From 95b4fa4df025f79447c14a401abe0fb7af480275 Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sat, 14 Aug 2021 21:40:16 +0300 Subject: [PATCH 51/57] Refactor: simplify logic Co-authored-by: Dylan Anthony <43723790+dbanty@users.noreply.github.com> --- openapi_python_client/parser/openapi.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index 4e308f634..8e4476f17 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -282,10 +282,9 @@ def _add_parameters( # This parameter was defined in the operation, so ignore the PathItem definition continue for location, parameters_dict in parameters_by_location.items(): - existing_prop: Optional[Property] = parameters_dict.get(prop.name) - same_location: bool = location == param.param_in - - if existing_prop and not same_location: + if location == param.param_in or prop.name not in parameters_dict: + continue + existing_prop: Property = parameters_dict[prop.name] # Existing should be converted too for consistency endpoint.used_python_identifiers.remove(existing_prop.python_name) existing_prop.set_python_name(new_name=f"{existing_prop.name}_{location}", config=config) From 39ab05656f98a5c35350292597a421f02227bf31 Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sat, 14 Aug 2021 21:48:27 +0300 Subject: [PATCH 52/57] Fix spaces --- openapi_python_client/parser/openapi.py | 34 ++++++++++++------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index 8e4476f17..773866881 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -278,27 +278,27 @@ def _add_parameters( ) if isinstance(prop, ParseError): return ParseError(detail=f"cannot parse parameter of endpoint {endpoint.name}", data=prop.data), schemas -if prop.name in parameters_by_location[param.param_in]: - # This parameter was defined in the operation, so ignore the PathItem definition - continue + if prop.name in parameters_by_location[param.param_in]: + # This parameter was defined in the Operation, so ignore the PathItem definition + continue for location, parameters_dict in parameters_by_location.items(): if location == param.param_in or prop.name not in parameters_dict: continue existing_prop: Property = parameters_dict[prop.name] - # Existing should be converted too for consistency - endpoint.used_python_identifiers.remove(existing_prop.python_name) - existing_prop.set_python_name(new_name=f"{existing_prop.name}_{location}", config=config) - - if existing_prop.python_name in endpoint.used_python_identifiers: - return ( - ParseError( - detail=f"Parameters with same Python identifier `{existing_prop.python_name}` detected", - data=data, - ), - schemas, - ) - endpoint.used_python_identifiers.add(existing_prop.python_name) - prop.set_python_name(new_name=f"{param.name}_{param.param_in}", config=config) + # Existing should be converted too for consistency + endpoint.used_python_identifiers.remove(existing_prop.python_name) + existing_prop.set_python_name(new_name=f"{existing_prop.name}_{location}", config=config) + + if existing_prop.python_name in endpoint.used_python_identifiers: + return ( + ParseError( + detail=f"Parameters with same Python identifier `{existing_prop.python_name}` detected", + data=data, + ), + schemas, + ) + endpoint.used_python_identifiers.add(existing_prop.python_name) + prop.set_python_name(new_name=f"{param.name}_{param.param_in}", config=config) endpoint.relative_imports.update(prop.get_imports(prefix="...")) From 28b824b1d2485523ac99595655032ce7f2f5d680 Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sat, 14 Aug 2021 21:49:59 +0300 Subject: [PATCH 53/57] Fix tests --- tests/test_parser/test_openapi.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_parser/test_openapi.py b/tests/test_parser/test_openapi.py index 68eef0e36..012fe794d 100644 --- a/tests/test_parser/test_openapi.py +++ b/tests/test_parser/test_openapi.py @@ -734,14 +734,12 @@ def test__add_parameters_happy(self, mocker): query_prop.get_imports.assert_called_once_with(prefix="...") header_prop_operation.get_imports.assert_called_once_with(prefix="...") cookie_prop.get_imports.assert_called_once_with(prefix="...") - header_prop_path.get_imports.assert_called_once_with(prefix="...") assert endpoint.relative_imports == { "import_3", path_prop_import, query_prop_import, header_prop_operation_import, cookie_prop_import, - header_prop_path_import, } assert endpoint.path_parameters == {path_prop.name: path_prop} assert endpoint.query_parameters == {query_prop.name: query_prop} @@ -765,7 +763,7 @@ def test__add_parameters_duplicate_properties(self, mocker): assert result == ( ParseError( data=data, - detail="Parameters MUST NOT duplicates. " + detail="Parameters MUST NOT contain duplicates. " "A unique parameter is defined by a combination of a name and location. " "Duplicated parameters named `test` detected in `path`.", ), From d78d4b01ed61c5f4e695ee527e9d8ca97360a5b2 Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sat, 14 Aug 2021 22:07:22 +0300 Subject: [PATCH 54/57] make line-length < 120 --- openapi_python_client/parser/openapi.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index 773866881..274b58b72 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -262,7 +262,8 @@ def _add_parameters( unique_param = (param.name, param.param_in) if unique_param in unique_parameters: duplication_detail = ( - "Parameters MUST NOT contain duplicates. A unique parameter is defined by a combination of a name and location. " + "Parameters MUST NOT contain duplicates. " + "A unique parameter is defined by a combination of a name and location. " f"Duplicated parameters named `{param.name}` detected in `{param.param_in}`." ) return ParseError(data=data, detail=duplication_detail), schemas From a9736379bd50115ec2113c1c18964a2b289de1f9 Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sun, 15 Aug 2021 13:27:34 +0300 Subject: [PATCH 55/57] add test for existing parameter has a conflicting PythonIdentifier after renaming --- tests/test_parser/test_openapi.py | 50 ++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/tests/test_parser/test_openapi.py b/tests/test_parser/test_openapi.py index 012fe794d..23bc6f358 100644 --- a/tests/test_parser/test_openapi.py +++ b/tests/test_parser/test_openapi.py @@ -534,11 +534,13 @@ def test_validation_error_when_location_not_supported(self, mocker): with pytest.raises(pydantic.ValidationError): oai.Parameter(name="test", required=True, param_schema=mocker.MagicMock(), param_in="error_location") - def test__add_parameters_with_location_postfix_conflict(self, mocker): + def test__add_parameters_with_location_postfix_conflict1(self, mocker): + """Checks when the PythonIdentifier of new parameter already used""" from openapi_python_client.parser.openapi import Endpoint from openapi_python_client.parser.properties import Property endpoint = self.make_endpoint() + path_prop_name_conflicted = "prop_name_path" path_prop_conflicted = mocker.MagicMock(autospec=Property) path_prop_conflicted_import = mocker.MagicMock() @@ -592,6 +594,52 @@ def test__add_parameters_with_location_postfix_conflict(self, mocker): assert isinstance(result, ParseError) assert result.detail == "Parameters with same Python identifier `prop_name_path` detected" + def test__add_parameters_with_location_postfix_conflict2(self, mocker): + """Checks when an existing parameter has a conflicting PythonIdentifier after renaming.""" + from openapi_python_client.parser.openapi import Endpoint + from openapi_python_client.parser.properties import Property + + endpoint = self.make_endpoint() + path_prop_conflicted = Property( + name="prop_name_path", required=False, nullable=False, default=None, python_name="prop_name_path" + ) + path_prop = Property(name="prop_name", required=False, nullable=False, default=None, python_name="prop_name") + query_prop = Property(name="prop_name", required=False, nullable=False, default=None, python_name="prop_name") + schemas_1 = mocker.MagicMock() + schemas_2 = mocker.MagicMock() + schemas_3 = mocker.MagicMock() + property_from_data = mocker.patch( + f"{MODULE_NAME}.property_from_data", + side_effect=[ + (path_prop_conflicted, schemas_1), + (path_prop, schemas_2), + (query_prop, schemas_3), + ], + ) + path_conflicted_schema = mocker.MagicMock() + path_schema = mocker.MagicMock() + query_schema = mocker.MagicMock() + + data = oai.Operation.construct( + parameters=[ + oai.Parameter.construct( + name=path_prop_conflicted.name, required=True, param_schema=path_conflicted_schema, param_in="path" + ), + oai.Parameter.construct(name=path_prop.name, required=True, param_schema=path_schema, param_in="path"), + oai.Parameter.construct( + name=query_prop.name, required=False, param_schema=query_schema, param_in="query" + ), + oai.Reference.construct(), # Should be ignored + oai.Parameter.construct(), # Should be ignored + ] + ) + initial_schemas = mocker.MagicMock() + config = MagicMock() + + result = Endpoint._add_parameters(endpoint=endpoint, data=data, schemas=initial_schemas, config=config)[0] + assert isinstance(result, ParseError) + assert result.detail == "Parameters with same Python identifier `prop_name_path` detected" + def test__add_parameters_happy(self, mocker): from openapi_python_client.parser.openapi import Endpoint from openapi_python_client.parser.properties import Property From a4710257aaea674766662dbfc63d4682f49ac707 Mon Sep 17 00:00:00 2001 From: Matvey <38750524+mtovts@users.noreply.github.com> Date: Sun, 15 Aug 2021 13:31:55 +0300 Subject: [PATCH 56/57] Refactor test for PythonIdentifier of new parameter already used --- tests/test_parser/test_openapi.py | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/tests/test_parser/test_openapi.py b/tests/test_parser/test_openapi.py index 23bc6f358..c3b1fe289 100644 --- a/tests/test_parser/test_openapi.py +++ b/tests/test_parser/test_openapi.py @@ -535,29 +535,17 @@ def test_validation_error_when_location_not_supported(self, mocker): oai.Parameter(name="test", required=True, param_schema=mocker.MagicMock(), param_in="error_location") def test__add_parameters_with_location_postfix_conflict1(self, mocker): - """Checks when the PythonIdentifier of new parameter already used""" + """Checks when the PythonIdentifier of new parameter already used.""" from openapi_python_client.parser.openapi import Endpoint from openapi_python_client.parser.properties import Property endpoint = self.make_endpoint() - path_prop_name_conflicted = "prop_name_path" - path_prop_conflicted = mocker.MagicMock(autospec=Property) - path_prop_conflicted_import = mocker.MagicMock() - path_prop_conflicted.get_imports = mocker.MagicMock(return_value={path_prop_conflicted_import}) - path_prop_conflicted.python_name = "prop_name_path" - - query_prop_name = "prop_name" - query_prop = mocker.MagicMock(autospec=Property) - query_prop_import = mocker.MagicMock() - query_prop.get_imports = mocker.MagicMock(return_value={query_prop_import}) - query_prop.python_name = "prop_name_query" - - path_prop_name = "prop_name" - path_prop = mocker.MagicMock(autospec=Property) - path_prop_import = mocker.MagicMock() - path_prop.get_imports = mocker.MagicMock(return_value={path_prop_import}) - path_prop.python_name = "prop_name_path" + path_prop_conflicted = Property( + name="prop_name_path", required=False, nullable=False, default=None, python_name="prop_name_path" + ) + query_prop = Property(name="prop_name", required=False, nullable=False, default=None, python_name="prop_name") + path_prop = Property(name="prop_name", required=False, nullable=False, default=None, python_name="prop_name") schemas_1 = mocker.MagicMock() schemas_2 = mocker.MagicMock() @@ -577,12 +565,12 @@ def test__add_parameters_with_location_postfix_conflict1(self, mocker): data = oai.Operation.construct( parameters=[ oai.Parameter.construct( - name=path_prop_name_conflicted, required=True, param_schema=path_conflicted_schema, param_in="path" + name=path_prop_conflicted.name, required=True, param_schema=path_conflicted_schema, param_in="path" ), oai.Parameter.construct( - name=query_prop_name, required=False, param_schema=query_schema, param_in="query" + name=query_prop.name, required=False, param_schema=query_schema, param_in="query" ), - oai.Parameter.construct(name=path_prop_name, required=True, param_schema=path_schema, param_in="path"), + oai.Parameter.construct(name=path_prop.name, required=True, param_schema=path_schema, param_in="path"), oai.Reference.construct(), # Should be ignored oai.Parameter.construct(), # Should be ignored ] From ca7c30f37de85b2e96ae81583dec3b620d520ce7 Mon Sep 17 00:00:00 2001 From: Dylan Anthony <43723790+dbanty@users.noreply.github.com> Date: Sun, 15 Aug 2021 10:23:35 -0600 Subject: [PATCH 57/57] refactor: Remove unneeded check --- openapi_python_client/parser/openapi.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index 274b58b72..3d143224a 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -303,16 +303,15 @@ def _add_parameters( endpoint.relative_imports.update(prop.get_imports(prefix="...")) - if prop.name not in parameters_by_location[param.param_in]: - if prop.python_name in endpoint.used_python_identifiers: - return ( - ParseError( - detail=f"Parameters with same Python identifier `{prop.python_name}` detected", data=data - ), - schemas, - ) - endpoint.used_python_identifiers.add(prop.python_name) - parameters_by_location[param.param_in][prop.name] = prop + if prop.python_name in endpoint.used_python_identifiers: + return ( + ParseError( + detail=f"Parameters with same Python identifier `{prop.python_name}` detected", data=data + ), + schemas, + ) + endpoint.used_python_identifiers.add(prop.python_name) + parameters_by_location[param.param_in][prop.name] = prop return endpoint, schemas