The get_required_params method from the OpenAPIToScanAPIConverter class is used during OpenAPI schema convertion to find out which parameters are required for a given endpoint.
For most cases, the required parameters are actually path parameters. In this example OpenAI schema. {character_id} is considered a required parameter:
...
"/api/characters/{character_id}": {
"get": {
"tags": [
"characters"
],
"summary": "Character",
"description": "...",
"parameters": [
{
"name": "character_id",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"maximum": 2147483647,
"title": "Character Id"
}
}
],
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/GetCharacterResponse"
}
}
}
},
...
The method essentially reads the parameters key from the endpoint and loops over the array. If any parameter has the required key set to True, we consider it a required parameter.
For each required parameter, we return its name and location (in).
Objective
We need to understand whether the name key is always present, and what should be do when it is a "falsy" value, such as an empty string, for example.
The example below is valid OpenAPI spec:
"/api/characters/{ }": {
"get": {
"tags": [
"characters"
],
"summary": "Character",
"description": "Retrieve specific character.\n\nThis endpoint enables users to retrieve detailed information about a specific Futurama character by providing\ntheir unique ID. The response will include essential details such as the character's name, status,\ngender, species, image, and other relevant details.\n\nCan be used to utilize this endpoint to obtain in-depth insights\ninto a particular character from the Futurama universe.",
"operationId": "character_api_characters__character_id__get",
"parameters": [
{
"name": " ",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"maximum": 2147483647,
"title": "Character Id"
}
}
],
(the parameter name was substituted for a single space ).
Notes
I don't think this is a real issue atm because our validator enforces two rules regarding path names:
- It must match the path variable
- It must not be empty (although a single space is considered ok)
Error when the path variable and the parameter name do not match:
Couldn't parse OpenAPI schema: ("Path parameter 'character_id' for 'get' operation in '/api/characters/{character_id}' was not resolved", , (), None, (), , , , (),
None)
Error when the path variable is empty:
Couldn't parse OpenAPI schema: ("'' does not match '[^/#?]+$'", 'pattern', deque(['paths', '/api/characters/{}', 'get', 'parameters', 0, 'name']), None, [], '[^/#?]+$', '', {'pattern':
'[^/#?]+$'}, deque(['properties', 'paths', 'patternProperties', '^/', 'else', 'properties', 'get', 'properties', 'parameters', 'items', 'else', 'dependentSchemas', 'schema', 'allOf', 1, 'then',
'properties', 'name', 'pattern']), None)
References
OpenAPI 3.x docs: https://swagger.io/docs/specification/v3_0/describing-parameters/#path-parameters.
The
get_required_paramsmethod from theOpenAPIToScanAPIConverterclass is used during OpenAPI schema convertion to find out which parameters are required for a given endpoint.For most cases, the required parameters are actually path parameters. In this example OpenAI schema.
{character_id}is considered a required parameter:The method essentially reads the
parameterskey from the endpoint and loops over the array. If any parameter has therequiredkey set toTrue, we consider it a required parameter.For each required parameter, we return its
nameand location (in).Objective
We need to understand whether the
namekey is always present, and what should be do when it is a "falsy" value, such as an empty string, for example.The example below is valid OpenAPI spec:
(the parameter name was substituted for a single space
).Notes
I don't think this is a real issue atm because our validator enforces two rules regarding path names:
Error when the path variable and the parameter name do not match:
Error when the path variable is empty:
References
OpenAPI 3.x docs: https://swagger.io/docs/specification/v3_0/describing-parameters/#path-parameters.