From 32f2db3fac4a737b37481c55b9e7f3063323348c Mon Sep 17 00:00:00 2001 From: JONEMI19 Date: Fri, 7 Jul 2023 21:01:55 +0000 Subject: [PATCH] tests passing for freeform queries --- fastapi/_compat.py | 19 +- fastapi/dependencies/utils.py | 2 +- test_openapi.json | 1472 +++++++++++++++++++++++++++++++++ tests/main.py | 15 +- tests/test_application.py | 1394 ++++++++++++++++--------------- tests/test_query.py | 6 + 6 files changed, 2252 insertions(+), 656 deletions(-) create mode 100644 test_openapi.json diff --git a/fastapi/_compat.py b/fastapi/_compat.py index 2fbef2d15..bdf40371b 100644 --- a/fastapi/_compat.py +++ b/fastapi/_compat.py @@ -45,7 +45,6 @@ sequence_types = tuple(sequence_annotation_to_type.keys()) mapping_annotation_to_type = { Mapping: list, - List: list, } mapping_types = tuple(mapping_annotation_to_type.keys()) @@ -567,16 +566,19 @@ def field_annotation_is_sequence(annotation: Union[Type[Any], None]) -> bool: get_origin(annotation) ) + def _annotation_is_mapping(annotation: Union[Type[Any], None]) -> bool: if lenient_issubclass(annotation, (str, bytes)): return False return lenient_issubclass(annotation, mapping_types) + def field_annotation_is_mapping(annotation: Union[Type[Any], None]) -> bool: - return _annotation_is_mapping(annotation) or _annotation_is_sequence( + return _annotation_is_mapping(annotation) or _annotation_is_mapping( get_origin(annotation) ) + def value_is_sequence(value: Any) -> bool: return isinstance(value, sequence_types) and not isinstance(value, (str, bytes)) # type: ignore[arg-type] @@ -585,6 +587,7 @@ def _annotation_is_complex(annotation: Union[Type[Any], None]) -> bool: return ( lenient_issubclass(annotation, (BaseModel, UploadFile)) or _annotation_is_sequence(annotation) + or _annotation_is_mapping(annotation) or is_dataclass(annotation) ) @@ -623,6 +626,7 @@ def field_annotation_is_scalar_sequence(annotation: Union[Type[Any], None]) -> b for sub_annotation in get_args(annotation) ) + def field_annotation_is_scalar_mapping(annotation: Union[Type[Any], None]) -> bool: origin = get_origin(annotation) if origin is Union or origin is UnionType: @@ -639,7 +643,10 @@ def field_annotation_is_scalar_mapping(annotation: Union[Type[Any], None]) -> bo for sub_annotation in get_args(annotation) ) -def field_annotation_is_scalar_sequence_mapping(annotation: Union[Type[Any], None]) -> bool: + +def field_annotation_is_scalar_sequence_mapping( + annotation: Union[Type[Any], None] +) -> bool: origin = get_origin(annotation) if origin is Union or origin is UnionType: at_least_one_scalar_mapping = False @@ -651,10 +658,14 @@ def field_annotation_is_scalar_sequence_mapping(annotation: Union[Type[Any], Non return False return at_least_one_scalar_mapping return field_annotation_is_mapping(annotation) and all( - (field_annotation_is_scalar_sequence(sub_annotation) or field_annotation_is_scalar(sub_annotation)) + ( + field_annotation_is_scalar_sequence(sub_annotation) + or field_annotation_is_scalar(sub_annotation) + ) for sub_annotation in get_args(annotation) ) + def is_bytes_or_nonable_bytes_annotation(annotation: Any) -> bool: if lenient_issubclass(annotation, bytes): return True diff --git a/fastapi/dependencies/utils.py b/fastapi/dependencies/utils.py index 2b6e7cf7a..3184664ca 100644 --- a/fastapi/dependencies/utils.py +++ b/fastapi/dependencies/utils.py @@ -652,7 +652,7 @@ def request_params_to_args( received_params, (QueryParams, Headers) ): value = received_params.getlist(field.alias) or field.default - if is_scalar_mapping_field(field) and isinstance( + elif is_scalar_mapping_field(field) and isinstance( received_params, (QueryParams, Headers) ): value = dict(received_params.multi_items()) or field.default diff --git a/test_openapi.json b/test_openapi.json new file mode 100644 index 000000000..05df1c120 --- /dev/null +++ b/test_openapi.json @@ -0,0 +1,1472 @@ +{ + "openapi": "3.1.0", + "info": { + "title": "FastAPI", + "version": "0.1.0" + }, + "paths": { + "/api_route": { + "get": { + "summary": "Non Operation", + "operationId": "non_operation_api_route_get", + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + } + } + } + }, + "/non_decorated_route": { + "get": { + "summary": "Non Decorated Route", + "operationId": "non_decorated_route_non_decorated_route_get", + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + } + } + } + }, + "/text": { + "get": { + "summary": "Get Text", + "operationId": "get_text_text_get", + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + } + } + } + }, + "/path/{item_id}": { + "get": { + "summary": "Get Id", + "operationId": "get_id_path__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/path/str/{item_id}": { + "get": { + "summary": "Get Str Id", + "operationId": "get_str_id_path_str__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "type": "string", + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/path/int/{item_id}": { + "get": { + "summary": "Get Int Id", + "operationId": "get_int_id_path_int__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "type": "integer", + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/path/float/{item_id}": { + "get": { + "summary": "Get Float Id", + "operationId": "get_float_id_path_float__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "type": "number", + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/path/bool/{item_id}": { + "get": { + "summary": "Get Bool Id", + "operationId": "get_bool_id_path_bool__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "type": "boolean", + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/path/param/{item_id}": { + "get": { + "summary": "Get Path Param Id", + "operationId": "get_path_param_id_path_param__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/path/param-minlength/{item_id}": { + "get": { + "summary": "Get Path Param Min Length", + "operationId": "get_path_param_min_length_path_param_minlength__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "type": "string", + "minLength": 3, + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/path/param-maxlength/{item_id}": { + "get": { + "summary": "Get Path Param Max Length", + "operationId": "get_path_param_max_length_path_param_maxlength__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "type": "string", + "maxLength": 3, + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/path/param-min_maxlength/{item_id}": { + "get": { + "summary": "Get Path Param Min Max Length", + "operationId": "get_path_param_min_max_length_path_param_min_maxlength__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "type": "string", + "minLength": 2, + "maxLength": 3, + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/path/param-gt/{item_id}": { + "get": { + "summary": "Get Path Param Gt", + "operationId": "get_path_param_gt_path_param_gt__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "type": "number", + "exclusiveMinimum": 3, + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/path/param-gt0/{item_id}": { + "get": { + "summary": "Get Path Param Gt0", + "operationId": "get_path_param_gt0_path_param_gt0__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "type": "number", + "exclusiveMinimum": 0, + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/path/param-ge/{item_id}": { + "get": { + "summary": "Get Path Param Ge", + "operationId": "get_path_param_ge_path_param_ge__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "type": "number", + "minimum": 3, + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/path/param-lt/{item_id}": { + "get": { + "summary": "Get Path Param Lt", + "operationId": "get_path_param_lt_path_param_lt__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "type": "number", + "exclusiveMaximum": 3, + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/path/param-lt0/{item_id}": { + "get": { + "summary": "Get Path Param Lt0", + "operationId": "get_path_param_lt0_path_param_lt0__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "type": "number", + "exclusiveMaximum": 0, + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/path/param-le/{item_id}": { + "get": { + "summary": "Get Path Param Le", + "operationId": "get_path_param_le_path_param_le__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "type": "number", + "maximum": 3, + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/path/param-lt-gt/{item_id}": { + "get": { + "summary": "Get Path Param Lt Gt", + "operationId": "get_path_param_lt_gt_path_param_lt_gt__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "type": "number", + "exclusiveMaximum": 3, + "exclusiveMinimum": 1, + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/path/param-le-ge/{item_id}": { + "get": { + "summary": "Get Path Param Le Ge", + "operationId": "get_path_param_le_ge_path_param_le_ge__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "type": "number", + "maximum": 3, + "minimum": 1, + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/path/param-lt-int/{item_id}": { + "get": { + "summary": "Get Path Param Lt Int", + "operationId": "get_path_param_lt_int_path_param_lt_int__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "type": "integer", + "exclusiveMaximum": 3, + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/path/param-gt-int/{item_id}": { + "get": { + "summary": "Get Path Param Gt Int", + "operationId": "get_path_param_gt_int_path_param_gt_int__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "type": "integer", + "exclusiveMinimum": 3, + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/path/param-le-int/{item_id}": { + "get": { + "summary": "Get Path Param Le Int", + "operationId": "get_path_param_le_int_path_param_le_int__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "type": "integer", + "maximum": 3, + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/path/param-ge-int/{item_id}": { + "get": { + "summary": "Get Path Param Ge Int", + "operationId": "get_path_param_ge_int_path_param_ge_int__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "type": "integer", + "minimum": 3, + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/path/param-lt-gt-int/{item_id}": { + "get": { + "summary": "Get Path Param Lt Gt Int", + "operationId": "get_path_param_lt_gt_int_path_param_lt_gt_int__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "type": "integer", + "exclusiveMaximum": 3, + "exclusiveMinimum": 1, + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/path/param-le-ge-int/{item_id}": { + "get": { + "summary": "Get Path Param Le Ge Int", + "operationId": "get_path_param_le_ge_int_path_param_le_ge_int__item_id__get", + "parameters": [ + { + "name": "item_id", + "in": "path", + "required": true, + "schema": { + "type": "integer", + "maximum": 3, + "minimum": 1, + "title": "Item Id" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/query": { + "get": { + "summary": "Get Query", + "operationId": "get_query_query_get", + "parameters": [ + { + "name": "query", + "in": "query", + "required": true, + "schema": { + "title": "Query" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/query/optional": { + "get": { + "summary": "Get Query Optional", + "operationId": "get_query_optional_query_optional_get", + "parameters": [ + { + "name": "query", + "in": "query", + "required": false, + "schema": { + "title": "Query" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/query/int": { + "get": { + "summary": "Get Query Type", + "operationId": "get_query_type_query_int_get", + "parameters": [ + { + "name": "query", + "in": "query", + "required": true, + "schema": { + "type": "integer", + "title": "Query" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/query/int/optional": { + "get": { + "summary": "Get Query Type Optional", + "operationId": "get_query_type_optional_query_int_optional_get", + "parameters": [ + { + "name": "query", + "in": "query", + "required": false, + "schema": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "title": "Query" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/query/int/default": { + "get": { + "summary": "Get Query Type Int Default", + "operationId": "get_query_type_int_default_query_int_default_get", + "parameters": [ + { + "name": "query", + "in": "query", + "required": false, + "schema": { + "type": "integer", + "default": 10, + "title": "Query" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/query/param": { + "get": { + "summary": "Get Query Param", + "operationId": "get_query_param_query_param_get", + "parameters": [ + { + "name": "query", + "in": "query", + "required": false, + "schema": { + "title": "Query" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/query/param-required": { + "get": { + "summary": "Get Query Param Required", + "operationId": "get_query_param_required_query_param_required_get", + "parameters": [ + { + "name": "query", + "in": "query", + "required": true, + "schema": { + "title": "Query" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/query/param-required/int": { + "get": { + "summary": "Get Query Param Required Type", + "operationId": "get_query_param_required_type_query_param_required_int_get", + "parameters": [ + { + "name": "query", + "in": "query", + "required": true, + "schema": { + "type": "integer", + "title": "Query" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/query/sequence-params": { + "get": { + "summary": "Get Sequence Query Params", + "operationId": "get_sequence_query_params_query_sequence_params_get", + "parameters": [ + { + "name": "query", + "in": "query", + "required": false, + "schema": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "integer" + } + }, + "default": {}, + "title": "Query" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/query/mapping-params": { + "get": { + "summary": "Get Mapping Query Params", + "operationId": "get_mapping_query_params_query_mapping_params_get", + "parameters": [ + { + "name": "queries", + "in": "query", + "required": false, + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + }, + "default": {}, + "title": "Queries" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/query/mapping-sequence-params": { + "get": { + "summary": "Get Sequence Mapping Query Params", + "operationId": "get_sequence_mapping_query_params_query_mapping_sequence_params_get", + "parameters": [ + { + "name": "queries", + "in": "query", + "required": false, + "schema": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "integer" + } + }, + "default": {}, + "title": "Queries" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/enum-status-code": { + "get": { + "summary": "Get Enum Status Code", + "operationId": "get_enum_status_code_enum_status_code_get", + "responses": { + "201": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + } + } + } + }, + "/query/frozenset": { + "get": { + "summary": "Get Query Type Frozenset", + "operationId": "get_query_type_frozenset_query_frozenset_get", + "parameters": [ + { + "name": "query", + "in": "query", + "required": true, + "schema": { + "type": "array", + "uniqueItems": true, + "items": { + "type": "integer" + }, + "title": "Query" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": {} + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + } + }, + "components": { + "schemas": { + "HTTPValidationError": { + "properties": { + "detail": { + "items": { + "$ref": "#/components/schemas/ValidationError" + }, + "type": "array", + "title": "Detail" + } + }, + "type": "object", + "title": "HTTPValidationError" + }, + "ValidationError": { + "properties": { + "loc": { + "items": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "integer" + } + ] + }, + "type": "array", + "title": "Location" + }, + "msg": { + "type": "string", + "title": "Message" + }, + "type": { + "type": "string", + "title": "Error Type" + } + }, + "type": "object", + "required": [ + "loc", + "msg", + "type" + ], + "title": "ValidationError" + } + } + } +} \ No newline at end of file diff --git a/tests/main.py b/tests/main.py index 935ff270f..1a590add8 100644 --- a/tests/main.py +++ b/tests/main.py @@ -184,16 +184,21 @@ def get_query_param_required_type(query: int = Query()): return f"foo bar {query}" -@app.get("/query/params") -def get_query_params(query: Mapping[str, int] = Query({})): - return f"foo bar {query}" - - @app.get("/query/sequence-params") def get_sequence_query_params(query: Mapping[str, List[int]] = Query({})): return f"foo bar {query}" +@app.get("/query/mapping-params") +def get_mapping_query_params(queries: Mapping[str, str] = Query({})): + return f"foo bar {queries['foo']} {queries['bar']}" + + +@app.get("/query/mapping-sequence-params") +def get_sequence_mapping_query_params(queries: Mapping[str, List[int]] = Query({})): + return f"foo bar {queries}" + + @app.get("/enum-status-code", status_code=http.HTTPStatus.CREATED) def get_enum_status_code(): return "foo bar" diff --git a/tests/test_application.py b/tests/test_application.py index 49e4711ed..b54a97281 100644 --- a/tests/test_application.py +++ b/tests/test_application.py @@ -1,5 +1,4 @@ import pytest -from dirty_equals import IsDict from fastapi.testclient import TestClient from .main import app @@ -1256,192 +1255,172 @@ def test_openapi_schema(): "paths": { "/api_route": { "get": { + "summary": "Non Operation", + "operationId": "non_operation_api_route_get", "responses": { "200": { "description": "Successful Response", "content": {"application/json": {"schema": {}}}, } }, - "summary": "Non Operation", - "operationId": "non_operation_api_route_get", } }, "/non_decorated_route": { "get": { + "summary": "Non Decorated Route", + "operationId": "non_decorated_route_non_decorated_route_get", "responses": { "200": { "description": "Successful Response", "content": {"application/json": {"schema": {}}}, } }, - "summary": "Non Decorated Route", - "operationId": "non_decorated_route_non_decorated_route_get", } }, "/text": { "get": { + "summary": "Get Text", + "operationId": "get_text_text_get", "responses": { "200": { "description": "Successful Response", "content": {"application/json": {"schema": {}}}, } }, - "summary": "Get Text", - "operationId": "get_text_text_get", } }, "/path/{item_id}": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Id", "operationId": "get_id_path__item_id__get", "parameters": [ { - "required": True, - "schema": {"title": "Item Id"}, "name": "item_id", "in": "path", + "required": True, + "schema": {"title": "Item Id"}, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/path/str/{item_id}": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Str Id", "operationId": "get_str_id_path_str__item_id__get", "parameters": [ { - "required": True, - "schema": {"title": "Item Id", "type": "string"}, "name": "item_id", "in": "path", + "required": True, + "schema": {"type": "string", "title": "Item Id"}, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/path/int/{item_id}": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Int Id", "operationId": "get_int_id_path_int__item_id__get", "parameters": [ { - "required": True, - "schema": {"title": "Item Id", "type": "integer"}, "name": "item_id", "in": "path", + "required": True, + "schema": {"type": "integer", "title": "Item Id"}, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/path/float/{item_id}": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Float Id", "operationId": "get_float_id_path_float__item_id__get", "parameters": [ { - "required": True, - "schema": {"title": "Item Id", "type": "number"}, "name": "item_id", "in": "path", + "required": True, + "schema": {"type": "number", "title": "Item Id"}, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/path/bool/{item_id}": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Bool Id", "operationId": "get_bool_id_path_bool__item_id__get", "parameters": [ { - "required": True, - "schema": {"title": "Item Id", "type": "boolean"}, "name": "item_id", "in": "path", + "required": True, + "schema": {"type": "boolean", "title": "Item Id"}, } ], - } - }, - "/path/param/{item_id}": { - "get": { "responses": { "200": { "description": "Successful Response", @@ -1458,6 +1437,10 @@ def test_openapi_schema(): }, }, }, + } + }, + "/path/param/{item_id}": { + "get": { "summary": "Get Path Param Id", "operationId": "get_path_param_id_path_param__item_id__get", "parameters": [ @@ -1465,693 +1448,685 @@ def test_openapi_schema(): "name": "item_id", "in": "path", "required": True, - "schema": IsDict( - { - "anyOf": [{"type": "string"}, {"type": "null"}], - "title": "Item Id", - } - ) - # TODO: remove when deprecating Pydantic v1 - | IsDict({"title": "Item Id", "type": "string"}), + "schema": { + "anyOf": [{"type": "string"}, {"type": "null"}], + "title": "Item Id", + }, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/path/param-minlength/{item_id}": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Path Param Min Length", "operationId": "get_path_param_min_length_path_param_minlength__item_id__get", "parameters": [ { - "required": True, - "schema": { - "title": "Item Id", - "minLength": 3, - "type": "string", - }, "name": "item_id", "in": "path", + "required": True, + "schema": { + "type": "string", + "minLength": 3, + "title": "Item Id", + }, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/path/param-maxlength/{item_id}": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Path Param Max Length", "operationId": "get_path_param_max_length_path_param_maxlength__item_id__get", "parameters": [ { - "required": True, - "schema": { - "title": "Item Id", - "maxLength": 3, - "type": "string", - }, "name": "item_id", "in": "path", + "required": True, + "schema": { + "type": "string", + "maxLength": 3, + "title": "Item Id", + }, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/path/param-min_maxlength/{item_id}": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Path Param Min Max Length", "operationId": "get_path_param_min_max_length_path_param_min_maxlength__item_id__get", "parameters": [ { - "required": True, - "schema": { - "title": "Item Id", - "maxLength": 3, - "minLength": 2, - "type": "string", - }, "name": "item_id", "in": "path", + "required": True, + "schema": { + "type": "string", + "minLength": 2, + "maxLength": 3, + "title": "Item Id", + }, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/path/param-gt/{item_id}": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Path Param Gt", "operationId": "get_path_param_gt_path_param_gt__item_id__get", "parameters": [ { - "required": True, - "schema": { - "title": "Item Id", - "exclusiveMinimum": 3.0, - "type": "number", - }, "name": "item_id", "in": "path", + "required": True, + "schema": { + "type": "number", + "exclusiveMinimum": 3, + "title": "Item Id", + }, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/path/param-gt0/{item_id}": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Path Param Gt0", "operationId": "get_path_param_gt0_path_param_gt0__item_id__get", "parameters": [ { - "required": True, - "schema": { - "title": "Item Id", - "exclusiveMinimum": 0.0, - "type": "number", - }, "name": "item_id", "in": "path", + "required": True, + "schema": { + "type": "number", + "exclusiveMinimum": 0, + "title": "Item Id", + }, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/path/param-ge/{item_id}": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Path Param Ge", "operationId": "get_path_param_ge_path_param_ge__item_id__get", "parameters": [ { - "required": True, - "schema": { - "title": "Item Id", - "minimum": 3.0, - "type": "number", - }, "name": "item_id", "in": "path", + "required": True, + "schema": { + "type": "number", + "minimum": 3, + "title": "Item Id", + }, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/path/param-lt/{item_id}": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Path Param Lt", "operationId": "get_path_param_lt_path_param_lt__item_id__get", "parameters": [ { - "required": True, - "schema": { - "title": "Item Id", - "exclusiveMaximum": 3.0, - "type": "number", - }, "name": "item_id", "in": "path", + "required": True, + "schema": { + "type": "number", + "exclusiveMaximum": 3, + "title": "Item Id", + }, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/path/param-lt0/{item_id}": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Path Param Lt0", "operationId": "get_path_param_lt0_path_param_lt0__item_id__get", "parameters": [ { - "required": True, - "schema": { - "title": "Item Id", - "exclusiveMaximum": 0.0, - "type": "number", - }, "name": "item_id", "in": "path", + "required": True, + "schema": { + "type": "number", + "exclusiveMaximum": 0, + "title": "Item Id", + }, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/path/param-le/{item_id}": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Path Param Le", "operationId": "get_path_param_le_path_param_le__item_id__get", "parameters": [ { - "required": True, - "schema": { - "title": "Item Id", - "maximum": 3.0, - "type": "number", - }, "name": "item_id", "in": "path", + "required": True, + "schema": { + "type": "number", + "maximum": 3, + "title": "Item Id", + }, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/path/param-lt-gt/{item_id}": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Path Param Lt Gt", "operationId": "get_path_param_lt_gt_path_param_lt_gt__item_id__get", "parameters": [ { - "required": True, - "schema": { - "title": "Item Id", - "exclusiveMaximum": 3.0, - "exclusiveMinimum": 1.0, - "type": "number", - }, "name": "item_id", "in": "path", + "required": True, + "schema": { + "type": "number", + "exclusiveMaximum": 3, + "exclusiveMinimum": 1, + "title": "Item Id", + }, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/path/param-le-ge/{item_id}": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Path Param Le Ge", "operationId": "get_path_param_le_ge_path_param_le_ge__item_id__get", "parameters": [ { - "required": True, - "schema": { - "title": "Item Id", - "maximum": 3.0, - "minimum": 1.0, - "type": "number", - }, "name": "item_id", "in": "path", + "required": True, + "schema": { + "type": "number", + "maximum": 3, + "minimum": 1, + "title": "Item Id", + }, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/path/param-lt-int/{item_id}": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Path Param Lt Int", "operationId": "get_path_param_lt_int_path_param_lt_int__item_id__get", "parameters": [ { - "required": True, - "schema": { - "title": "Item Id", - "exclusiveMaximum": 3.0, - "type": "integer", - }, "name": "item_id", "in": "path", + "required": True, + "schema": { + "type": "integer", + "exclusiveMaximum": 3, + "title": "Item Id", + }, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/path/param-gt-int/{item_id}": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Path Param Gt Int", "operationId": "get_path_param_gt_int_path_param_gt_int__item_id__get", "parameters": [ { - "required": True, - "schema": { - "title": "Item Id", - "exclusiveMinimum": 3.0, - "type": "integer", - }, "name": "item_id", "in": "path", + "required": True, + "schema": { + "type": "integer", + "exclusiveMinimum": 3, + "title": "Item Id", + }, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/path/param-le-int/{item_id}": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Path Param Le Int", "operationId": "get_path_param_le_int_path_param_le_int__item_id__get", "parameters": [ { - "required": True, - "schema": { - "title": "Item Id", - "maximum": 3.0, - "type": "integer", - }, "name": "item_id", "in": "path", + "required": True, + "schema": { + "type": "integer", + "maximum": 3, + "title": "Item Id", + }, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/path/param-ge-int/{item_id}": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Path Param Ge Int", "operationId": "get_path_param_ge_int_path_param_ge_int__item_id__get", "parameters": [ { - "required": True, - "schema": { - "title": "Item Id", - "minimum": 3.0, - "type": "integer", - }, "name": "item_id", "in": "path", + "required": True, + "schema": { + "type": "integer", + "minimum": 3, + "title": "Item Id", + }, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/path/param-lt-gt-int/{item_id}": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Path Param Lt Gt Int", "operationId": "get_path_param_lt_gt_int_path_param_lt_gt_int__item_id__get", "parameters": [ { - "required": True, - "schema": { - "title": "Item Id", - "exclusiveMaximum": 3.0, - "exclusiveMinimum": 1.0, - "type": "integer", - }, "name": "item_id", "in": "path", + "required": True, + "schema": { + "type": "integer", + "exclusiveMaximum": 3, + "exclusiveMinimum": 1, + "title": "Item Id", + }, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/path/param-le-ge-int/{item_id}": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Path Param Le Ge Int", "operationId": "get_path_param_le_ge_int_path_param_le_ge_int__item_id__get", "parameters": [ { - "required": True, - "schema": { - "title": "Item Id", - "maximum": 3.0, - "minimum": 1.0, - "type": "integer", - }, "name": "item_id", "in": "path", + "required": True, + "schema": { + "type": "integer", + "maximum": 3, + "minimum": 1, + "title": "Item Id", + }, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/query": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Query", "operationId": "get_query_query_get", "parameters": [ { - "required": True, - "schema": {"title": "Query"}, "name": "query", "in": "query", + "required": True, + "schema": {"title": "Query"}, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/query/optional": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Query Optional", "operationId": "get_query_optional_query_optional_get", "parameters": [ { - "required": False, - "schema": {"title": "Query"}, "name": "query", "in": "query", + "required": False, + "schema": {"title": "Query"}, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/query/int": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Query Type", "operationId": "get_query_type_query_int_get", "parameters": [ { - "required": True, - "schema": {"title": "Query", "type": "integer"}, "name": "query", "in": "query", + "required": True, + "schema": {"type": "integer", "title": "Query"}, } ], - } - }, - "/query/int/optional": { - "get": { "responses": { "200": { "description": "Successful Response", @@ -2168,6 +2143,10 @@ def test_openapi_schema(): }, }, }, + } + }, + "/query/int/optional": { + "get": { "summary": "Get Query Type Optional", "operationId": "get_query_type_optional_query_int_optional_get", "parameters": [ @@ -2175,114 +2154,106 @@ def test_openapi_schema(): "name": "query", "in": "query", "required": False, - "schema": IsDict( - { - "anyOf": [{"type": "integer"}, {"type": "null"}], - "title": "Query", - } - ) - # TODO: remove when deprecating Pydantic v1 - | IsDict({"title": "Query", "type": "integer"}), + "schema": { + "anyOf": [{"type": "integer"}, {"type": "null"}], + "title": "Query", + }, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/query/int/default": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Query Type Int Default", "operationId": "get_query_type_int_default_query_int_default_get", "parameters": [ { - "required": False, - "schema": { - "title": "Query", - "type": "integer", - "default": 10, - }, "name": "query", "in": "query", + "required": False, + "schema": { + "type": "integer", + "default": 10, + "title": "Query", + }, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/query/param": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Query Param", "operationId": "get_query_param_query_param_get", "parameters": [ { - "required": False, - "schema": {"title": "Query"}, "name": "query", "in": "query", + "required": False, + "schema": {"title": "Query"}, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/query/param-required": { "get": { - "responses": { - "200": { - "description": "Successful Response", - "content": {"application/json": {"schema": {}}}, - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - }, - }, "summary": "Get Query Param Required", "operationId": "get_query_param_required_query_param_required_get", "parameters": [ { - "required": True, - "schema": {"title": "Query"}, "name": "query", "in": "query", + "required": True, + "schema": {"title": "Query"}, } ], - } - }, - "/query/param-required/int": { - "get": { "responses": { "200": { "description": "Successful Response", @@ -2299,28 +2270,159 @@ def test_openapi_schema(): }, }, }, + } + }, + "/query/param-required/int": { + "get": { "summary": "Get Query Param Required Type", "operationId": "get_query_param_required_type_query_param_required_int_get", "parameters": [ { - "required": True, - "schema": {"title": "Query", "type": "integer"}, "name": "query", "in": "query", + "required": True, + "schema": {"type": "integer", "title": "Query"}, } ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, + } + }, + "/query/sequence-params": { + "get": { + "summary": "Get Sequence Query Params", + "operationId": "get_sequence_query_params_query_sequence_params_get", + "parameters": [ + { + "name": "query", + "in": "query", + "required": False, + "schema": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": {"type": "integer"}, + }, + "default": {}, + "title": "Query", + }, + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, + } + }, + "/query/mapping-params": { + "get": { + "summary": "Get Mapping Query Params", + "operationId": "get_mapping_query_params_query_mapping_params_get", + "parameters": [ + { + "name": "queries", + "in": "query", + "required": False, + "schema": { + "type": "object", + "additionalProperties": {"type": "string"}, + "default": {}, + "title": "Queries", + }, + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, + } + }, + "/query/mapping-sequence-params": { + "get": { + "summary": "Get Sequence Mapping Query Params", + "operationId": "get_sequence_mapping_query_params_query_mapping_sequence_params_get", + "parameters": [ + { + "name": "queries", + "in": "query", + "required": False, + "schema": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": {"type": "integer"}, + }, + "default": {}, + "title": "Queries", + }, + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": {"application/json": {"schema": {}}}, + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + }, + }, } }, "/enum-status-code": { "get": { + "summary": "Get Enum Status Code", + "operationId": "get_enum_status_code_enum_status_code_get", "responses": { "201": { "description": "Successful Response", "content": {"application/json": {"schema": {}}}, - }, + } }, - "summary": "Get Enum Status Code", - "operationId": "get_enum_status_code_enum_status_code_get", } }, "/query/frozenset": { @@ -2329,15 +2431,15 @@ def test_openapi_schema(): "operationId": "get_query_type_frozenset_query_frozenset_get", "parameters": [ { - "required": True, - "schema": { - "title": "Query", - "uniqueItems": True, - "type": "array", - "items": {"type": "integer"}, - }, "name": "query", "in": "query", + "required": True, + "schema": { + "type": "array", + "uniqueItems": True, + "items": {"type": "integer"}, + "title": "Query", + }, } ], "responses": { @@ -2361,32 +2463,32 @@ def test_openapi_schema(): }, "components": { "schemas": { - "ValidationError": { - "title": "ValidationError", - "required": ["loc", "msg", "type"], + "HTTPValidationError": { + "properties": { + "detail": { + "items": {"$ref": "#/components/schemas/ValidationError"}, + "type": "array", + "title": "Detail", + } + }, "type": "object", + "title": "HTTPValidationError", + }, + "ValidationError": { "properties": { "loc": { - "title": "Location", - "type": "array", "items": { "anyOf": [{"type": "string"}, {"type": "integer"}] }, - }, - "msg": {"title": "Message", "type": "string"}, - "type": {"title": "Error Type", "type": "string"}, - }, - }, - "HTTPValidationError": { - "title": "HTTPValidationError", - "type": "object", - "properties": { - "detail": { - "title": "Detail", "type": "array", - "items": {"$ref": "#/components/schemas/ValidationError"}, - } + "title": "Location", + }, + "msg": {"type": "string", "title": "Message"}, + "type": {"type": "string", "title": "Error Type"}, }, + "type": "object", + "required": ["loc", "msg", "type"], + "title": "ValidationError", }, } }, diff --git a/tests/test_query.py b/tests/test_query.py index 5bb9995d6..43f0a8038 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -408,3 +408,9 @@ def test_query_frozenset_query_1_query_1_query_2(): response = client.get("/query/frozenset/?query=1&query=1&query=2") assert response.status_code == 200 assert response.json() == "1,2" + + +def test_mapping_query(): + response = client.get("/query/mapping-params/?foo=fuzz&bar=buzz") + assert response.status_code == 200 + assert response.json() == "foo bar fuzz buzz"