UNPKG

arrest

Version:

OpenAPI v3 compliant REST framework for Node.js, with support for MongoDB and JSON-Schema

56 lines 1.61 kB
import { API } from './api.js'; import { Operation } from './operation.js'; import { Resource } from './resource.js'; export class SchemaResource extends Resource { constructor() { super({ name: 'Schema', }, { '/:id': { get: ReadSchemaOperation, }, }); } } class ReadSchemaOperation extends Operation { constructor(resource, path, method) { super(resource, path, method, 'read'); } getCustomInfo() { return { summary: 'Retrieve a JSON Schema by id', parameters: [ { $ref: '#/components/parameters/id', }, ], responses: { '200': { description: 'The requested JSON Schema', content: { 'application/json': { schema: { type: 'object', }, }, }, }, '404': { $ref: '#/components/responses/notFound' }, default: { $ref: '#/components/responses/defaultError' }, }, }; } get swaggerScopes() { return {}; } handler(req, res, next) { const schema = this.api.originalSchemas[req.params.id]; if (schema) { res.json(schema); } else { this.api.handleError(API.newError(404, 'not_found'), req, res); } } } //# sourceMappingURL=schema.js.map