openapi-graph-core
Advanced tools
Comparing version 0.0.1-alpha.2.0 to 0.0.1-alpha.2.1.0
@@ -1,2 +0,2 @@ | ||
import { OpenAPIGraph } from "../OpenAPIGraph"; | ||
import { OpenAPIGraph } from '../OpenAPIGraph'; | ||
export declare function connectRefNodes(graph: OpenAPIGraph): OpenAPIGraph; |
@@ -10,3 +10,3 @@ import { OpenAPIV3 } from 'openapi-types'; | ||
*/ | ||
export declare function getSchemaNodes(apiContent: OpenAPIV3.Document): Nodes["schemas"]; | ||
export declare function getSchemaNodes(apiContent: OpenAPIV3.Document): Nodes['schemas']; | ||
/** | ||
@@ -13,0 +13,0 @@ * It will find all the references defined in the specification |
@@ -16,3 +16,3 @@ "use strict"; | ||
if (schemas) { | ||
Object.keys(schemas).forEach(schema => { | ||
Object.keys(schemas).forEach((schema) => { | ||
if ('$ref' !== schema) { | ||
@@ -43,10 +43,10 @@ nodes[schema] = new SchemaNode_1.SchemaNode(schema, schemas[schema]); | ||
function handleJson() { | ||
Object.keys(json).forEach(key => { | ||
Object.keys(json).forEach((key) => { | ||
edges = getRefEdges(json[key], absolutePath, edges); | ||
}); | ||
} | ||
if (({}).constructor === json.constructor) { | ||
if ({}.constructor === json.constructor) { | ||
handleJson(); | ||
} | ||
else if (([]).constructor === json.constructor) { | ||
else if ([].constructor === json.constructor) { | ||
json.forEach(handleJson); | ||
@@ -60,8 +60,8 @@ } | ||
const filteredRefs = { | ||
schemaRef: {} | ||
schemaRef: {}, | ||
}; | ||
Object.values(refs.schemaRef) | ||
.map(r => ({ r, g: graphs.find(g => g.path === r.absolutePath) })) | ||
.filter(o => o.g?.nodes.schemas[o.r.tokenName]) | ||
.forEach(o => { | ||
.map((r) => ({ r, g: graphs.find((g) => g.path === r.absolutePath) })) | ||
.filter((o) => o.g?.nodes.schemas[o.r.tokenName]) | ||
.forEach((o) => { | ||
o.r.child = o.g?.nodes.schemas[o.r.tokenName]; | ||
@@ -68,0 +68,0 @@ filteredRefs.schemaRef[o.r.getFullPath()] = o.r; |
@@ -1,3 +0,3 @@ | ||
import { OpenAPIContent } from "../../../model"; | ||
import { OpenAPIGraph } from "../OpenAPIGraph"; | ||
import { OpenAPIContent } from '../../../model'; | ||
import { OpenAPIGraph } from '../OpenAPIGraph'; | ||
export declare class OpenAPIGraphsBuilder { | ||
@@ -4,0 +4,0 @@ graphs: OpenAPIGraph[]; |
@@ -12,3 +12,3 @@ "use strict"; | ||
const graphs = []; | ||
apis.forEach(api => { | ||
apis.forEach((api) => { | ||
const graph = new OpenAPIGraph_1.OpenAPIGraph(api.path); | ||
@@ -15,0 +15,0 @@ graph.setSchemaNodes(this.getSchemaNodes(api)); |
@@ -1,2 +0,2 @@ | ||
import { Node } from "../nodes/Node"; | ||
import { Node } from '../nodes/Node'; | ||
export declare class Edge { | ||
@@ -3,0 +3,0 @@ parent: Node | undefined; |
@@ -1,3 +0,3 @@ | ||
export { OpenAPIGraph } from "./OpenAPIGraph"; | ||
export { OpenAPIGraphsBuilder } from "./builder/OpenAPIGraphsBuilder"; | ||
export { OpenAPIGraphsManager } from "./OpenAPIGraphsManager"; | ||
export { OpenAPIGraph } from './OpenAPIGraph'; | ||
export { OpenAPIGraphsBuilder } from './builder/OpenAPIGraphsBuilder'; | ||
export { OpenAPIGraphs } from './OpenAPIGraphs'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OpenAPIGraphsManager = exports.OpenAPIGraphsBuilder = exports.OpenAPIGraph = void 0; | ||
exports.OpenAPIGraphs = exports.OpenAPIGraphsBuilder = exports.OpenAPIGraph = void 0; | ||
var OpenAPIGraph_1 = require("./OpenAPIGraph"); | ||
@@ -8,3 +8,3 @@ Object.defineProperty(exports, "OpenAPIGraph", { enumerable: true, get: function () { return OpenAPIGraph_1.OpenAPIGraph; } }); | ||
Object.defineProperty(exports, "OpenAPIGraphsBuilder", { enumerable: true, get: function () { return OpenAPIGraphsBuilder_1.OpenAPIGraphsBuilder; } }); | ||
var OpenAPIGraphsManager_1 = require("./OpenAPIGraphsManager"); | ||
Object.defineProperty(exports, "OpenAPIGraphsManager", { enumerable: true, get: function () { return OpenAPIGraphsManager_1.OpenAPIGraphsManager; } }); | ||
var OpenAPIGraphs_1 = require("./OpenAPIGraphs"); | ||
Object.defineProperty(exports, "OpenAPIGraphs", { enumerable: true, get: function () { return OpenAPIGraphs_1.OpenAPIGraphs; } }); |
@@ -7,6 +7,6 @@ import { Edges, EdgesRefDict, Nodes } from '../../model'; | ||
constructor(path: string); | ||
setSchemaNodes(schemaNodes: Nodes["schemas"]): void; | ||
getSchemaNodes(): Nodes["schemas"]; | ||
setSchemaNodes(schemaNodes: Nodes['schemas']): void; | ||
getSchemaNodes(): Nodes['schemas']; | ||
setRefEdges(refEdges: EdgesRefDict): void; | ||
getSchemaRefEdges(): EdgesRefDict["schemaRef"]; | ||
getSchemaRefEdges(): EdgesRefDict['schemaRef']; | ||
} |
@@ -8,8 +8,8 @@ "use strict"; | ||
this.nodes = { | ||
schemas: {} | ||
schemas: {}, | ||
}; | ||
this.edges = { | ||
ref: { | ||
schemaRef: {} | ||
} | ||
schemaRef: {}, | ||
}, | ||
}; | ||
@@ -16,0 +16,0 @@ } |
@@ -1,1 +0,1 @@ | ||
export { getUnusedSchemas } from "./swagger-graph"; | ||
export { OpenAPIGraphs } from './graph'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getUnusedSchemas = void 0; | ||
var swagger_graph_1 = require("./swagger-graph"); | ||
Object.defineProperty(exports, "getUnusedSchemas", { enumerable: true, get: function () { return swagger_graph_1.getUnusedSchemas; } }); | ||
exports.OpenAPIGraphs = void 0; | ||
var graph_1 = require("./graph"); | ||
Object.defineProperty(exports, "OpenAPIGraphs", { enumerable: true, get: function () { return graph_1.OpenAPIGraphs; } }); |
@@ -1,2 +0,2 @@ | ||
import { OpenAPIContent } from "../../model"; | ||
import { OpenAPIContent } from '../../model'; | ||
/** | ||
@@ -3,0 +3,0 @@ * reads the contents of all given paths. The files will be validated. |
@@ -19,11 +19,12 @@ "use strict"; | ||
// Validates it contents, but they are | ||
const validationPromises = paths.map(p => swagger_parser_1.default.validate(p)); | ||
const validationPromises = paths.map((p) => swagger_parser_1.default.validate(p)); | ||
// Filter only promises which return some content | ||
const validationResponse = await Promise.allSettled(validationPromises); | ||
return validationResponse.map((v, i) => ({ promise: v, path: paths[i] })) | ||
.filter(r => r.promise.status === 'fulfilled') | ||
return (validationResponse | ||
.map((v, i) => ({ promise: v, path: paths[i] })) | ||
.filter((r) => r.promise.status === 'fulfilled') | ||
// as you can see, the file is read twice. One in the SwaggerParser.validate | ||
// and another one here. It cool be cool to get SwaggerParser.validate value dereferenced | ||
.map(r => ({ path: r.path, content: js_yaml_1.load(fs_1.readFileSync(r.path, 'utf8')) })); | ||
.map((r) => ({ path: r.path, content: js_yaml_1.load(fs_1.readFileSync(r.path, 'utf8')) }))); | ||
} | ||
exports.getOpenApisContent = getOpenApisContent; |
{ | ||
"name": "openapi-graph-core", | ||
"version": "0.0.1-alpha.2.0", | ||
"version": "0.0.1-alpha.2.1.0", | ||
"description": "A TS library to manage large API projects defined by OpenAPIv3 specification.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
27170
53
665
4