mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-10-03 20:20:35 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
})
|
||||
: [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user