@seamapi/blueprint
Version:
Build tools for the Seam API using this blueprint.
24 lines • 1.04 kB
JavaScript
export function findCommonOpenapiSchemaProperties(schemas) {
const firstSchema = schemas[0];
if (schemas.length === 0 || firstSchema?.properties == null) {
return {};
}
return Object.entries(firstSchema.properties).reduce((commonProps, [propKey, propValue]) => {
const isPropInAllSchemas = schemas.every((schema) => Object.keys(schema.properties ?? {}).includes(propKey));
if (!isPropInAllSchemas) {
return commonProps;
}
if ('enum' in propValue) {
const mergedEnumValues = schemas.reduce((allEnums, schema) => {
const enumValues = schema.properties?.[propKey]?.enum ?? [];
return [...new Set([...allEnums, ...enumValues])];
}, []);
return {
...commonProps,
[propKey]: { ...propValue, enum: mergedEnumValues },
};
}
return { ...commonProps, [propKey]: propValue };
}, {});
}
//# sourceMappingURL=find-common-openapi-schema-properties.js.map