diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/configuration.handlebars b/modules/openapi-json-schema-generator/src/main/resources/python/configuration.handlebars index 8837fa9515d..7e311be3bf4 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/configuration.handlebars +++ b/modules/openapi-json-schema-generator/src/main/resources/python/configuration.handlebars @@ -37,17 +37,6 @@ class Configuration(object): The dict value is an API key prefix when generating the auth data. :param username: Username for HTTP basic authentication :param password: Password for HTTP basic authentication - :param discard_unknown_keys: Boolean value indicating whether to discard - unknown properties. A server may send a response that includes additional - properties that are not known by the client in the following scenarios: - 1. The OpenAPI document is incomplete, i.e. it does not match the server - implementation. - 2. The client was generated using an older version of the OpenAPI document - and the server has been upgraded since then. - If a schema in the OpenAPI document defines the additionalProperties attribute, - then all undeclared properties received by the server are injected into the - additional properties map. In that case, there are undeclared properties, and - nothing to discard. :param disabled_client_side_validations (string): Comma-separated list of JSON schema validation keywords to disable JSON schema structural validation rules. The following keywords may be specified: multipleOf, maximum, @@ -162,17 +151,29 @@ conf = {{{packageName}}}.Configuration( _default = None - def __init__(self, host=None, - api_key=None, api_key_prefix=None, - username=None, password=None, - discard_unknown_keys=False, - disabled_client_side_validations="", + def __init__( + self, + host=None, +{{#if hasApiKeyMethods}} + api_key=None, + api_key_prefix=None, +{{/if}} +{{#if hasHttpBasicMethods}} + username=None, + password=None, +{{/if}} + disabled_client_side_validations="", {{#if hasHttpSignatureMethods}} - signing_info=None, + signing_info=None, {{/if}} - server_index=None, server_variables=None, - server_operation_index=None, server_operation_variables=None, - ): + server_index=None, + server_variables=None, + server_operation_index=None, + server_operation_variables=None, +{{#or hasOAuthMethods hasBearerMethods}} + access_token=None, +{{/or}} + ): """Constructor """ self._base_path = "{{{basePath}}}" if host is None else host @@ -190,6 +191,7 @@ conf = {{{packageName}}}.Configuration( """Temp file folder for downloading files """ # Authentication Settings +{{#if hasApiKeyMethods}} self.api_key = {} if api_key: self.api_key = api_key @@ -203,13 +205,15 @@ conf = {{{packageName}}}.Configuration( self.refresh_api_key_hook = None """function hook to refresh API key if expired """ +{{/if}} +{{#if hasHttpBasicMethods}} self.username = username """Username for HTTP basic authentication """ self.password = password """Password for HTTP basic authentication """ - self.discard_unknown_keys = discard_unknown_keys +{{/if}} self.disabled_client_side_validations = disabled_client_side_validations {{#if hasHttpSignatureMethods}} if signing_info is not None: @@ -218,18 +222,11 @@ conf = {{{packageName}}}.Configuration( """The HTTP signing configuration """ {{/if}} -{{#if hasOAuthMethods}} - self.access_token = None - """access token for OAuth/Bearer - """ -{{/if}} -{{#unless hasOAuthMethods}} -{{#if hasBearerMethods}} - self.access_token = None +{{#or hasOAuthMethods hasBearerMethods}} + self.access_token = access_token """access token for OAuth/Bearer """ -{{/if}} -{{/unless}} +{{/or}} self.logger = {} """Logging Settings """ diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/doc_auth_partial.handlebars b/modules/openapi-json-schema-generator/src/main/resources/python/doc_auth_partial.handlebars index b16451d867e..f5d61321c35 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/doc_auth_partial.handlebars +++ b/modules/openapi-json-schema-generator/src/main/resources/python/doc_auth_partial.handlebars @@ -101,9 +101,9 @@ configuration.api_key['{{{name}}}'] = 'YOUR_API_KEY' # Configure OAuth2 access token for authorization: {{{name}}} configuration = {{{packageName}}}.Configuration( - host = "{{{basePath}}}" + host = "{{{basePath}}}", + access_token = 'YOUR_ACCESS_TOKEN' ) -configuration.access_token = 'YOUR_ACCESS_TOKEN' {{/if}} {{/each}} {{/if}} diff --git a/modules/openapi-json-schema-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-json-schema-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index be50c4b1a58..9b3b54380f8 100644 --- a/modules/openapi-json-schema-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-json-schema-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -791,13 +791,16 @@ paths: description: Required String in group parameters required: true schema: - type: integer + type: string - name: required_boolean_group in: header description: Required Boolean in group parameters required: true schema: - type: boolean + type: string + enum: + - true + - false - name: required_int64_group in: query description: Required Integer in group parameters @@ -809,12 +812,15 @@ paths: in: query description: String in group parameters schema: - type: integer + type: string - name: boolean_group in: header description: Boolean in group parameters schema: - type: boolean + type: string + enum: + - true + - false - name: int64_group in: query description: Integer in group parameters diff --git a/samples/openapi3/client/3_0_3_unit_test/python/unit_test_api/configuration.py b/samples/openapi3/client/3_0_3_unit_test/python/unit_test_api/configuration.py index ee4ca7e8424..df35a2dfdc7 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/unit_test_api/configuration.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/unit_test_api/configuration.py @@ -42,17 +42,6 @@ class Configuration(object): The dict value is an API key prefix when generating the auth data. :param username: Username for HTTP basic authentication :param password: Password for HTTP basic authentication - :param discard_unknown_keys: Boolean value indicating whether to discard - unknown properties. A server may send a response that includes additional - properties that are not known by the client in the following scenarios: - 1. The OpenAPI document is incomplete, i.e. it does not match the server - implementation. - 2. The client was generated using an older version of the OpenAPI document - and the server has been upgraded since then. - If a schema in the OpenAPI document defines the additionalProperties attribute, - then all undeclared properties received by the server are injected into the - additional properties map. In that case, there are undeclared properties, and - nothing to discard. :param disabled_client_side_validations (string): Comma-separated list of JSON schema validation keywords to disable JSON schema structural validation rules. The following keywords may be specified: multipleOf, maximum, @@ -80,14 +69,15 @@ class Configuration(object): _default = None - def __init__(self, host=None, - api_key=None, api_key_prefix=None, - username=None, password=None, - discard_unknown_keys=False, - disabled_client_side_validations="", - server_index=None, server_variables=None, - server_operation_index=None, server_operation_variables=None, - ): + def __init__( + self, + host=None, + disabled_client_side_validations="", + server_index=None, + server_variables=None, + server_operation_index=None, + server_operation_variables=None, + ): """Constructor """ self._base_path = "https://someserver.com/v1" if host is None else host @@ -105,26 +95,6 @@ def __init__(self, host=None, """Temp file folder for downloading files """ # Authentication Settings - self.api_key = {} - if api_key: - self.api_key = api_key - """dict to store API key(s) - """ - self.api_key_prefix = {} - if api_key_prefix: - self.api_key_prefix = api_key_prefix - """dict to store API prefix (e.g. Bearer) - """ - self.refresh_api_key_hook = None - """function hook to refresh API key if expired - """ - self.username = username - """Username for HTTP basic authentication - """ - self.password = password - """Password for HTTP basic authentication - """ - self.discard_unknown_keys = discard_unknown_keys self.disabled_client_side_validations = disabled_client_side_validations self.logger = {} """Logging Settings diff --git a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/this_package/configuration.py b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/this_package/configuration.py index 641cf246141..32cd774ed63 100644 --- a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/this_package/configuration.py +++ b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/this_package/configuration.py @@ -42,17 +42,6 @@ class Configuration(object): The dict value is an API key prefix when generating the auth data. :param username: Username for HTTP basic authentication :param password: Password for HTTP basic authentication - :param discard_unknown_keys: Boolean value indicating whether to discard - unknown properties. A server may send a response that includes additional - properties that are not known by the client in the following scenarios: - 1. The OpenAPI document is incomplete, i.e. it does not match the server - implementation. - 2. The client was generated using an older version of the OpenAPI document - and the server has been upgraded since then. - If a schema in the OpenAPI document defines the additionalProperties attribute, - then all undeclared properties received by the server are injected into the - additional properties map. In that case, there are undeclared properties, and - nothing to discard. :param disabled_client_side_validations (string): Comma-separated list of JSON schema validation keywords to disable JSON schema structural validation rules. The following keywords may be specified: multipleOf, maximum, @@ -80,14 +69,15 @@ class Configuration(object): _default = None - def __init__(self, host=None, - api_key=None, api_key_prefix=None, - username=None, password=None, - discard_unknown_keys=False, - disabled_client_side_validations="", - server_index=None, server_variables=None, - server_operation_index=None, server_operation_variables=None, - ): + def __init__( + self, + host=None, + disabled_client_side_validations="", + server_index=None, + server_variables=None, + server_operation_index=None, + server_operation_variables=None, + ): """Constructor """ self._base_path = "http://localhost:3000" if host is None else host @@ -105,26 +95,6 @@ def __init__(self, host=None, """Temp file folder for downloading files """ # Authentication Settings - self.api_key = {} - if api_key: - self.api_key = api_key - """dict to store API key(s) - """ - self.api_key_prefix = {} - if api_key_prefix: - self.api_key_prefix = api_key_prefix - """dict to store API prefix (e.g. Bearer) - """ - self.refresh_api_key_hook = None - """function hook to refresh API key if expired - """ - self.username = username - """Username for HTTP basic authentication - """ - self.password = password - """Password for HTTP basic authentication - """ - self.discard_unknown_keys = discard_unknown_keys self.disabled_client_side_validations = disabled_client_side_validations self.logger = {} """Logging Settings diff --git a/samples/openapi3/client/petstore/python/docs/apis/tags/FakeApi.md b/samples/openapi3/client/petstore/python/docs/apis/tags/FakeApi.md index e8690102866..e990e97345e 100644 --- a/samples/openapi3/client/petstore/python/docs/apis/tags/FakeApi.md +++ b/samples/openapi3/client/petstore/python/docs/apis/tags/FakeApi.md @@ -1328,11 +1328,11 @@ with petstore_api.ApiClient(configuration) as api_client: # example passing only required values which don't have defaults set query_params = { - 'required_string_group': 1, + 'required_string_group': "required_string_group_example", 'required_int64_group': 1, } header_params = { - 'required_boolean_group': True, + 'required_boolean_group': "true", } try: # Fake endpoint to test group parameters (optional) @@ -1345,14 +1345,14 @@ with petstore_api.ApiClient(configuration) as api_client: # example passing only optional values query_params = { - 'required_string_group': 1, + 'required_string_group': "required_string_group_example", 'required_int64_group': 1, - 'string_group': 1, + 'string_group': "string_group_example", 'int64_group': 1, } header_params = { - 'required_boolean_group': True, - 'boolean_group': True, + 'required_boolean_group': "true", + 'boolean_group': "true", } try: # Fake endpoint to test group parameters (optional) @@ -1389,7 +1389,7 @@ int64_group | Int64GroupSchema | | optional ## Model Type Info Input Type | Accessed Type | Description | Notes ------------ | ------------- | ------------- | ------------- -decimal.Decimal, int, | decimal.Decimal, | | +str, | str, | | # RequiredInt64GroupSchema @@ -1403,7 +1403,7 @@ decimal.Decimal, int, | decimal.Decimal, | | value must be a 64 bit integer ## Model Type Info Input Type | Accessed Type | Description | Notes ------------ | ------------- | ------------- | ------------- -decimal.Decimal, int, | decimal.Decimal, | | +str, | str, | | # Int64GroupSchema @@ -1425,14 +1425,14 @@ boolean_group | BooleanGroupSchema | | optional ## Model Type Info Input Type | Accessed Type | Description | Notes ------------ | ------------- | ------------- | ------------- -bool, | BoolClass, | | +str, | str, | | must be one of ["true", "false", ] # BooleanGroupSchema ## Model Type Info Input Type | Accessed Type | Description | Notes ------------ | ------------- | ------------- | ------------- -bool, | BoolClass, | | +str, | str, | | must be one of ["true", "false", ] ### Return Types, Responses diff --git a/samples/openapi3/client/petstore/python/docs/apis/tags/PetApi.md b/samples/openapi3/client/petstore/python/docs/apis/tags/PetApi.md index a295a0d499b..28787e08d35 100644 --- a/samples/openapi3/client/petstore/python/docs/apis/tags/PetApi.md +++ b/samples/openapi3/client/petstore/python/docs/apis/tags/PetApi.md @@ -104,9 +104,9 @@ configuration = petstore_api.Configuration( # Configure OAuth2 access token for authorization: petstore_auth configuration = petstore_api.Configuration( - host = "http://petstore.swagger.io:80/v2" + host = "http://petstore.swagger.io:80/v2", + access_token = 'YOUR_ACCESS_TOKEN' ) -configuration.access_token = 'YOUR_ACCESS_TOKEN' # Enter a context with an instance of the API client with petstore_api.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -218,9 +218,9 @@ configuration = petstore_api.Configuration( # Configure OAuth2 access token for authorization: petstore_auth configuration = petstore_api.Configuration( - host = "http://petstore.swagger.io:80/v2" + host = "http://petstore.swagger.io:80/v2", + access_token = 'YOUR_ACCESS_TOKEN' ) -configuration.access_token = 'YOUR_ACCESS_TOKEN' # Enter a context with an instance of the API client with petstore_api.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -404,9 +404,9 @@ configuration = petstore_api.Configuration( # Configure OAuth2 access token for authorization: petstore_auth configuration = petstore_api.Configuration( - host = "http://petstore.swagger.io:80/v2" + host = "http://petstore.swagger.io:80/v2", + access_token = 'YOUR_ACCESS_TOKEN' ) -configuration.access_token = 'YOUR_ACCESS_TOKEN' # Enter a context with an instance of the API client with petstore_api.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -598,9 +598,9 @@ configuration = petstore_api.Configuration( # Configure OAuth2 access token for authorization: petstore_auth configuration = petstore_api.Configuration( - host = "http://petstore.swagger.io:80/v2" + host = "http://petstore.swagger.io:80/v2", + access_token = 'YOUR_ACCESS_TOKEN' ) -configuration.access_token = 'YOUR_ACCESS_TOKEN' # Enter a context with an instance of the API client with petstore_api.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -912,9 +912,9 @@ configuration = petstore_api.Configuration( # Configure OAuth2 access token for authorization: petstore_auth configuration = petstore_api.Configuration( - host = "http://petstore.swagger.io:80/v2" + host = "http://petstore.swagger.io:80/v2", + access_token = 'YOUR_ACCESS_TOKEN' ) -configuration.access_token = 'YOUR_ACCESS_TOKEN' # Enter a context with an instance of the API client with petstore_api.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -1034,9 +1034,9 @@ configuration = petstore_api.Configuration( # Configure OAuth2 access token for authorization: petstore_auth configuration = petstore_api.Configuration( - host = "http://petstore.swagger.io:80/v2" + host = "http://petstore.swagger.io:80/v2", + access_token = 'YOUR_ACCESS_TOKEN' ) -configuration.access_token = 'YOUR_ACCESS_TOKEN' # Enter a context with an instance of the API client with petstore_api.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -1159,9 +1159,9 @@ configuration = petstore_api.Configuration( # Configure OAuth2 access token for authorization: petstore_auth configuration = petstore_api.Configuration( - host = "http://petstore.swagger.io:80/v2" + host = "http://petstore.swagger.io:80/v2", + access_token = 'YOUR_ACCESS_TOKEN' ) -configuration.access_token = 'YOUR_ACCESS_TOKEN' # Enter a context with an instance of the API client with petstore_api.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -1293,9 +1293,9 @@ configuration = petstore_api.Configuration( # Configure OAuth2 access token for authorization: petstore_auth configuration = petstore_api.Configuration( - host = "http://petstore.swagger.io:80/v2" + host = "http://petstore.swagger.io:80/v2", + access_token = 'YOUR_ACCESS_TOKEN' ) -configuration.access_token = 'YOUR_ACCESS_TOKEN' # Enter a context with an instance of the API client with petstore_api.ApiClient(configuration) as api_client: # Create an instance of the API class diff --git a/samples/openapi3/client/petstore/python/petstore_api/configuration.py b/samples/openapi3/client/petstore/python/petstore_api/configuration.py index f7c2a3ff91e..3e09af0b250 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python/petstore_api/configuration.py @@ -42,17 +42,6 @@ class Configuration(object): The dict value is an API key prefix when generating the auth data. :param username: Username for HTTP basic authentication :param password: Password for HTTP basic authentication - :param discard_unknown_keys: Boolean value indicating whether to discard - unknown properties. A server may send a response that includes additional - properties that are not known by the client in the following scenarios: - 1. The OpenAPI document is incomplete, i.e. it does not match the server - implementation. - 2. The client was generated using an older version of the OpenAPI document - and the server has been upgraded since then. - If a schema in the OpenAPI document defines the additionalProperties attribute, - then all undeclared properties received by the server are injected into the - additional properties map. In that case, there are undeclared properties, and - nothing to discard. :param disabled_client_side_validations (string): Comma-separated list of JSON schema validation keywords to disable JSON schema structural validation rules. The following keywords may be specified: multipleOf, maximum, @@ -157,15 +146,21 @@ class Configuration(object): _default = None - def __init__(self, host=None, - api_key=None, api_key_prefix=None, - username=None, password=None, - discard_unknown_keys=False, - disabled_client_side_validations="", - signing_info=None, - server_index=None, server_variables=None, - server_operation_index=None, server_operation_variables=None, - ): + def __init__( + self, + host=None, + api_key=None, + api_key_prefix=None, + username=None, + password=None, + disabled_client_side_validations="", + signing_info=None, + server_index=None, + server_variables=None, + server_operation_index=None, + server_operation_variables=None, + access_token=None, + ): """Constructor """ self._base_path = "http://petstore.swagger.io:80/v2" if host is None else host @@ -202,14 +197,13 @@ def __init__(self, host=None, self.password = password """Password for HTTP basic authentication """ - self.discard_unknown_keys = discard_unknown_keys self.disabled_client_side_validations = disabled_client_side_validations if signing_info is not None: signing_info.host = host self.signing_info = signing_info """The HTTP signing configuration """ - self.access_token = None + self.access_token = access_token """access token for OAuth/Bearer """ self.logger = {} diff --git a/samples/openapi3/client/petstore/python/petstore_api/paths/fake/delete.py b/samples/openapi3/client/petstore/python/petstore_api/paths/fake/delete.py index 9803516eec2..7afe98ac646 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/paths/fake/delete.py +++ b/samples/openapi3/client/petstore/python/petstore_api/paths/fake/delete.py @@ -28,21 +28,21 @@ from . import path # Query params -RequiredStringGroupSchema = schemas.IntSchema +RequiredStringGroupSchema = schemas.StrSchema RequiredInt64GroupSchema = schemas.Int64Schema -StringGroupSchema = schemas.IntSchema +StringGroupSchema = schemas.StrSchema Int64GroupSchema = schemas.Int64Schema RequestRequiredQueryParams = typing_extensions.TypedDict( 'RequestRequiredQueryParams', { - 'required_string_group': typing.Union[RequiredStringGroupSchema, decimal.Decimal, int, ], + 'required_string_group': typing.Union[RequiredStringGroupSchema, str, ], 'required_int64_group': typing.Union[RequiredInt64GroupSchema, decimal.Decimal, int, ], } ) RequestOptionalQueryParams = typing_extensions.TypedDict( 'RequestOptionalQueryParams', { - 'string_group': typing.Union[StringGroupSchema, decimal.Decimal, int, ], + 'string_group': typing.Union[StringGroupSchema, str, ], 'int64_group': typing.Union[Int64GroupSchema, decimal.Decimal, int, ], }, total=False @@ -80,18 +80,58 @@ class RequestQueryParams(RequestRequiredQueryParams, RequestOptionalQueryParams) explode=True, ) # Header params -RequiredBooleanGroupSchema = schemas.BoolSchema -BooleanGroupSchema = schemas.BoolSchema + + +class RequiredBooleanGroupSchema( + schemas.EnumBase, + schemas.StrSchema +): + + + class MetaOapg: + enum_value_to_name = { + "true": "TRUE", + "false": "FALSE", + } + + @schemas.classproperty + def TRUE(cls): + return cls("true") + + @schemas.classproperty + def FALSE(cls): + return cls("false") + + +class BooleanGroupSchema( + schemas.EnumBase, + schemas.StrSchema +): + + + class MetaOapg: + enum_value_to_name = { + "true": "TRUE", + "false": "FALSE", + } + + @schemas.classproperty + def TRUE(cls): + return cls("true") + + @schemas.classproperty + def FALSE(cls): + return cls("false") RequestRequiredHeaderParams = typing_extensions.TypedDict( 'RequestRequiredHeaderParams', { - 'required_boolean_group': typing.Union[RequiredBooleanGroupSchema, bool, ], + 'required_boolean_group': typing.Union[RequiredBooleanGroupSchema, str, ], } ) RequestOptionalHeaderParams = typing_extensions.TypedDict( 'RequestOptionalHeaderParams', { - 'boolean_group': typing.Union[BooleanGroupSchema, bool, ], + 'boolean_group': typing.Union[BooleanGroupSchema, str, ], }, total=False ) diff --git a/samples/openapi3/client/petstore/python/petstore_api/paths/fake/delete.pyi b/samples/openapi3/client/petstore/python/petstore_api/paths/fake/delete.pyi index 1bb21445f6f..d074fbd1071 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/paths/fake/delete.pyi +++ b/samples/openapi3/client/petstore/python/petstore_api/paths/fake/delete.pyi @@ -26,21 +26,21 @@ import frozendict # noqa: F401 from petstore_api import schemas # noqa: F401 # Query params -RequiredStringGroupSchema = schemas.IntSchema +RequiredStringGroupSchema = schemas.StrSchema RequiredInt64GroupSchema = schemas.Int64Schema -StringGroupSchema = schemas.IntSchema +StringGroupSchema = schemas.StrSchema Int64GroupSchema = schemas.Int64Schema RequestRequiredQueryParams = typing_extensions.TypedDict( 'RequestRequiredQueryParams', { - 'required_string_group': typing.Union[RequiredStringGroupSchema, decimal.Decimal, int, ], + 'required_string_group': typing.Union[RequiredStringGroupSchema, str, ], 'required_int64_group': typing.Union[RequiredInt64GroupSchema, decimal.Decimal, int, ], } ) RequestOptionalQueryParams = typing_extensions.TypedDict( 'RequestOptionalQueryParams', { - 'string_group': typing.Union[StringGroupSchema, decimal.Decimal, int, ], + 'string_group': typing.Union[StringGroupSchema, str, ], 'int64_group': typing.Union[Int64GroupSchema, decimal.Decimal, int, ], }, total=False @@ -78,18 +78,44 @@ request_query_int64_group = api_client.QueryParameter( explode=True, ) # Header params -RequiredBooleanGroupSchema = schemas.BoolSchema -BooleanGroupSchema = schemas.BoolSchema + + +class RequiredBooleanGroupSchema( + schemas.EnumBase, + schemas.StrSchema +): + + @schemas.classproperty + def TRUE(cls): + return cls("true") + + @schemas.classproperty + def FALSE(cls): + return cls("false") + + +class BooleanGroupSchema( + schemas.EnumBase, + schemas.StrSchema +): + + @schemas.classproperty + def TRUE(cls): + return cls("true") + + @schemas.classproperty + def FALSE(cls): + return cls("false") RequestRequiredHeaderParams = typing_extensions.TypedDict( 'RequestRequiredHeaderParams', { - 'required_boolean_group': typing.Union[RequiredBooleanGroupSchema, bool, ], + 'required_boolean_group': typing.Union[RequiredBooleanGroupSchema, str, ], } ) RequestOptionalHeaderParams = typing_extensions.TypedDict( 'RequestOptionalHeaderParams', { - 'boolean_group': typing.Union[BooleanGroupSchema, bool, ], + 'boolean_group': typing.Union[BooleanGroupSchema, str, ], }, total=False ) diff --git a/samples/openapi3/client/petstore/python/tests_manual/test_paths/test_fake/test_delete.py b/samples/openapi3/client/petstore/python/tests_manual/test_paths/test_fake/test_delete.py new file mode 100644 index 00000000000..1a082a9b663 --- /dev/null +++ b/samples/openapi3/client/petstore/python/tests_manual/test_paths/test_fake/test_delete.py @@ -0,0 +1,61 @@ +# coding: utf-8 + +""" + + + Generated by: https://openapi-generator.tech +""" + +import unittest +from unittest.mock import patch + +import urllib3 + +from petstore_api.paths.fake import delete +from petstore_api import configuration, schemas, api_client + +from ... import ApiTestMixin + + +class TestFake(ApiTestMixin, unittest.TestCase): + used_configuration = configuration.Configuration( + access_token='someBearerToken' + ) + used_api_client = api_client.ApiClient( + configuration=used_configuration + ) + api = delete.ApiFordelete(api_client=used_api_client) + + @patch.object(urllib3.PoolManager, 'request') + def test_delete_uses_http_bearer_auth(self, mock_request): + mock_request.return_value = self.response(b'') + + query_params = { + 'required_string_group': 'a', + 'required_int64_group': 1, + } + header_params = { + 'required_boolean_group': 'true' + } + api_response = self.api.delete(query_params=query_params, header_params=header_params) + self.assert_pool_manager_request_called_with( + mock_request, + f'http://petstore.swagger.io:80/v2/fake?required_string_group=a&required_int64_group=1', + body=None, + method='DELETE', + content_type=None, + accept_content_type=None, + headers={ + 'Authorization': 'Bearer someBearerToken', + 'required_boolean_group': 'true' + } + ) + + assert isinstance(api_response.response, urllib3.HTTPResponse) + assert isinstance(api_response.body, schemas.Unset) + assert isinstance(api_response.headers, schemas.Unset) + assert api_response.response.status == 200 + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python/tests_manual/test_paths/test_fake/test_post.py b/samples/openapi3/client/petstore/python/tests_manual/test_paths/test_fake/test_post.py new file mode 100644 index 00000000000..290c8fc22f9 --- /dev/null +++ b/samples/openapi3/client/petstore/python/tests_manual/test_paths/test_fake/test_post.py @@ -0,0 +1,52 @@ +# coding: utf-8 + +""" + + + Generated by: https://openapi-generator.tech +""" + +import unittest +from unittest.mock import patch + +import urllib3 + +from petstore_api.paths.fake import post +from petstore_api import configuration, schemas, api_client + +from ... import ApiTestMixin + + +class TestFake(ApiTestMixin, unittest.TestCase): + used_configuration = configuration.Configuration( + username='demo', + password='p@55w0rd' + ) + used_api_client = api_client.ApiClient( + configuration=used_configuration + ) + api = post.ApiForpost(api_client=used_api_client) + + @patch.object(urllib3.PoolManager, 'request') + def test_post_uses_http_basic_auth(self, mock_request): + mock_request.return_value = self.response(b'') + + api_response = self.api.post() + self.assert_pool_manager_request_called_with( + mock_request, + f'http://petstore.swagger.io:80/v2/fake', + body=None, + method='POST', + content_type=None, + accept_content_type=None, + headers={'Authorization': 'Basic ZGVtbzpwQDU1dzByZA=='} + ) + + assert isinstance(api_response.response, urllib3.HTTPResponse) + assert isinstance(api_response.body, schemas.Unset) + assert isinstance(api_response.headers, schemas.Unset) + assert api_response.response.status == 200 + + +if __name__ == '__main__': + unittest.main()