UNPKG

@opra/common

Version:
37 lines (36 loc) 1.11 kB
import { ResponsiveMap } from '../../helpers/index.js'; import { ApiBase } from '../common/api-base.js'; import { HttpController } from './http-controller.js'; /** * @class HttpApi */ export class HttpApi extends ApiBase { constructor(init) { super(init); // noinspection JSUnusedGlobalSymbols this._controllerReverseMap = new WeakMap(); this.transport = 'http'; this.controllers = new ResponsiveMap(); this.url = init.url; } findController(arg0) { return HttpController.prototype.findController.call(this, arg0); } findOperation(arg0, operationName) { const controller = this.findController(arg0); return controller?.operations.get(operationName); } toJSON(options) { const schema = super.toJSON(); const out = { ...schema, transport: this.transport, url: this.url, controllers: {}, }; for (const v of this.controllers.values()) { out.controllers[v.name] = v.toJSON(options); } return out; } }