@goast/core 0.2.1 → 0.3.0

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.
Files changed (47) hide show
  1. package/README.md +65 -11
  2. package/cjs/lib/codegen/config.js +5 -1
  3. package/cjs/lib/codegen/generator.js +28 -35
  4. package/cjs/lib/codegen/internal-utils.js +1 -2
  5. package/cjs/lib/collect/collector.js +1 -2
  6. package/cjs/lib/collect/helpers.js +2 -3
  7. package/cjs/lib/internal-utils.js +1 -2
  8. package/cjs/lib/parse/deref-proxy.js +1 -2
  9. package/cjs/lib/parse/parser.js +114 -126
  10. package/cjs/lib/transform/helpers.js +10 -10
  11. package/cjs/lib/transform/transform-document.js +5 -3
  12. package/cjs/lib/transform/transform-endpoint.js +35 -10
  13. package/cjs/lib/transform/transform-schema.js +5 -3
  14. package/cjs/lib/transform/transformer.js +1 -2
  15. package/cjs/lib/utils/array.utils.js +1 -2
  16. package/cjs/lib/utils/class.utils.js +3 -4
  17. package/cjs/lib/utils/common.utils.js +12 -13
  18. package/cjs/lib/utils/condition.js +1 -2
  19. package/cjs/lib/utils/endpoint.utils.js +1 -2
  20. package/cjs/lib/utils/error.utils.js +1 -2
  21. package/cjs/lib/utils/file-system.utils.js +21 -26
  22. package/cjs/lib/utils/generator.utils.js +1 -2
  23. package/cjs/lib/utils/object.utils.js +1 -2
  24. package/cjs/lib/utils/schema.utils.js +67 -5
  25. package/cjs/lib/utils/source-builder.js +5 -3
  26. package/cjs/lib/utils/string-builder/options.js +3 -0
  27. package/cjs/lib/utils/string-builder/string-builder.js +1 -1
  28. package/cjs/lib/utils/string-builder/utils.js +5 -6
  29. package/cjs/lib/utils/string.utils.js +27 -28
  30. package/cjs/lib/utils/type.utils.js +2 -3
  31. package/esm/lib/codegen/config.js +5 -1
  32. package/esm/lib/codegen/generator.js +28 -35
  33. package/esm/lib/parse/parser.js +114 -127
  34. package/esm/lib/transform/transform-document.js +4 -1
  35. package/esm/lib/transform/transform-endpoint.js +34 -8
  36. package/esm/lib/transform/transform-schema.js +4 -1
  37. package/esm/lib/utils/file-system.utils.js +19 -24
  38. package/esm/lib/utils/schema.utils.js +65 -2
  39. package/esm/lib/utils/source-builder.js +6 -4
  40. package/esm/lib/utils/string-builder/options.js +3 -0
  41. package/esm/lib/utils/string-builder/string-builder.js +1 -1
  42. package/esm/lib/utils/string.utils.js +7 -7
  43. package/package.json +6 -5
  44. package/types/lib/codegen/config.d.ts +8 -0
  45. package/types/lib/utils/source-builder.d.ts +11 -1
  46. package/types/lib/utils/string-builder/options.d.ts +8 -2
  47. package/types/lib/utils/string.utils.types.d.ts +1 -0
