You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using FastAPI, attempting to utilize the getEndpointSnippets function on an endpoint with an optional query parameter of enum type, which has a default value set, results in an error.
Reproduction Steps
Create an endpoint in a FastAPI application with an optional query parameter of enum type and assign a default value to this parameter.
Obtain the OpenAPI schema generated by FastAPI for this endpoint.
Try to generate snippets using getEndpointSnippets.
Example Scenario
Consider the following API endpoint:
classSortOrder(str, Enum):
ASCENDING="asc"DESCENDING="desc"@router.get("/v1/items",tags=["Catalog Integration"],summary="Get a list of item details",response_model=Success,)asyncdefitems(
request: Request,
start: int=Query(default=None, ge=0),
size: int=Query(default=None, ge=1, le=1000),
sort: SortOrder=Query(default=SortOrder.DESCENDING),
):
The generated OpenAPI schema for this endpoint might resemble the following:
/home/user/redoc_generation/node_modules/snippet-enricher-cli/node_modules/openapi-snippet/openapi-to-har.js:441
'SOME_' + (param.type || param.schema.type).toUpperCase() + '_VALUE';
^
TypeError: Cannot read properties of undefined (reading 'toUpperCase')
at getParameterValues (/home/user/redoc_generation/node_modules/snippet-enricher-cli/node_modules/openapi-snippet/openapi-to-har.js:441:49)
at parseParametersToQuery (/home/user/redoc_generation/node_modules/snippet-enricher-cli/node_modules/openapi-snippet/openapi-to-har.js:515:34)
at getParameterCollectionIn (/home/user/redoc_generation/node_modules/snippet-enricher-cli/node_modules/openapi-snippet/openapi-to-har.js:570:27)
at getQueryStrings (/home/user/redoc_generation/node_modules/snippet-enricher-cli/node_modules/openapi-snippet/openapi-to-har.js:603:10)
at Object.createHar [as getEndpoint] (/home/user/redoc_generation/node_modules/snippet-enricher-cli/node_modules/openapi-snippet/openapi-to-har.js:45:18)
at Object.getEndpointSnippets (/home/user/redoc_generation/node_modules/snippet-enricher-cli/node_modules/openapi-snippet/index.js:31:29)
at enrichSchema (/home/user/redoc_generation/node_modules/snippet-enricher-cli/index.js:18:39)
at /home/user/redoc_generation/node_modules/snippet-enricher-cli/index.js:52:12
at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)
Node.js v18.19.1
The text was updated successfully, but these errors were encountered:
afif-fahim
changed the title
getQueryStrings throws error with optional enum query param and default value (FastAPI 0.91.0)getParameterValues throws error with optional enum query param and default value (FastAPI 0.91.0)
Apr 29, 2024
Summary
When using FastAPI, attempting to utilize the
getEndpointSnippets
function on an endpoint with an optional query parameter of enum type, which has a default value set, results in an error.Reproduction Steps
getEndpointSnippets
.Example Scenario
Consider the following API endpoint:
The generated OpenAPI schema for this endpoint might resemble the following:
Error Stacktrace
The text was updated successfully, but these errors were encountered: