-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Closed
Labels
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The generator adds default values to path parameters, which FastAPI does not like.
openapi-generator version
v7.0.0-beta
OpenAPI declaration file content or url
{
"openapi": "3.0.0",
"paths": {
"/project/{projectId}/status": {
"post": {
"operationId": "ProjectController_projectStatus",
"summary": "Notify of changes in the project",
"description": "Synchronous endpoint. Platform Api would call this endpoint to notify any changes made to a project.",
"parameters": [
{
"name": "projectId",
"required": true,
"in": "path",
"description": "Globally unique ID of an project across time",
"example": "1bd98aa5-5a83-4bf3-97a2-a8a7e444c73e",
"schema": {
"type": "string"
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProjectStatusRequestBodyDto"
}
}
}
},
"responses": {
"200": {
"description": "OK"
},
},
"tags": [
"Project related endpoints"
]
}
}
},
"info": {
"title": "Asset API Specification",
"description": "API Specification that an asset has to implement in order to integrate with the Platform.",
"version": "1.0.0",
"contact": {}
},
"tags": [],
"servers": [
{
"url": "dummy"
}
]
}This yields
# FastAPI does not like the `None` below, it should be `...`
projectId: str = Path(None, description="Globally unique ID of an project across time"),This check is explicitly codified in the FastAPI source code:
https://github.com/tiangolo/fastapi/blob/master/fastapi/params.py
i.e.,
class Path(Param):
in_ = ParamTypes.path
def __init__(
self,
default: Any = ...,
*,
alias: Optional[str] = None,
title: Optional[str] = None,
description: Optional[str] = None,
gt: Optional[float] = None,
ge: Optional[float] = None,
lt: Optional[float] = None,
le: Optional[float] = None,
min_length: Optional[int] = None,
max_length: Optional[int] = None,
regex: Optional[str] = None,
examples: Optional[List[Any]] = None,
example: Annotated[
Optional[Any],
deprecated(
"Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
"although still supported. Use examples instead."
),
] = Undefined,
deprecated: Optional[bool] = None,
include_in_schema: bool = True,
**extra: Any,
):
assert default is ..., "Path parameters cannot have a default value"
...Generation Details
Steps to reproduce
- Use config above to generate with FastAPI generator
- See generated output
Suggest a fix
Ensure default path params are always set to ...
Reactions are currently unavailable