package/README.md CHANGED
@@ -1,11 +1,65 @@
1
- # core
2
-
3
- This library was generated with [Nx](https://nx.dev).
4
-
5
- ## Building
6
-
7
- Run `nx build core` to build the library.
8
-
9
- ## Running unit tests
10
-
11
- Run `nx test core` to execute the unit tests via [Jest](https://jestjs.io).
1
+ # gOAst (@goast/core)
2
+
3
+ [![@goast/core NPM Version](https://img.shields.io/npm/v/%40goast%2Fcore?logo=npm&label=%40goast%2Fcore)](https://www.npmjs.com/package/@goast/core)
4
+
5
+ **gOAst** stands for **g**enerative **O**pen **A**PI **s**pecification **t**ransformer, a tool designed to transform OpenAPI specifications into various forms with flexibility and extensibility at its core.
6
+
7
+ For more Information, please visit the [gOAst GitHub Repository](https://github.com/MaSch0212/goast/blob/main).
8
+
9
+ ## Purpose 👍
10
+
11
+ The `@goast/core` package provides:
12
+
13
+ - entry points for using the **gOAst** library
14
+ - base classes for creating custom generators
15
+ - utilities for parsing and transforming OpenAPI specifications
16
+
17
+ ## Usage Example 🚀
18
+
19
+ ```typescript
20
+ import { OpenApiGenerator } from '@goast/core';
21
+
22
+ class MyGenerator implements OpenApiGenerationProvider {
23
+ generate(
24
+ context: OpenApiGeneratorContext<OpenApiGeneratorInput>,
25
+ config?: Partial<Readonly<Record<string, unknown>>>,
26
+ ): Record<string, unknown> {
27
+ // Do something
28
+ return {};
29
+ }
30
+ }
31
+
32
+ async function main() {
33
+ const generator = new OpenApiGenerator()
34
+
35
+ // Add a generator using a class
36
+ .useType(MyGenerator)
37
+
38
+ // Add a generator using a function
39
+ .useFn((ctx, cfg) => {
40
+ // Do the generation
41
+ return {}; // Return information about the generated files so it can be used by other generators
42
+ })
43
+
44
+ // Add a generator using an object implementing `OpenApiGenerationProvider`
45
+ .useValue({ generate: (ctx, cfg) => ({}) });
46
+
47
+ // Generate for one of more OpenAPI specification files
48
+ await generator.parseAndGenerate('path/to/openapi.json', 'path/to/another/openapi.yaml');
49
+
50
+ // Alternatively, you can generate output for all specifications in a directory.
51
+ // By default, it will only consider files within the directory (non-recursively) with the extensions: .json, .yaml, .yml.
52
+ await generator.parseAndGenerateFromDir('path/to/openapi/specs');
53
+ }
54
+
55
+ main();
56
+ ```
57
+
58
+ ## Available Generator Packages 📚
59
+
60
+ [![@goast/typescript NPM Version](https://img.shields.io/npm/v/%40goast%2Ftypescript?logo=npm&label=%40goast%2Ftypescript)](https://www.npmjs.com/package/@goast/typescript)
61
+ [![@goast/kotlin NPM Version](https://img.shields.io/npm/v/%40goast%2Fkotlin?logo=npm&label=%40goast%2Fkotlin)](https://www.npmjs.com/package/@goast/kotlin)
62
+
63
+ ## API Documentation 📖
64
+
65
+ The API documentation can be found [here](https://github.com/MaSch0212/goast/wiki).
@@ -2,4 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultOpenApiGeneratorConfig = void 0;
4
4
  const source_builder_1 = require("../utils/source-builder");
5
- exports.defaultOpenApiGeneratorConfig = Object.assign(Object.assign({}, source_builder_1.defaultSourceBuilderOptions), { outputDir: 'generated', clearOutputDir: true });
5
+ exports.defaultOpenApiGeneratorConfig = {
6
+ ...source_builder_1.defaultSourceBuilderOptions,
7
+ outputDir: 'generated',
8
+ clearOutputDir: true,
9
+ };
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OpenApiGenerationProviderBase = exports.OpenApiGenerator = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const path_1 = require("path");
6
5
  const fs_extra_1 = require("fs-extra");
7
6
  const config_1 = require("./config");
@@ -27,46 +26,40 @@ class _OpenApiGenerator {
27
26
  useValue(value, config) {
28
27
  return this.use(action_provider_1.ActionProvider.fromValue(value, 'generate'), config);
29
28
  }
30
- generate(data) {
31
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
32
- const absOutputPath = (0, path_1.resolve)(this._config.outputDir);
33
- if (this._config.clearOutputDir) {
34
- yield (0, fs_extra_1.emptyDir)(absOutputPath);
35
- }
36
- else {
37
- yield (0, fs_extra_1.ensureDir)(absOutputPath);
38
- }
39
- let input = {};
40
- for (const generator of this._providers) {
41
- const context = {
42
- data,
43
- input,
44
- config: this._config,
45
- };
46
- const result = generator.provider.run(context, generator.config);
47
- if (result) {
48
- input = mergeDeep(input, result);
49
- }
29
+ async generate(data) {
30
+ const absOutputPath = (0, path_1.resolve)(this._config.outputDir);
31
+ if (this._config.clearOutputDir) {
32
+ await (0, fs_extra_1.emptyDir)(absOutputPath);
33
+ }
34
+ else {
35
+ await (0, fs_extra_1.ensureDir)(absOutputPath);
36
+ }
37
+ let input = {};
38
+ for (const generator of this._providers) {
39
+ const context = {
40
+ data,
41
+ input,
42
+ config: this._config,
43
+ };
44
+ const result = generator.provider.run(context, generator.config);
45
+ if (result) {
46
+ input = mergeDeep(input, result);
50
47
  }
51
- return input;
52
- });
48
+ }
49
+ return input;
53
50
  }
54
- parseAndGenerate(...fileNames) {
55
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
56
- const data = yield this._parser.parseApisAndTransform(...fileNames);
57
- return yield this.generate(data);
58
- });
51
+ async parseAndGenerate(...fileNames) {
52
+ const data = await this._parser.parseApisAndTransform(...fileNames);
53
+ return await this.generate(data);
59
54
  }
60
- parseAndGenerateFromDir(dir, options) {
61
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
62
- const filter = (file) => { var _a, _b; return (file.endsWith('.yml') || file.endsWith('.yaml') || file.endsWith('.json')) && ((_b = (_a = options === null || options === void 0 ? void 0 : options.filter) === null || _a === void 0 ? void 0 : _a.call(options, file)) !== null && _b !== void 0 ? _b : true); };
63
- return this.parseAndGenerate(...(yield (0, file_system_utils_1.getFiles)(dir, Object.assign(Object.assign({}, options), { filter }))));
64
- });
55
+ async parseAndGenerateFromDir(dir, options) {
56
+ const filter = (file) => { var _a, _b; return (file.endsWith('.yml') || file.endsWith('.yaml') || file.endsWith('.json')) && ((_b = (_a = options === null || options === void 0 ? void 0 : options.filter) === null || _a === void 0 ? void 0 : _a.call(options, file)) !== null && _b !== void 0 ? _b : true); };
57
+ return this.parseAndGenerate(...(await (0, file_system_utils_1.getFiles)(dir, { ...options, filter })));
65
58
  }
66
59
  }
67
60
  class OpenApiGenerator extends _OpenApiGenerator {
68
61
  constructor(config) {
69
- super(Object.assign(Object.assign({}, config_1.defaultOpenApiGeneratorConfig), config), [], new parser_1.OpenApiParser());
62
+ super({ ...config_1.defaultOpenApiGeneratorConfig, ...config }, [], new parser_1.OpenApiParser());
70
63
  }
71
64
  }
72
65
  exports.OpenApiGenerator = OpenApiGenerator;
@@ -100,7 +93,7 @@ class OpenApiGenerationProviderBase {
100
93
  return this.onGenerate(ctx);
101
94
  }
102
95
  getProviderContext(context, config, defaultConfig) {
103
- const c = Object.assign(Object.assign(Object.assign({}, context.config), defaultConfig), config);
96
+ const c = { ...context.config, ...defaultConfig, ...config };
104
97
  return Object.assign(context, {
105
98
  config: c,
106
99
  });
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addSourceIfTest = void 0;
3
+ exports.addSourceIfTest = addSourceIfTest;
4
4
  function addSourceIfTest(config, result, sourceFn) {
5
5
  if (config.__test__ && !result.__source__) {
6
6
  result.__source__ = sourceFn();
7
7
  }
8
8
  }
9
- exports.addSourceIfTest = addSourceIfTest;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.collectOpenApi = void 0;
3
+ exports.collectOpenApi = collectOpenApi;
4
4
  const helpers_1 = require("./helpers");
5
5
  function collectOpenApi(apis) {
6
6
  const data = {
@@ -11,7 +11,6 @@ function collectOpenApi(apis) {
11
11
  collectDocument(data, apis);
12
12
  return data;
13
13
  }
14
- exports.collectOpenApi = collectOpenApi;
15
14
  function collectDocument(data, documents) {
16
15
  (0, helpers_1.collect)(data, documents, (data, document) => {
17
16
  var _a, _b, _c, _d, _e;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.collectRecord = exports.collect = void 0;
3
+ exports.collect = collect;
4
+ exports.collectRecord = collectRecord;
4
5
  const internal_utils_1 = require("../internal-utils");
5
6
  function collect(data, obj, func) {
6
7
  if (!obj)
@@ -20,7 +21,6 @@ function collect(data, obj, func) {
20
21
  func(data, obj);
21
22
  }
22
23
  }
23
- exports.collect = collect;
24
24
  function collectRecord(data, obj, func) {
25
25
  if (!obj)
26
26
  return;
@@ -35,4 +35,3 @@ function collectRecord(data, obj, func) {
35
35
  func(data, value, key);
36
36
  }
37
37
  }
38
- exports.collectRecord = collectRecord;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isOpenApiObjectProperty = void 0;
3
+ exports.isOpenApiObjectProperty = isOpenApiObjectProperty;
4
4
  function isOpenApiObjectProperty(propertyName) {
5
5
  return !propertyName.startsWith('$') && !propertyName.startsWith('x-');
6
6
  }
7
- exports.isOpenApiObjectProperty = isOpenApiObjectProperty;
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createDerefProxy = void 0;
3
+ exports.createDerefProxy = createDerefProxy;
4
4
  const utils_1 = require("../utils");
5
5
  function createDerefProxy(obj, source, ref) {
6
6
  return new Proxy(obj, new DerefProxyHandler(source, ref));
7
7
  }
8
- exports.createDerefProxy = createDerefProxy;
9
8
  const propertiesNotDerivedFromRef = ['title'];
10
9
  class DerefProxyHandler {
11
10
  constructor(_source, _ref) {
@@ -16,150 +16,138 @@ class OpenApiParser {
16
16
  constructor() {
17
17
  this._loadedDocuments = new Map();
18
18
  }
19
- parseApisAndTransform(...fileNames) {
20
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
21
- const flatFileNames = [].concat(...fileNames);
22
- const apis = yield Promise.all(flatFileNames.map((fileName) => this.parseApi(fileName)));
23
- const transformed = this.transformApis(apis);
24
- return transformed;
25
- });
19
+ async parseApisAndTransform(...fileNames) {
20
+ const flatFileNames = [].concat(...fileNames);
21
+ const apis = await Promise.all(flatFileNames.map((fileName) => this.parseApi(fileName)));
22
+ const transformed = this.transformApis(apis);
23
+ return transformed;
26
24
  }
27
- parseApi(fileName) {
28
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
29
- const absoluteFilePath = this.isUrl(fileName) ? fileName : path_1.default.resolve((0, process_1.cwd)(), fileName);
30
- const doc = yield this.loadDocument(absoluteFilePath);
31
- return yield this.dereference(absoluteFilePath, '', doc.document);
32
- });
25
+ async parseApi(fileName) {
26
+ const absoluteFilePath = this.isUrl(fileName) ? fileName : path_1.default.resolve((0, process_1.cwd)(), fileName);
27
+ const doc = await this.loadDocument(absoluteFilePath);
28
+ return await this.dereference(absoluteFilePath, '', doc.document);
33
29
  }
34
30
  transformApis(apis) {
35
31
  const collectedData = (0, collector_1.collectOpenApi)(apis);
36
32
  const transformedData = (0, transformer_1.transformOpenApi)(collectedData);
37
33
  return transformedData;
38
34
  }
39
- dereference(file, path, value) {
40
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
41
- let existingDocument = this._loadedDocuments.get(file);
42
- if (existingDocument) {
43
- const existingComponent = existingDocument.dereferencedComponents.get(path);
44
- if (existingComponent) {
45
- return existingComponent;
46
- }
47
- }
48
- else {
49
- existingDocument = yield this.loadDocument(file);
50
- }
51
- const result = (0, deref_proxy_1.createDerefProxy)(value, {
52
- file,
53
- path,
54
- document: existingDocument.dereferencedDocument,
55
- originalComponent: value,
56
- });
57
- existingDocument.dereferencedComponents.set(path, result);
58
- if (value.$ref) {
59
- result.$ref = (yield this.resolveReference(file, value));
35
+ async dereference(file, path, value) {
36
+ let existingDocument = this._loadedDocuments.get(file);
37
+ if (existingDocument) {
38
+ const existingComponent = existingDocument.dereferencedComponents.get(path);
39
+ if (existingComponent) {
40
+ return existingComponent;
60
41
  }
61
- for (const key of Object.keys(value)) {
62
- if (key === '$ref')
63
- continue;
64
- const v = value[key];
65
- if ((0, utils_1.isNullish)(v))
66
- continue;
67
- if (typeof v === 'object') {
68
- if (Array.isArray(v)) {
69
- result[key] = yield Promise.all(v.map((v, index) => tslib_1.__awaiter(this, void 0, void 0, function* () {
70
- if (v && typeof v === 'object') {
71
- return yield this.dereference(file, `${path}/${String(key)}/${index}`, v);
72
- }
73
- else {
74
- return v;
75
- }
76
- })));
77
- }
78
- else {
79
- result[key] = yield this.dereference(file, `${path}/${String(key)}`, v);
80
- }
42
+ }
43
+ else {
44
+ existingDocument = await this.loadDocument(file);
45
+ }
46
+ const result = (0, deref_proxy_1.createDerefProxy)(value, {
47
+ file,
48
+ path,
49
+ document: existingDocument.dereferencedDocument,
50
+ originalComponent: value,
51
+ });
52
+ existingDocument.dereferencedComponents.set(path, result);
53
+ if (value.$ref) {
54
+ result.$ref = (await this.resolveReference(file, value));
55
+ }
56
+ for (const key of Object.keys(value)) {
57
+ if (key === '$ref')
58
+ continue;
59
+ const v = value[key];
60
+ if ((0, utils_1.isNullish)(v))
61
+ continue;
62
+ if (typeof v === 'object') {
63
+ if (Array.isArray(v)) {
64
+ result[key] = await Promise.all(v.map(async (v, index) => {
65
+ if (v && typeof v === 'object') {
66
+ return await this.dereference(file, `${path}/${String(key)}/${index}`, v);
67
+ }
68
+ else {
69
+ return v;
70
+ }
71
+ }));
81
72
  }
82
- if (typeof v === 'string' && path.endsWith('/discriminator/mapping')) {
83
- result[key] = yield this.resolveReference(file, { $ref: v });
73
+ else {
74
+ result[key] = await this.dereference(file, `${path}/${String(key)}`, v);
84
75
  }
85
76
  }
86
- return result;
87
- });
88
- }
89
- resolveReference(file, ref) {
90
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
91
- const [refFile, refPath] = ref.$ref.split('#');
92
- let absoluteRefFile = refFile;
93
- if (!/\S/.test(refFile)) {
94
- absoluteRefFile = file;
95
- }
96
- else if (!this.isUrl(refFile)) {
97
- absoluteRefFile = path_1.default.resolve(path_1.default.dirname(file), refFile);
77
+ if (typeof v === 'string' && path.endsWith('/discriminator/mapping')) {
78
+ result[key] = await this.resolveReference(file, { $ref: v });
98
79
  }
99
- const doc = yield this.loadDocument(absoluteRefFile);
100
- const value = getDeepProperty(doc.document, refPath.replace(/[/]/g, '.'));
101
- if (value && typeof value === 'object') {
102
- return this.dereference(absoluteRefFile, refPath, value);
103
- }
104
- return undefined;
105
- });
80
+ }
81
+ return result;
106
82
  }
107
- loadDocument(fileOrUrl) {
108
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
109
- const existingDocument = this._loadedDocuments.get(fileOrUrl);
110
- if (existingDocument) {
111
- return existingDocument;
112
- }
113
- const documentContent = yield this.getDocumentContent(fileOrUrl);
114
- const extname = path_1.default.extname(fileOrUrl).toLowerCase();
115
- let parsedDocument;
116
- if (extname === '.json') {
117
- parsedDocument = this.tryParseJson(documentContent);
118
- }
119
- else if (extname === '.yaml' || extname === '.yml') {
83
+ async resolveReference(file, ref) {
84
+ const [refFile, refPath] = ref.$ref.split('#');
85
+ let absoluteRefFile = refFile;
86
+ if (!/\S/.test(refFile)) {
87
+ absoluteRefFile = file;
88
+ }
89
+ else if (!this.isUrl(refFile)) {
90
+ absoluteRefFile = path_1.default.resolve(path_1.default.dirname(file), refFile);
91
+ }
92
+ const doc = await this.loadDocument(absoluteRefFile);
93
+ const value = getDeepProperty(doc.document, refPath.replace(/[/]/g, '.'));
94
+ if (value && typeof value === 'object') {
95
+ return this.dereference(absoluteRefFile, refPath, value);
96
+ }
97
+ return undefined;
98
+ }
99
+ async loadDocument(fileOrUrl) {
100
+ const existingDocument = this._loadedDocuments.get(fileOrUrl);
101
+ if (existingDocument) {
102
+ return existingDocument;
103
+ }
104
+ const documentContent = await this.getDocumentContent(fileOrUrl);
105
+ const extname = path_1.default.extname(fileOrUrl).toLowerCase();
106
+ let parsedDocument;
107
+ if (extname === '.json') {
108
+ parsedDocument = this.tryParseJson(documentContent);
109
+ }
110
+ else if (extname === '.yaml' || extname === '.yml') {
111
+ parsedDocument = this.tryParseYaml(documentContent);
112
+ }
113
+ else {
114
+ parsedDocument = this.tryParseJson(documentContent);
115
+ if (parsedDocument !== undefined) {
120
116
  parsedDocument = this.tryParseYaml(documentContent);
121
117
  }
122
- else {
123
- parsedDocument = this.tryParseJson(documentContent);
124
- if (parsedDocument !== undefined) {
125
- parsedDocument = this.tryParseYaml(documentContent);
126
- }
127
- }
128
- if (parsedDocument === undefined) {
129
- throw new Error(`Unable to parse ${fileOrUrl}`);
130
- }
131
- const doc = (parsedDocument !== null && parsedDocument !== void 0 ? parsedDocument : {});
132
- const deref = (0, deref_proxy_1.createDerefProxy)(doc, {
133
- file: fileOrUrl,
134
- path: '',
135
- originalComponent: doc,
136
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
137
- document: undefined,
138
- });
139
- deref.$src.document = deref;
140
- const loadedDocument = {
141
- file: fileOrUrl,
142
- document: doc,
143
- dereferencedDocument: deref,
144
- dereferencedComponents: new Map(),
145
- };
146
- this._loadedDocuments.set(fileOrUrl, loadedDocument);
147
- return loadedDocument;
118
+ }
119
+ if (parsedDocument === undefined) {
120
+ throw new Error(`Unable to parse ${fileOrUrl}`);
121
+ }
122
+ const doc = (parsedDocument !== null && parsedDocument !== void 0 ? parsedDocument : {});
123
+ const deref = (0, deref_proxy_1.createDerefProxy)(doc, {
124
+ file: fileOrUrl,
125
+ path: '',
126
+ originalComponent: doc,
127
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
128
+ document: undefined,
148
129
  });
130
+ deref.$src.document = deref;
131
+ const loadedDocument = {
132
+ file: fileOrUrl,
133
+ document: doc,
134
+ dereferencedDocument: deref,
135
+ dereferencedComponents: new Map(),
136
+ };
137
+ this._loadedDocuments.set(fileOrUrl, loadedDocument);
138
+ return loadedDocument;
149
139
  }
150
- getDocumentContent(fileOrUrl) {
151
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
152
- if (this.isUrl(fileOrUrl)) {
153
- const res = yield (0, node_fetch_1.default)(fileOrUrl);
154
- if (!res.ok) {
155
- throw new Error(`Unable to download ${fileOrUrl}: ${res.statusText}`);
156
- }
157
- return yield res.text();
140
+ async getDocumentContent(fileOrUrl) {
141
+ if (this.isUrl(fileOrUrl)) {
142
+ const res = await (0, node_fetch_1.default)(fileOrUrl);
143
+ if (!res.ok) {
144
+ throw new Error(`Unable to download ${fileOrUrl}: ${res.statusText}`);
158
145
  }
159
- else {
160
- return (yield fs_extra_1.default.readFile(fileOrUrl)).toString();
161
- }
162
- });
146
+ return await res.text();
147
+ }
148
+ else {
149
+ return (await fs_extra_1.default.readFile(fileOrUrl)).toString();
150
+ }
163
151
  }
164
152
  isUrl(fileOrUrl) {
165
153
  return /^https?:\/\//i.test(fileOrUrl);
@@ -1,6 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getOpenApiObjectIdentifier = exports.IdGenerator = exports.transformSchemaProperties = exports.transformAdditionalProperties = exports.determineEndpointName = exports.getCustomFields = exports.updateSchemaAccessibility = exports.determineSchemaAccessibility = exports.determineSchemaName = exports.determineSchemaKind = void 0;
3
+ exports.IdGenerator = void 0;
4
+ exports.determineSchemaKind = determineSchemaKind;
5
+ exports.determineSchemaName = determineSchemaName;
6
+ exports.determineSchemaAccessibility = determineSchemaAccessibility;
7
+ exports.updateSchemaAccessibility = updateSchemaAccessibility;
8
+ exports.getCustomFields = getCustomFields;
9
+ exports.determineEndpointName = determineEndpointName;
10
+ exports.transformAdditionalProperties = transformAdditionalProperties;
11
+ exports.transformSchemaProperties = transformSchemaProperties;
12
+ exports.getOpenApiObjectIdentifier = getOpenApiObjectIdentifier;
4
13
  const internal_utils_1 = require("../internal-utils");
5
14
  const common_utils_1 = require("../utils/common.utils");
6
15
  function determineSchemaKind(schema) {
@@ -24,7 +33,6 @@ function determineSchemaKind(schema) {
24
33
  }
25
34
  return 'unknown';
26
35
  }
27
- exports.determineSchemaKind = determineSchemaKind;
28
36
  function determineSchemaName(schema, id) {
29
37
  if (schema.title)
30
38
  return { name: schema.title, isGenerated: false };
@@ -42,7 +50,6 @@ function determineSchemaName(schema, id) {
42
50
  }
43
51
  return { name: id, isGenerated: true };
44
52
  }
45
- exports.determineSchemaName = determineSchemaName;
46
53
  function determineSchemaAccessibility(schema) {
47
54
  if (schema.readOnly === true) {
48
55
  return schema.writeOnly === true ? 'none' : 'readOnly';
@@ -51,7 +58,6 @@ function determineSchemaAccessibility(schema) {
51
58
  return schema.writeOnly === true ? 'writeOnly' : 'all';
52
59
  }
53
60
  }
54
- exports.determineSchemaAccessibility = determineSchemaAccessibility;
55
61
  function updateSchemaAccessibility(accessibility, schema) {
56
62
  if (accessibility === 'none')
57
63
  return 'none';
@@ -61,7 +67,6 @@ function updateSchemaAccessibility(accessibility, schema) {
61
67
  return schema.readOnly === true ? 'none' : 'writeOnly';
62
68
  return determineSchemaAccessibility(schema);
63
69
  }
64
- exports.updateSchemaAccessibility = updateSchemaAccessibility;
65
70
  function getCustomFields(schema) {
66
71
  const result = {};
67
72
  for (const key in schema) {
@@ -72,13 +77,11 @@ function getCustomFields(schema) {
72
77
  }
73
78
  return result;
74
79
  }
75
- exports.getCustomFields = getCustomFields;
76
80
  function determineEndpointName(endpointInfo) {
77
81
  if (endpointInfo.operation.operationId)
78
82
  return endpointInfo.operation.operationId;
79
83
  return endpointInfo.method + endpointInfo.path.replace(/\{([^}]+)\}/g, ':$1').replace(/\//g, '_');
80
84
  }
81
- exports.determineEndpointName = determineEndpointName;
82
85
  function transformAdditionalProperties(context, schema, transformSchema) {
83
86
  if ((0, common_utils_1.isNullish)(schema.additionalProperties))
84
87
  return undefined;
@@ -86,7 +89,6 @@ function transformAdditionalProperties(context, schema, transformSchema) {
86
89
  return schema.additionalProperties;
87
90
  return transformSchema(context, schema.additionalProperties);
88
91
  }
89
- exports.transformAdditionalProperties = transformAdditionalProperties;
90
92
  function transformSchemaProperties(context, schema, transformSchema) {
91
93
  const result = new Map();
92
94
  if (!schema.properties)
@@ -101,7 +103,6 @@ function transformSchemaProperties(context, schema, transformSchema) {
101
103
  }
102
104
  return result;
103
105
  }
104
- exports.transformSchemaProperties = transformSchemaProperties;
105
106
  class IdGenerator {
106
107
  constructor() {
107
108
  this._idMap = new Map();
@@ -117,4 +118,3 @@ exports.IdGenerator = IdGenerator;
117
118
  function getOpenApiObjectIdentifier(obj) {
118
119
  return obj.$src.file + '#' + obj.$src.path;
119
120
  }
120
- exports.getOpenApiObjectIdentifier = getOpenApiObjectIdentifier;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transformDocument = void 0;
3
+ exports.transformDocument = transformDocument;
4
4
  const helpers_1 = require("./helpers");
5
5
  function transformDocument(context, document) {
6
6
  var _a;
@@ -8,7 +8,6 @@ function transformDocument(context, document) {
8
8
  transformTag(context, tag);
9
9
  }
10
10
  }
11
- exports.transformDocument = transformDocument;
12
11
  function transformTag(context, tag, isReference = false) {
13
12
  var _a;
14
13
  const openApiObjectId = (0, helpers_1.getOpenApiObjectIdentifier)(tag);
@@ -18,7 +17,10 @@ function transformTag(context, tag, isReference = false) {
18
17
  const ref = tag.$ref ? transformTag(context, tag.$ref, true) : undefined;
19
18
  const id = context.idGenerator.generateId('service');
20
19
  const service = {
21
- $src: Object.assign(Object.assign({}, tag.$src), { component: tag }),
20
+ $src: {
21
+ ...tag.$src,
22
+ component: tag,
23
+ },
22
24
  $ref: ref,
23
25
  id,
24
26
  name: (_a = tag.name) !== null && _a !== void 0 ? _a : id,