Skip to content

Commit

Permalink
Remove unecessary parameters in functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsil committed Jul 11, 2023
1 parent 8971ff6 commit c2133aa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 31 deletions.
10 changes: 2 additions & 8 deletions esmerald/_openapi/_utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from enum import Enum
from typing import Any, Dict, List, Set, Tuple, Type, Union
from typing import Any, Dict, List, Tuple, Union

from pydantic import BaseModel, TypeAdapter
from pydantic import TypeAdapter
from pydantic.fields import FieldInfo
from pydantic.json_schema import GenerateJsonSchema, JsonSchemaValue
from pydantic.v1.schema import field_schema, model_process_schema
from typing_extensions import Literal

from esmerald._openapi.constants import REF_PREFIX
from esmerald.typing import ModelMap

validation_error_definition = {
"title": "ValidationError",
Expand Down Expand Up @@ -51,7 +48,6 @@ def get_definitions(
*,
fields: List[FieldInfo],
schema_generator: GenerateJsonSchema,
model_name_map: ModelMap,
) -> Tuple[
Dict[Tuple[FieldInfo, Literal["validation", "serialization"]], JsonSchemaValue],
Dict[str, Dict[str, Any]],
Expand All @@ -64,8 +60,6 @@ def get_definitions(
def get_schema_from_model_field(
*,
field: FieldInfo,
schema_generator: GenerateJsonSchema,
model_name_map: ModelMap,
field_mapping: Dict[Tuple[FieldInfo, Literal["validation", "serialization"]], JsonSchemaValue],
) -> Dict[str, Any]:
json_schema = field_mapping[(field, "validation")]
Expand Down
24 changes: 1 addition & 23 deletions esmerald/_openapi/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from esmerald.enums import MediaType
from esmerald.params import Body, Param
from esmerald.routing import gateways, router
from esmerald.typing import ModelMap, Undefined
from esmerald.typing import Undefined
from esmerald.utils.constants import DATA
from esmerald.utils.url import clean_path

Expand Down Expand Up @@ -69,10 +69,6 @@ def get_fields_from_routes(
return list(body_fields + response_from_routes + request_fields)


def get_compat_model_name_map(all_fields: List[FieldInfo]) -> ModelMap:
return {}


def get_openapi_operation(
*, route: router.HTTPHandler, method: str, operation_ids: Set[str]
) -> Dict[str, Any]:
Expand Down Expand Up @@ -103,8 +99,6 @@ def get_openapi_operation(
def get_openapi_operation_parameters(
*,
all_route_params: Sequence[FieldInfo],
schema_generator: GenerateJsonSchema,
model_name_map: ModelMap,
field_mapping: Dict[Tuple[FieldInfo, Literal["validation", "serialization"]], JsonSchemaValue],
) -> List[Dict[str, Any]]:
parameters = []
Expand All @@ -115,8 +109,6 @@ def get_openapi_operation_parameters(

param_schema = get_schema_from_model_field(
field=param,
schema_generator=schema_generator,
model_name_map=model_name_map,
field_mapping=field_mapping,
)
parameter = {
Expand All @@ -138,8 +130,6 @@ def get_openapi_operation_parameters(
def get_openapi_operation_request_body(
*,
data_field: Optional[FieldInfo],
schema_generator: GenerateJsonSchema,
model_name_map: ModelMap,
field_mapping: Dict[Tuple[FieldInfo, Literal["validation", "serialization"]], JsonSchemaValue],
) -> Optional[Dict[str, Any]]:
if not data_field:
Expand All @@ -148,8 +138,6 @@ def get_openapi_operation_request_body(
assert isinstance(data_field, FieldInfo), "The 'data' needs to be a FieldInfo"
schema = get_schema_from_model_field(
field=data_field,
schema_generator=schema_generator,
model_name_map=model_name_map,
field_mapping=field_mapping,
)

Expand All @@ -172,8 +160,6 @@ def get_openapi_path(
*,
route: gateways.Gateway,
operation_ids: Set[str],
schema_generator: GenerateJsonSchema,
model_name_map: ModelMap,
field_mapping: Dict[Tuple[FieldInfo, Literal["validation", "serialization"]], JsonSchemaValue],
) -> Tuple[Dict[str, Any], Dict[str, Any], Dict[str, Any]]:
path = {}
Expand Down Expand Up @@ -220,8 +206,6 @@ def get_openapi_path(
all_route_params = get_flat_params(handler)
operation_parameters = get_openapi_operation_parameters(
all_route_params=all_route_params,
schema_generator=schema_generator,
model_name_map=model_name_map,
field_mapping=field_mapping,
)
parameters.extend(operation_parameters)
Expand All @@ -239,8 +223,6 @@ def get_openapi_path(
if method in METHODS_WITH_BODY:
request_data_oai = get_openapi_operation_request_body(
data_field=handler.data_field,
schema_generator=schema_generator,
model_name_map=model_name_map,
field_mapping=field_mapping,
)
if request_data_oai:
Expand Down Expand Up @@ -366,12 +348,10 @@ def get_openapi(
paths: Dict[str, Dict[str, Any]] = {}
operation_ids: Set[str] = set()
all_fields = get_fields_from_routes(list(routes or []))
model_name_map = get_compat_model_name_map(all_fields)
schema_generator = GenerateJsonSchema(ref_template=REF_TEMPLATE)
field_mapping, definitions = get_definitions(
fields=all_fields,
schema_generator=schema_generator,
model_name_map=model_name_map,
)

# Iterate through the routes
Expand Down Expand Up @@ -399,8 +379,6 @@ def iterate_routes(
result = get_openapi_path(
route=route,
operation_ids=operation_ids,
schema_generator=schema_generator,
model_name_map=model_name_map,
field_mapping=field_mapping,
)
if result:
Expand Down

0 comments on commit c2133aa

Please sign in to comment.