/************************************************************************* * * Troven CONFIDENTIAL * __________________ * * (c) 2017-2020 Troven Ventures Pty Ltd * All Rights Reserved. * * NOTICE: All information contained herein is, and remains * the property of Troven Pty Ltd and its licensors, * if any. The intellectual and technical concepts contained * herein are proprietary to Troven Pty Ltd * and its suppliers and may be covered by International and Regional Patents, * patents in process, and are protected by trade secret or copyright law. * Dissemination of this information or reproduction of this material * is strictly forbidden unless prior written permission is obtained * from Troven Pty Ltd. */ import * as _ from "lodash"; import {IChassisContext, IOpenAPIv3} from "../interfaces"; import { Operation } from "./Operation"; import { Security } from "./Security"; // import APIError from "../core/APIError"; // import {Request, Response} from "express"; export class Paths { context: IChassisContext; security: Security; ops: {} = {}; /** * Process Open API v2/v3 path specification * * @param {IChassisContext} context * @param {Security} security */ constructor(context: IChassisContext, security: Security) { this.context = context; this.security = security; } public operations(): Operation[] { // TODO: sort by operationId or path / verb return _.values( this.ops ); } public resources = function(openapi: IOpenAPIv3) { let paths = openapi.paths || []; // for each resource path .. we build our pipelines _.each(paths, this._path_operations.bind(this) ); }; _path_operations = function(operations: any, resource: string) { delete operations.methods; // hack fix?? let self = this; _.each(operations, function(oper, method) { let operation = new Operation(self.context, method, resource, oper ); self.add(operation); }); } public add(operation: Operation) { // if (this.ops[operation.operationId]) throw new APIError(500, { code: "api:openapi:operation:duplicate", operationId: operation.operationId}); this.ops[operation.operationId] = operation; operation.response; } }