Fix error on parameters being an object instead of an array (#3623)

Co-authored-by: Nicolas Dorseuil <nicolas@gitbook.io>
This commit is contained in:
conico974
2025-09-05 16:17:50 +02:00
committed by GitHub
parent 791135040a
commit ccc0975240
2 changed files with 16 additions and 9 deletions
@@ -66,7 +66,11 @@ function generateCodeSamples(props: {
const searchParams = new URLSearchParams();
const headersObject: { [k: string]: string } = {};
data.operation.parameters?.forEach((param) => {
// The parser can sometimes returns invalid parameters (an object instead of an array).
// It should get fixed in scalar, but in the meantime we just ignore the parameters in that case.
const params = Array.isArray(data.operation.parameters) ? data.operation.parameters : [];
params.forEach((param) => {
if (!param) {
return;
}
+11 -8
View File
@@ -117,19 +117,22 @@ function getParameterGroupName(paramIn: string, context: OpenAPIClientContext):
/** Deduplicate parameters by name and in.
* Some specs have both parameters define at path and operation level.
* We only want to display one of them.
* Parameters can have the wrong type (object instead of array) sometimes, we just return an empty array in that case.
*/
function deduplicateParameters(parameters: OpenAPI.Parameters): OpenAPI.Parameters {
const seen = new Set();
return parameters.filter((param) => {
const key = `${param.name}:${param.in}`;
return Array.isArray(parameters)
? parameters.filter((param) => {
const key = `${param.name}:${param.in}`;
if (seen.has(key)) {
return false;
}
if (seen.has(key)) {
return false;
}
seen.add(key);
seen.add(key);
return true;
});
return true;
})
: [];
}