@anatine/zod-nestjs
Version:
Zod helper methods for NestJS
34 lines • 1.6 kB
JavaScript
;
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/ban-types */
Object.defineProperty(exports, "__esModule", { value: true });
exports.patchNestjsSwagger = void 0;
/**
* This file was copied from:
* https://github.com/kbkk/abitia/blob/master/packages/zod-dto/src/OpenApi/patchNestjsSwagger.ts
*/
const zod_openapi_1 = require("@anatine/zod-openapi");
const patchNestjsSwagger = (schemaObjectFactoryModule = require('@nestjs/swagger/dist/services/schema-object-factory')) => {
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/naming-convention
const { SchemaObjectFactory } = schemaObjectFactoryModule;
const orgExploreModelSchema = SchemaObjectFactory.prototype.exploreModelSchema;
SchemaObjectFactory.prototype.exploreModelSchema = function (type, schemas, // TODO : Figure out what schemas actually are.
schemaRefsStack = []
// type: Type<unknown> | Function | any,
// schemas: Record<string, SchemaObject>,
// schemaRefsStack: string[] = []
) {
if (this.isLazyTypeFunc(type)) {
// eslint-disable-next-line @typescript-eslint/ban-types
type = type();
}
if (!type.zodSchema) {
return orgExploreModelSchema.call(this, type, schemas, schemaRefsStack);
}
const openApiDef = (0, zod_openapi_1.generateSchema)(type.zodSchema);
schemas[type.name] = openApiDef;
return type.name;
};
};
exports.patchNestjsSwagger = patchNestjsSwagger;
//# sourceMappingURL=patch-nest-swagger.js.map