Explained below.
import json
from litestar import Litestar, post
from litestar.openapi.spec import Example
from litestar.params import Parameter
@post("/{path_arg:str}")
def endpoint(
path_arg: str = Parameter(examples=[Example(value="EXAMPLE_VALUE")]),
) -> None:
pass
app = Litestar(route_handlers=[endpoint])
print(json.dumps(app.openapi_schema.to_schema(), indent=4))
The generated schema contains:
{
"name": "path_arg",
"in": "path",
"schema": {
"type": "string",
"examples": { <------- HERE
"path_arg-example-1": {
"value": "EXAMPLE_VALUE"
}
}
},
"required": true,
"deprecated": false,
"allowEmptyValue": false,
"allowReserved": false,
"examples": { <------- HERE
"path_arg-example-1": {
"value": "EXAMPLE_VALUE"
}
}
}
I would expect one occurrence is sufficient. The example was given for/as OpenAPI path parameter (via Parameter
) so the latter is correct, and the JSON schema example (former one) can be dropped.
1. `python app.py`
2. See the generated schema
No response
No response
2.5.1
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too