@goast/core 0.5.0-beta.3 → 0.5.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/src/parse/parser.js +13 -4
- package/package.json +1 -1
- package/script/src/parse/parser.js +13 -4
package/esm/src/parse/parser.js
CHANGED
|
@@ -33,7 +33,7 @@ export class OpenApiParser {
|
|
|
33
33
|
async parseApi(fileName) {
|
|
34
34
|
const absoluteFilePath = this.isUrl(fileName) ? fileName : path.resolve(cwd(), fileName);
|
|
35
35
|
const doc = await this.loadDocument(absoluteFilePath);
|
|
36
|
-
return await this.dereference(absoluteFilePath, '', doc.document);
|
|
36
|
+
return await this.dereference(absoluteFilePath, '/', doc.document);
|
|
37
37
|
}
|
|
38
38
|
transformApis(apis) {
|
|
39
39
|
const collectedData = collectOpenApi(apis);
|
|
@@ -72,7 +72,7 @@ export class OpenApiParser {
|
|
|
72
72
|
if (Array.isArray(v)) {
|
|
73
73
|
result[key] = await Promise.all(v.map(async (v, index) => {
|
|
74
74
|
if (v && typeof v === 'object') {
|
|
75
|
-
return await this.dereference(file,
|
|
75
|
+
return await this.dereference(file, joinPaths(path, key, index), v);
|
|
76
76
|
}
|
|
77
77
|
else {
|
|
78
78
|
return v;
|
|
@@ -80,7 +80,7 @@ export class OpenApiParser {
|
|
|
80
80
|
}));
|
|
81
81
|
}
|
|
82
82
|
else {
|
|
83
|
-
result[key] = await this.dereference(file,
|
|
83
|
+
result[key] = await this.dereference(file, joinPaths(path, key), v);
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
if (typeof v === 'string' && path.endsWith('/discriminator/mapping')) {
|
|
@@ -101,7 +101,7 @@ export class OpenApiParser {
|
|
|
101
101
|
const doc = await this.loadDocument(absoluteRefFile);
|
|
102
102
|
const value = refPath ? getDeepProperty(doc.document, refPath.replace(/[/]/g, '.')) : doc.document;
|
|
103
103
|
if (value && typeof value === 'object') {
|
|
104
|
-
return this.dereference(absoluteRefFile, refPath !== null && refPath !== void 0 ? refPath : '', value);
|
|
104
|
+
return this.dereference(absoluteRefFile, refPath !== null && refPath !== void 0 ? refPath : '/', value);
|
|
105
105
|
}
|
|
106
106
|
return undefined;
|
|
107
107
|
}
|
|
@@ -193,3 +193,12 @@ function getDeepProperty(value, path) {
|
|
|
193
193
|
}
|
|
194
194
|
return result;
|
|
195
195
|
}
|
|
196
|
+
function joinPaths(...paths) {
|
|
197
|
+
var _a;
|
|
198
|
+
const startingSlash = String((_a = paths[0]) !== null && _a !== void 0 ? _a : '').startsWith('/') ? '/' : '';
|
|
199
|
+
const path = paths
|
|
200
|
+
.map((p) => String(p).replace(/^\//, '').replace(/\/$/, ''))
|
|
201
|
+
.filter((p) => !!p)
|
|
202
|
+
.join('/');
|
|
203
|
+
return startingSlash + path;
|
|
204
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goast/core",
|
|
3
|
-
"version": "0.5.0-beta.
|
|
3
|
+
"version": "0.5.0-beta.4",
|
|
4
4
|
"description": "A tool designed to transform OpenAPI specifications into various forms with flexibility and extensibility at its core.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Marc Schmidt (MaSch0212)",
|
|
@@ -37,7 +37,7 @@ class OpenApiParser {
|
|
|
37
37
|
async parseApi(fileName) {
|
|
38
38
|
const absoluteFilePath = this.isUrl(fileName) ? fileName : node_path_1.default.resolve((0, node_process_1.cwd)(), fileName);
|
|
39
39
|
const doc = await this.loadDocument(absoluteFilePath);
|
|
40
|
-
return await this.dereference(absoluteFilePath, '', doc.document);
|
|
40
|
+
return await this.dereference(absoluteFilePath, '/', doc.document);
|
|
41
41
|
}
|
|
42
42
|
transformApis(apis) {
|
|
43
43
|
const collectedData = (0, collector_js_1.collectOpenApi)(apis);
|
|
@@ -76,7 +76,7 @@ class OpenApiParser {
|
|
|
76
76
|
if (Array.isArray(v)) {
|
|
77
77
|
result[key] = await Promise.all(v.map(async (v, index) => {
|
|
78
78
|
if (v && typeof v === 'object') {
|
|
79
|
-
return await this.dereference(file,
|
|
79
|
+
return await this.dereference(file, joinPaths(path, key, index), v);
|
|
80
80
|
}
|
|
81
81
|
else {
|
|
82
82
|
return v;
|
|
@@ -84,7 +84,7 @@ class OpenApiParser {
|
|
|
84
84
|
}));
|
|
85
85
|
}
|
|
86
86
|
else {
|
|
87
|
-
result[key] = await this.dereference(file,
|
|
87
|
+
result[key] = await this.dereference(file, joinPaths(path, key), v);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
if (typeof v === 'string' && path.endsWith('/discriminator/mapping')) {
|
|
@@ -105,7 +105,7 @@ class OpenApiParser {
|
|
|
105
105
|
const doc = await this.loadDocument(absoluteRefFile);
|
|
106
106
|
const value = refPath ? getDeepProperty(doc.document, refPath.replace(/[/]/g, '.')) : doc.document;
|
|
107
107
|
if (value && typeof value === 'object') {
|
|
108
|
-
return this.dereference(absoluteRefFile, refPath !== null && refPath !== void 0 ? refPath : '', value);
|
|
108
|
+
return this.dereference(absoluteRefFile, refPath !== null && refPath !== void 0 ? refPath : '/', value);
|
|
109
109
|
}
|
|
110
110
|
return undefined;
|
|
111
111
|
}
|
|
@@ -198,3 +198,12 @@ function getDeepProperty(value, path) {
|
|
|
198
198
|
}
|
|
199
199
|
return result;
|
|
200
200
|
}
|
|
201
|
+
function joinPaths(...paths) {
|
|
202
|
+
var _a;
|
|
203
|
+
const startingSlash = String((_a = paths[0]) !== null && _a !== void 0 ? _a : '').startsWith('/') ? '/' : '';
|
|
204
|
+
const path = paths
|
|
205
|
+
.map((p) => String(p).replace(/^\//, '').replace(/\/$/, ''))
|
|
206
|
+
.filter((p) => !!p)
|
|
207
|
+
.join('/');
|
|
208
|
+
return startingSlash + path;
|
|
209
|
+
}
|