UNPKG

json-api-nestjs

Version:
99 lines 4.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SwaggerService = void 0; const tslib_1 = require("tslib"); const common_1 = require("@nestjs/common"); const core_1 = require("@nestjs/core"); const swagger_1 = require("@nestjs/swagger"); const zod_openapi_1 = require("@anatine/zod-openapi"); const controllers_1 = require("../controllers"); const constants_1 = require("../constants"); let SwaggerService = class SwaggerService { moduleRef; typeZodInputOperation; initSwagger() { const operationControllerInst = this.moduleRef.get(controllers_1.OperationController); if (!operationControllerInst) throw new Error('OperationController not found'); const controller = operationControllerInst.constructor.prototype; const descriptor = Reflect.getOwnPropertyDescriptor(controller, 'index'); if (!descriptor) throw new Error(`Descriptor for controller OperationController is empty`); (0, swagger_1.ApiTags)('Atomic operation')(operationControllerInst.constructor); (0, swagger_1.ApiOperation)({ summary: `Atomic operation for several entity"`, operationId: `atomic_operation`, })(controller, 'index', descriptor); (0, swagger_1.ApiBody)({ description: `Json api schema for new atomic operatiom`, schema: (0, zod_openapi_1.generateSchema)(this.typeZodInputOperation), required: true, examples: { allField: { summary: 'Examples several operation', description: 'Examples several operation', value: { ['atomic:operations']: [ { op: 'add', ref: { type: 'users', }, data: 'EntityPostOne', }, { op: 'update', ref: { type: 'users', id: '1', }, data: 'EntityPatchOne', }, { op: 'remove', ref: { type: 'users', id: '1', }, }, { op: 'add', ref: { type: 'users', id: '1', relationship: 'EntityRelationName', }, data: 'UsersPostRelationship', }, { op: 'update', ref: { type: 'users', id: '1', relationship: 'EntityRelationName', }, data: 'UsersDeleteRelationship', }, ], }, }, }, })(controller, 'index', descriptor); } onModuleInit() { this.initSwagger(); } }; exports.SwaggerService = SwaggerService; tslib_1.__decorate([ (0, common_1.Inject)(core_1.ModuleRef), tslib_1.__metadata("design:type", core_1.ModuleRef) ], SwaggerService.prototype, "moduleRef", void 0); tslib_1.__decorate([ (0, common_1.Inject)(constants_1.ZOD_INPUT_OPERATION), tslib_1.__metadata("design:type", Object) ], SwaggerService.prototype, "typeZodInputOperation", void 0); exports.SwaggerService = SwaggerService = tslib_1.__decorate([ (0, common_1.Injectable)() ], SwaggerService); //# sourceMappingURL=swagger.service.js.map