UNPKG

turtle-express

Version:

`turtle-express` is kinda a framework or a library based on `express.js` with an opinionated express router with type safety and schema validation with zod. Also many [more features](https://github.com/mm-ninja-turtles/turtle-express/discussions/7) planni

36 lines 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.extendsZodWithOpenApi = void 0; const lodash_es_1 = require("lodash-es"); function extendsZodWithOpenApi(zod) { // zod object cannot be extend // so need to clone it first to extend with custom object const zodClone = (0, lodash_es_1.cloneDeep)(zod); // add open api request info to zod object function openApiRequest(options) { // extends with request type return Object.assign(options.schema, { _openApi: { title: options.title, type: options.type, }, }); } // add open api response info to zod object function openApiResponse(options) { // create extends object const _openApi = { title: options.title, type: 'Response', mediaType: options.mediaType ?? 'application/json', }; // extends with response type return Object.assign(options.schema, { _openApi, }); } // return extended zod object return Object.assign(zodClone, { openApiRequest, openApiResponse }); } exports.extendsZodWithOpenApi = extendsZodWithOpenApi; //# sourceMappingURL=zod-extends-openapi.js.map