mirror of https://github.com/tiangolo/fastapi.git
add: option to generate api specification by field name instead of alias
This commit is contained in:
parent
480620372a
commit
f507a77a43
|
|
@ -26,6 +26,7 @@ And that function `get_openapi()` receives as parameters:
|
||||||
* `summary`: A short summary of the API.
|
* `summary`: A short summary of the API.
|
||||||
* `description`: The description of your API, this can include markdown and will be shown in the docs.
|
* `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`.
|
* `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
|
!!! info
|
||||||
The parameter `summary` is available in OpenAPI 3.1.0 and above, supported by FastAPI 0.99.0 and above.
|
The parameter `summary` is available in OpenAPI 3.1.0 and above, supported by FastAPI 0.99.0 and above.
|
||||||
|
|
|
||||||
|
|
@ -450,6 +450,7 @@ def get_openapi(
|
||||||
contact: Optional[Dict[str, Union[str, Any]]] = None,
|
contact: Optional[Dict[str, Union[str, Any]]] = None,
|
||||||
license_info: Optional[Dict[str, Union[str, Any]]] = None,
|
license_info: Optional[Dict[str, Union[str, Any]]] = None,
|
||||||
separate_input_output_schemas: bool = True,
|
separate_input_output_schemas: bool = True,
|
||||||
|
field_names_by_alias: bool = True,
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
info: Dict[str, Any] = {"title": title, "version": version}
|
info: Dict[str, Any] = {"title": title, "version": version}
|
||||||
if summary:
|
if summary:
|
||||||
|
|
@ -471,7 +472,9 @@ def get_openapi(
|
||||||
operation_ids: Set[str] = set()
|
operation_ids: Set[str] = set()
|
||||||
all_fields = get_fields_from_routes(list(routes or []) + list(webhooks or []))
|
all_fields = get_fields_from_routes(list(routes or []) + list(webhooks or []))
|
||||||
model_name_map = get_compat_model_name_map(all_fields)
|
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(
|
field_mapping, definitions = get_definitions(
|
||||||
fields=all_fields,
|
fields=all_fields,
|
||||||
schema_generator=schema_generator,
|
schema_generator=schema_generator,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue