(
*,
route: routing._APIRouteLike,
operation_ids: set[str],
model_name_map: ModelNameMap,
field_mapping: dict[
tuple[ModelField, Literal["validation", "serialization"]], dict[str, Any]
],
separate_input_output_schemas: bool = True,
)
| 258 | |
| 259 | |
| 260 | def get_openapi_path( |
| 261 | *, |
| 262 | route: routing._APIRouteLike, |
| 263 | operation_ids: set[str], |
| 264 | model_name_map: ModelNameMap, |
| 265 | field_mapping: dict[ |
| 266 | tuple[ModelField, Literal["validation", "serialization"]], dict[str, Any] |
| 267 | ], |
| 268 | separate_input_output_schemas: bool = True, |
| 269 | ) -> tuple[dict[str, Any], dict[str, Any], dict[str, Any]]: |
| 270 | path = {} |
| 271 | security_schemes: dict[str, Any] = {} |
| 272 | definitions: dict[str, Any] = {} |
| 273 | assert route.methods is not None, "Methods must be a list" |
| 274 | if isinstance(route.response_class, DefaultPlaceholder): |
| 275 | current_response_class: type[Response] = route.response_class.value |
| 276 | else: |
| 277 | current_response_class = route.response_class |
| 278 | assert current_response_class, "A response class is needed to generate OpenAPI" |
| 279 | route_response_media_type: str | None = current_response_class.media_type |
| 280 | if route.include_in_schema: |
| 281 | for method in route.methods: |
| 282 | operation = get_openapi_operation_metadata( |
| 283 | route=route, method=method, operation_ids=operation_ids |
| 284 | ) |
| 285 | parameters: list[dict[str, Any]] = [] |
| 286 | flat_dependant = get_flat_dependant(route.dependant, skip_repeats=True) |
| 287 | security_definitions, operation_security = get_openapi_security_definitions( |
| 288 | flat_dependant=flat_dependant |
| 289 | ) |
| 290 | if operation_security: |
| 291 | operation.setdefault("security", []).extend(operation_security) |
| 292 | if security_definitions: |
| 293 | security_schemes.update(security_definitions) |
| 294 | operation_parameters = _get_openapi_operation_parameters( |
| 295 | dependant=route.dependant, |
| 296 | model_name_map=model_name_map, |
| 297 | field_mapping=field_mapping, |
| 298 | separate_input_output_schemas=separate_input_output_schemas, |
| 299 | ) |
| 300 | parameters.extend(operation_parameters) |
| 301 | if parameters: |
| 302 | all_parameters = { |
| 303 | (param["in"], param["name"]): param for param in parameters |
| 304 | } |
| 305 | required_parameters = { |
| 306 | (param["in"], param["name"]): param |
| 307 | for param in parameters |
| 308 | if param.get("required") |
| 309 | } |
| 310 | # Make sure required definitions of the same parameter take precedence |
| 311 | # over non-required definitions |
| 312 | all_parameters.update(required_parameters) |
| 313 | operation["parameters"] = list(all_parameters.values()) |
| 314 | if method in METHODS_WITH_BODY: |
| 315 | request_body_oai = get_openapi_operation_request_body( |
| 316 | body_field=route.body_field, |
| 317 | model_name_map=model_name_map, |
no test coverage detected
searching dependent graphs…