UNPKG

openapi-graph-core

Version:

A TS library to manage large API projects defined by OpenAPIv3 specification.

49 lines (48 loc) 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Edge = void 0; const openapi_graph_types_1 = require("openapi-graph-types"); const path_1 = require("path"); const Edge = class EdgeImpl { constructor(filePath, specificationPath) { // TODO: Check that inputs are valid this.filePath = filePath; this.rawPath = specificationPath; const cleanSpecificationPathParts = specificationPath?.split('#'); if (cleanSpecificationPathParts.length < 2) { return; } this.specificationPath = cleanSpecificationPathParts[1]; switch (this.type) { case openapi_graph_types_1.RefType.Local: case openapi_graph_types_1.RefType.URL: this.refToFilePath = path_1.resolve(`${filePath}/${cleanSpecificationPathParts[0]}`); break; case openapi_graph_types_1.RefType.Remote: this.refToFilePath = path_1.resolve(`${filePath}/../${cleanSpecificationPathParts[0]}`); break; } const specificationPathParts = specificationPath.split('/'); this.tokenName = specificationPathParts[specificationPathParts.length - 1]; } get path() { return `${this.filePath}#${this.specificationPath}`; } // TODO Tests get type() { // Test if extension file is in the string if (/\.(yml|yaml|json)\/?#\//.test(this.rawPath)) { if (/^https?:\/\//.test(this.rawPath)) { return openapi_graph_types_1.RefType.URL; } else { return openapi_graph_types_1.RefType.Remote; } } else if (!/\.(yml|yaml|json)\/?#\//.test(this.rawPath)) { return openapi_graph_types_1.RefType.Local; } return undefined; } }; exports.Edge = Edge;