mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 23:55:20 +00:00
Deduplicate path parameters from OpenAPI spec (#3264)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@gitbook/react-openapi': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Deduplicate path parameters from OpenAPI spec
|
||||||
@@ -18,7 +18,7 @@ export function OpenAPISpec(props: {
|
|||||||
|
|
||||||
const { operation } = data;
|
const { operation } = data;
|
||||||
|
|
||||||
const parameters = operation.parameters ?? [];
|
const parameters = deduplicateParameters(operation.parameters ?? []);
|
||||||
const parameterGroups = groupParameters(parameters, context);
|
const parameterGroups = groupParameters(parameters, context);
|
||||||
|
|
||||||
const securities = 'securities' in data ? data.securities : [];
|
const securities = 'securities' in data ? data.securities : [];
|
||||||
@@ -113,3 +113,23 @@ function getParameterGroupName(paramIn: string, context: OpenAPIClientContext):
|
|||||||
return paramIn;
|
return paramIn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 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.
|
||||||
|
*/
|
||||||
|
function deduplicateParameters(parameters: OpenAPI.Parameters): OpenAPI.Parameters {
|
||||||
|
const seen = new Set();
|
||||||
|
|
||||||
|
return parameters.filter((param) => {
|
||||||
|
const key = `${param.name}:${param.in}`;
|
||||||
|
|
||||||
|
if (seen.has(key)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
seen.add(key);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user