@nestjs/swagger
Version:
OpenAPI for NestJS: generate the API document from controllers and decorators, serve Swagger UI, and derive request types with mapped types.
12 lines (11 loc) • 505 B
JavaScript
import isUndefined from 'es-toolkit/compat/isUndefined';
import omitBy from 'es-toolkit/compat/omitBy';
export function wrapRefInAllOf(schema, extraAllOf = []) {
const { $ref, allOf, ...siblings } = schema;
const rest = omitBy(siblings, isUndefined);
const allOfEntries = [...(Array.isArray(allOf) ? allOf : []), ...extraAllOf];
if (Object.keys(rest).length === 0 && allOfEntries.length === 0) {
return { $ref };
}
return { ...rest, allOf: [...allOfEntries, { $ref }] };
}