Open thim81 opened 2 months ago
I think, it would make sense to provide an explicit merge instruction for the "parameters".
This will handle that the parameters are merged intelligently by checking for existing parameters with the same name and path location (in: query in this case)
Something like this?
jsonpath.apply(spec, target, (chunk) => {
if (typeof chunk === 'object' && typeof action.update === 'object') {
if (Array.isArray(chunk) && Array.isArray(action.update)) {
// Handle array merging carefully to avoid duplicating parameters
if (target.includes('parameters')) {
// Merge the parameters array by checking if parameter already exists
const mergedParameters = [...chunk];
action.update.forEach((newParam: any) => {
const existingParamIndex = mergedParameters.findIndex(
(p: any) => p.name === newParam.name && p.in === newParam.in
);
if (existingParamIndex > -1) {
// Update the existing parameter
mergedParameters[existingParamIndex] = merger(mergedParameters[existingParamIndex], newParam);
} else {
// Add the new parameter if it doesn't exist
mergedParameters.push(newParam);
}
});
return mergedParameters;
} else {
// For arrays that are not parameters, just concatenate
return chunk.concat(action.update);
}
} else {
return merger(chunk, action.update);
}
} else {
return action.update;
}
});
Steps to reproduce
Openapi.yaml
overlays.yaml
execute:
bump overlay openapi.yaml overlays.yaml > openapi.public.yam
lResult in:
Expected result