Yasin
5 days ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
6 additions and
1 deletions
-
docs/en/docs/how-to/extending-openapi.md
-
fastapi/_compat.py
-
fastapi/openapi/utils.py
|
|
@ -26,6 +26,7 @@ And that function `get_openapi()` receives as parameters: |
|
|
|
* `summary`: A short summary of the API. |
|
|
|
* `description`: The description of your API, this can include markdown and will be shown in the docs. |
|
|
|
* `routes`: A list of routes, these are each of the registered *path operations*. They are taken from `app.routes`. |
|
|
|
* `field_names_by_alias`: A boolean indicating whether to use the field names or the alias names for the models. |
|
|
|
|
|
|
|
/// info |
|
|
|
|
|
|
|
|
|
@ -363,6 +363,7 @@ else: |
|
|
|
@dataclass |
|
|
|
class GenerateJsonSchema: # type: ignore[no-redef] |
|
|
|
ref_template: str |
|
|
|
by_alias: bool = True |
|
|
|
|
|
|
|
class PydanticSchemaGenerationError(Exception): # type: ignore[no-redef] |
|
|
|
pass |
|
|
|
|
|
@ -489,6 +489,7 @@ def get_openapi( |
|
|
|
contact: Optional[Dict[str, Union[str, Any]]] = None, |
|
|
|
license_info: Optional[Dict[str, Union[str, Any]]] = None, |
|
|
|
separate_input_output_schemas: bool = True, |
|
|
|
field_names_by_alias: bool = True, |
|
|
|
) -> Dict[str, Any]: |
|
|
|
info: Dict[str, Any] = {"title": title, "version": version} |
|
|
|
if summary: |
|
|
@ -510,7 +511,9 @@ def get_openapi( |
|
|
|
operation_ids: Set[str] = set() |
|
|
|
all_fields = get_fields_from_routes(list(routes or []) + list(webhooks or [])) |
|
|
|
model_name_map = get_compat_model_name_map(all_fields) |
|
|
|
schema_generator = GenerateJsonSchema(ref_template=REF_TEMPLATE) |
|
|
|
schema_generator = GenerateJsonSchema( |
|
|
|
ref_template=REF_TEMPLATE, by_alias=field_names_by_alias |
|
|
|
) |
|
|
|
field_mapping, definitions = get_definitions( |
|
|
|
fields=all_fields, |
|
|
|
schema_generator=schema_generator, |
|
|
|