@goast/core 0.5.2 → 0.6.0-beta.1
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/LICENSE +21 -21
- package/README.md +67 -67
- package/esm/src/parse/parser.js +2 -1
- package/package.json +1 -1
- package/script/src/parse/parser.js +2 -1
- package/src/_dnt.shims.ts +0 -69
- package/src/mod.ts +0 -35
- package/src/src/ast/node.ts +0 -46
- package/src/src/codegen/config.ts +0 -41
- package/src/src/codegen/endpoints-generator.ts +0 -72
- package/src/src/codegen/generator.ts +0 -192
- package/src/src/codegen/internal-utils.ts +0 -6
- package/src/src/codegen/schemas-generator.ts +0 -87
- package/src/src/codegen/services-generator.ts +0 -77
- package/src/src/codegen/types.ts +0 -37
- package/src/src/collect/collector.ts +0 -142
- package/src/src/collect/helpers.ts +0 -36
- package/src/src/collect/types.ts +0 -21
- package/src/src/internal-utils.ts +0 -5
- package/src/src/parse/deref-proxy.ts +0 -70
- package/src/src/parse/openapi-types.ts +0 -949
- package/src/src/parse/parser.ts +0 -206
- package/src/src/parse/types.ts +0 -28
- package/src/src/transform/api-types.ts +0 -245
- package/src/src/transform/helpers.ts +0 -218
- package/src/src/transform/transform-document.ts +0 -35
- package/src/src/transform/transform-endpoint.ts +0 -331
- package/src/src/transform/transform-schema.ts +0 -217
- package/src/src/transform/transformer.ts +0 -53
- package/src/src/transform/types.ts +0 -52
- package/src/src/utils/action-provider.ts +0 -58
- package/src/src/utils/api-data.utils.ts +0 -48
- package/src/src/utils/array.utils.ts +0 -7
- package/src/src/utils/asset-manager.ts +0 -51
- package/src/src/utils/class.utils.ts +0 -40
- package/src/src/utils/common.utils.ts +0 -86
- package/src/src/utils/condition.ts +0 -7
- package/src/src/utils/endpoint.utils.ts +0 -10
- package/src/src/utils/error.utils.ts +0 -3
- package/src/src/utils/factory.ts +0 -42
- package/src/src/utils/file-system.utils.ts +0 -61
- package/src/src/utils/generator.utils.ts +0 -6
- package/src/src/utils/object.utils.ts +0 -32
- package/src/src/utils/schema.utils.ts +0 -148
- package/src/src/utils/source-builder.ts +0 -597
- package/src/src/utils/string-builder/options.ts +0 -19
- package/src/src/utils/string-builder/string-builder.ts +0 -165
- package/src/src/utils/string-builder/utils.ts +0 -69
- package/src/src/utils/string.utils.ts +0 -369
- package/src/src/utils/string.utils.types.ts +0 -179
- package/src/src/utils/type.utils.ts +0 -93
- package/src/src/utils/yaml-info.ts +0 -48
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 Marc Schmidt
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Marc Schmidt
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
# gOAst (@goast/core)
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/@goast/core)
|
|
4
|
-
[](https://jsr.io/@goast/core)
|
|
5
|
-
|
|
6
|
-
**gOAst** stands for **g**enerative **O**pen **A**PI **s**pecification **t**ransformer, a tool designed to transform
|
|
7
|
-
OpenAPI specifications into various forms with flexibility and extensibility at its core.
|
|
8
|
-
|
|
9
|
-
For more Information, please visit the [gOAst GitHub Repository](https://github.com/MaSch0212/goast/blob/main).
|
|
10
|
-
|
|
11
|
-
## Purpose 👍
|
|
12
|
-
|
|
13
|
-
The `@goast/core` package provides:
|
|
14
|
-
|
|
15
|
-
- entry points for using the **gOAst** library
|
|
16
|
-
- base classes for creating custom generators
|
|
17
|
-
- utilities for parsing and transforming OpenAPI specifications
|
|
18
|
-
|
|
19
|
-
## Usage Example 🚀
|
|
20
|
-
|
|
21
|
-
```typescript
|
|
22
|
-
import { OpenApiGenerator } from '@goast/core';
|
|
23
|
-
|
|
24
|
-
class MyGenerator implements OpenApiGenerationProvider {
|
|
25
|
-
generate(
|
|
26
|
-
context: OpenApiGeneratorContext<OpenApiGeneratorInput>,
|
|
27
|
-
config?: Partial<Readonly<Record<string, unknown>>>,
|
|
28
|
-
): Record<string, unknown> {
|
|
29
|
-
// Do something
|
|
30
|
-
return {};
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async function main() {
|
|
35
|
-
const generator = new OpenApiGenerator()
|
|
36
|
-
// Add a generator using a class
|
|
37
|
-
.useType(MyGenerator)
|
|
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
|
-
// Add a generator using an object implementing `OpenApiGenerationProvider`
|
|
44
|
-
.useValue({ generate: (ctx, cfg) => ({}) });
|
|
45
|
-
|
|
46
|
-
// Generate for one of more OpenAPI specification files
|
|
47
|
-
await generator.parseAndGenerate('path/to/openapi.json', 'path/to/another/openapi.yaml');
|
|
48
|
-
|
|
49
|
-
// Alternatively, you can generate output for all specifications in a directory.
|
|
50
|
-
// By default, it will only consider files within the directory (non-recursively) with the extensions: .json, .yaml, .yml.
|
|
51
|
-
await generator.parseAndGenerateFromDir('path/to/openapi/specs');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
main();
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
## Available Generator Packages 📚
|
|
58
|
-
|
|
59
|
-
[](https://www.npmjs.com/package/@goast/typescript)
|
|
60
|
-
[](https://www.npmjs.com/package/@goast/kotlin)
|
|
61
|
-
<br>
|
|
62
|
-
[](https://jsr.io/@goast/typescript)
|
|
63
|
-
[](https://jsr.io/@goast/kotlin)
|
|
64
|
-
|
|
65
|
-
## API Documentation 📖
|
|
66
|
-
|
|
67
|
-
The API documentation can be found [here](https://github.com/MaSch0212/goast/wiki).
|
|
1
|
+
# gOAst (@goast/core)
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@goast/core)
|
|
4
|
+
[](https://jsr.io/@goast/core)
|
|
5
|
+
|
|
6
|
+
**gOAst** stands for **g**enerative **O**pen **A**PI **s**pecification **t**ransformer, a tool designed to transform
|
|
7
|
+
OpenAPI specifications into various forms with flexibility and extensibility at its core.
|
|
8
|
+
|
|
9
|
+
For more Information, please visit the [gOAst GitHub Repository](https://github.com/MaSch0212/goast/blob/main).
|
|
10
|
+
|
|
11
|
+
## Purpose 👍
|
|
12
|
+
|
|
13
|
+
The `@goast/core` package provides:
|
|
14
|
+
|
|
15
|
+
- entry points for using the **gOAst** library
|
|
16
|
+
- base classes for creating custom generators
|
|
17
|
+
- utilities for parsing and transforming OpenAPI specifications
|
|
18
|
+
|
|
19
|
+
## Usage Example 🚀
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { OpenApiGenerator } from '@goast/core';
|
|
23
|
+
|
|
24
|
+
class MyGenerator implements OpenApiGenerationProvider {
|
|
25
|
+
generate(
|
|
26
|
+
context: OpenApiGeneratorContext<OpenApiGeneratorInput>,
|
|
27
|
+
config?: Partial<Readonly<Record<string, unknown>>>,
|
|
28
|
+
): Record<string, unknown> {
|
|
29
|
+
// Do something
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function main() {
|
|
35
|
+
const generator = new OpenApiGenerator()
|
|
36
|
+
// Add a generator using a class
|
|
37
|
+
.useType(MyGenerator)
|
|
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
|
+
// Add a generator using an object implementing `OpenApiGenerationProvider`
|
|
44
|
+
.useValue({ generate: (ctx, cfg) => ({}) });
|
|
45
|
+
|
|
46
|
+
// Generate for one of more OpenAPI specification files
|
|
47
|
+
await generator.parseAndGenerate('path/to/openapi.json', 'path/to/another/openapi.yaml');
|
|
48
|
+
|
|
49
|
+
// Alternatively, you can generate output for all specifications in a directory.
|
|
50
|
+
// By default, it will only consider files within the directory (non-recursively) with the extensions: .json, .yaml, .yml.
|
|
51
|
+
await generator.parseAndGenerateFromDir('path/to/openapi/specs');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
main();
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Available Generator Packages 📚
|
|
58
|
+
|
|
59
|
+
[](https://www.npmjs.com/package/@goast/typescript)
|
|
60
|
+
[](https://www.npmjs.com/package/@goast/kotlin)
|
|
61
|
+
<br>
|
|
62
|
+
[](https://jsr.io/@goast/typescript)
|
|
63
|
+
[](https://jsr.io/@goast/kotlin)
|
|
64
|
+
|
|
65
|
+
## API Documentation 📖
|
|
66
|
+
|
|
67
|
+
The API documentation can be found [here](https://github.com/MaSch0212/goast/wiki).
|
package/esm/src/parse/parser.js
CHANGED
|
@@ -92,6 +92,7 @@ export class OpenApiParser {
|
|
|
92
92
|
return result;
|
|
93
93
|
}
|
|
94
94
|
async resolveReference(file, ref) {
|
|
95
|
+
var _a;
|
|
95
96
|
const [refFile, refPath] = ref.$ref.split('#');
|
|
96
97
|
let absoluteRefFile = refFile;
|
|
97
98
|
if (!/\S/.test(refFile)) {
|
|
@@ -103,7 +104,7 @@ export class OpenApiParser {
|
|
|
103
104
|
const doc = await this.loadDocument(absoluteRefFile);
|
|
104
105
|
const value = refPath ? getDeepProperty(doc.document, refPath.replace(/[/]/g, '.')) : doc.document;
|
|
105
106
|
if (value && typeof value === 'object') {
|
|
106
|
-
return this.dereference(absoluteRefFile, refPath.split('/').filter(Boolean), value);
|
|
107
|
+
return this.dereference(absoluteRefFile, (_a = refPath === null || refPath === void 0 ? void 0 : refPath.split('/').filter(Boolean)) !== null && _a !== void 0 ? _a : [], value);
|
|
107
108
|
}
|
|
108
109
|
return undefined;
|
|
109
110
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goast/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-beta.1",
|
|
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)",
|
|
@@ -96,6 +96,7 @@ class OpenApiParser {
|
|
|
96
96
|
return result;
|
|
97
97
|
}
|
|
98
98
|
async resolveReference(file, ref) {
|
|
99
|
+
var _a;
|
|
99
100
|
const [refFile, refPath] = ref.$ref.split('#');
|
|
100
101
|
let absoluteRefFile = refFile;
|
|
101
102
|
if (!/\S/.test(refFile)) {
|
|
@@ -107,7 +108,7 @@ class OpenApiParser {
|
|
|
107
108
|
const doc = await this.loadDocument(absoluteRefFile);
|
|
108
109
|
const value = refPath ? getDeepProperty(doc.document, refPath.replace(/[/]/g, '.')) : doc.document;
|
|
109
110
|
if (value && typeof value === 'object') {
|
|
110
|
-
return this.dereference(absoluteRefFile, refPath.split('/').filter(Boolean), value);
|
|
111
|
+
return this.dereference(absoluteRefFile, (_a = refPath === null || refPath === void 0 ? void 0 : refPath.split('/').filter(Boolean)) !== null && _a !== void 0 ? _a : [], value);
|
|
111
112
|
}
|
|
112
113
|
return undefined;
|
|
113
114
|
}
|
package/src/_dnt.shims.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { fetch, File, FormData, Headers, Request, Response } from "undici";
|
|
2
|
-
export { fetch, File, FormData, Headers, Request, Response, type BodyInit, type HeadersInit, type ReferrerPolicy, type RequestInit, type RequestCache, type RequestMode, type RequestRedirect, type ResponseInit } from "undici";
|
|
3
|
-
|
|
4
|
-
const dntGlobals = {
|
|
5
|
-
fetch,
|
|
6
|
-
File,
|
|
7
|
-
FormData,
|
|
8
|
-
Headers,
|
|
9
|
-
Request,
|
|
10
|
-
Response,
|
|
11
|
-
};
|
|
12
|
-
export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
13
|
-
|
|
14
|
-
function createMergeProxy<T extends object, U extends object>(
|
|
15
|
-
baseObj: T,
|
|
16
|
-
extObj: U,
|
|
17
|
-
): Omit<T, keyof U> & U {
|
|
18
|
-
return new Proxy(baseObj, {
|
|
19
|
-
get(_target, prop, _receiver) {
|
|
20
|
-
if (prop in extObj) {
|
|
21
|
-
return (extObj as any)[prop];
|
|
22
|
-
} else {
|
|
23
|
-
return (baseObj as any)[prop];
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
set(_target, prop, value) {
|
|
27
|
-
if (prop in extObj) {
|
|
28
|
-
delete (extObj as any)[prop];
|
|
29
|
-
}
|
|
30
|
-
(baseObj as any)[prop] = value;
|
|
31
|
-
return true;
|
|
32
|
-
},
|
|
33
|
-
deleteProperty(_target, prop) {
|
|
34
|
-
let success = false;
|
|
35
|
-
if (prop in extObj) {
|
|
36
|
-
delete (extObj as any)[prop];
|
|
37
|
-
success = true;
|
|
38
|
-
}
|
|
39
|
-
if (prop in baseObj) {
|
|
40
|
-
delete (baseObj as any)[prop];
|
|
41
|
-
success = true;
|
|
42
|
-
}
|
|
43
|
-
return success;
|
|
44
|
-
},
|
|
45
|
-
ownKeys(_target) {
|
|
46
|
-
const baseKeys = Reflect.ownKeys(baseObj);
|
|
47
|
-
const extKeys = Reflect.ownKeys(extObj);
|
|
48
|
-
const extKeysSet = new Set(extKeys);
|
|
49
|
-
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
|
50
|
-
},
|
|
51
|
-
defineProperty(_target, prop, desc) {
|
|
52
|
-
if (prop in extObj) {
|
|
53
|
-
delete (extObj as any)[prop];
|
|
54
|
-
}
|
|
55
|
-
Reflect.defineProperty(baseObj, prop, desc);
|
|
56
|
-
return true;
|
|
57
|
-
},
|
|
58
|
-
getOwnPropertyDescriptor(_target, prop) {
|
|
59
|
-
if (prop in extObj) {
|
|
60
|
-
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
61
|
-
} else {
|
|
62
|
-
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
has(_target, prop) {
|
|
66
|
-
return prop in extObj || prop in baseObj;
|
|
67
|
-
},
|
|
68
|
-
}) as any;
|
|
69
|
-
}
|
package/src/mod.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export * from './src/ast/node.js';
|
|
2
|
-
|
|
3
|
-
export * from './src/codegen/config.js';
|
|
4
|
-
export * from './src/codegen/endpoints-generator.js';
|
|
5
|
-
export * from './src/codegen/generator.js';
|
|
6
|
-
export * from './src/codegen/schemas-generator.js';
|
|
7
|
-
export * from './src/codegen/services-generator.js';
|
|
8
|
-
export * from './src/codegen/types.js';
|
|
9
|
-
|
|
10
|
-
export * from './src/parse/openapi-types.js';
|
|
11
|
-
export * from './src/parse/parser.js';
|
|
12
|
-
export * from './src/parse/types.js';
|
|
13
|
-
|
|
14
|
-
export * from './src/transform/api-types.js';
|
|
15
|
-
export * from './src/transform/transformer.js';
|
|
16
|
-
|
|
17
|
-
export * from './src/utils/api-data.utils.js';
|
|
18
|
-
export * from './src/utils/array.utils.js';
|
|
19
|
-
export * from './src/utils/asset-manager.js';
|
|
20
|
-
export * from './src/utils/class.utils.js';
|
|
21
|
-
export * from './src/utils/common.utils.js';
|
|
22
|
-
export * from './src/utils/endpoint.utils.js';
|
|
23
|
-
export * from './src/utils/error.utils.js';
|
|
24
|
-
export * from './src/utils/factory.js';
|
|
25
|
-
export * from './src/utils/file-system.utils.js';
|
|
26
|
-
export * from './src/utils/generator.utils.js';
|
|
27
|
-
export * from './src/utils/object.utils.js';
|
|
28
|
-
export * from './src/utils/schema.utils.js';
|
|
29
|
-
export * from './src/utils/source-builder.js';
|
|
30
|
-
export * from './src/utils/string-builder/options.js';
|
|
31
|
-
export { type AppendParam, StringBuilder } from './src/utils/string-builder/string-builder.js';
|
|
32
|
-
export * from './src/utils/string-builder/utils.js';
|
|
33
|
-
export * from './src/utils/string.utils.js';
|
|
34
|
-
export * from './src/utils/string.utils.types.js';
|
|
35
|
-
export * from './src/utils/type.utils.js';
|
package/src/src/ast/node.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { StringBuilder } from '../utils/string-builder/string-builder.js';
|
|
2
|
-
import type { AppendValue } from '../utils/string-builder/utils.js';
|
|
3
|
-
import type { Prettify } from '../utils/type.utils.js';
|
|
4
|
-
|
|
5
|
-
const NODE_HISTORY_SYMBOL = Symbol('node-history');
|
|
6
|
-
type BuilderWithHistory<T extends StringBuilder = StringBuilder> = T & { [NODE_HISTORY_SYMBOL]?: AstNode[] };
|
|
7
|
-
|
|
8
|
-
export type AstNodeInject<TBuilder extends StringBuilder, TInjects extends string> = {
|
|
9
|
-
[K in `${'after' | 'before'}${Capitalize<TInjects>}`]?: AppendValue<TBuilder>;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export type AstNodeOptions<
|
|
13
|
-
// deno-lint-ignore no-explicit-any
|
|
14
|
-
TBase extends abstract new (...args: any) => any,
|
|
15
|
-
// deno-lint-ignore ban-types
|
|
16
|
-
TExtensions extends object = {},
|
|
17
|
-
> = Prettify<TExtensions & ConstructorParameters<TBase>[0]>;
|
|
18
|
-
|
|
19
|
-
export abstract class AstNode<TBuilder extends StringBuilder = StringBuilder, TInjects extends string = never> {
|
|
20
|
-
public inject: AstNodeInject<TBuilder, TInjects | ''>;
|
|
21
|
-
|
|
22
|
-
constructor(options: { inject?: AstNode<TBuilder, TInjects>['inject'] }) {
|
|
23
|
-
this.inject = options.inject ?? {};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public write(builder: TBuilder): void {
|
|
27
|
-
let history = (builder as BuilderWithHistory)[NODE_HISTORY_SYMBOL];
|
|
28
|
-
if (!history) {
|
|
29
|
-
history = [];
|
|
30
|
-
(builder as BuilderWithHistory)[NODE_HISTORY_SYMBOL] = history;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
history.push(this);
|
|
34
|
-
builder.append(this.inject.before);
|
|
35
|
-
this.onWrite(builder);
|
|
36
|
-
builder.append(this.inject.after);
|
|
37
|
-
history.pop();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
protected getParentNode(builder: TBuilder): AstNode | undefined {
|
|
41
|
-
const history = (builder as BuilderWithHistory)[NODE_HISTORY_SYMBOL];
|
|
42
|
-
return history?.at(-2);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
protected abstract onWrite(builder: TBuilder): void;
|
|
46
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { OpenApiParserOptions } from '../parse/types.js';
|
|
2
|
-
import { defaultOpenApiTransformerOptions } from '../transform/types.js';
|
|
3
|
-
import { defaultSourceBuilderOptions, type SourceBuilderOptions } from '../utils/source-builder.js';
|
|
4
|
-
|
|
5
|
-
export type OpenApiGeneratorConfig =
|
|
6
|
-
& SourceBuilderOptions
|
|
7
|
-
& OpenApiParserOptions
|
|
8
|
-
& {
|
|
9
|
-
/**
|
|
10
|
-
* The directory where the generated files should be saved.
|
|
11
|
-
* @default 'generated'
|
|
12
|
-
*/
|
|
13
|
-
outputDir: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Whether to clear the output directory before generating the files.
|
|
17
|
-
* @default true
|
|
18
|
-
*/
|
|
19
|
-
clearOutputDir: boolean;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* How to handle existing files in the output directory.
|
|
23
|
-
* - 'override': overwrite existing files.
|
|
24
|
-
* - 'skip': skip generating files that already exist.
|
|
25
|
-
* - 'error': throw an error if a file already exists.
|
|
26
|
-
*
|
|
27
|
-
* Is is recommended to use `'error'` to prevent issues of two schemas generating the same file and overwriting each other.
|
|
28
|
-
* If `clearOutputDir` is set to `false`, it is recommended to use `'override'` to ensure that the generated files are up to date.
|
|
29
|
-
* @default 'error'
|
|
30
|
-
*/
|
|
31
|
-
existingFileBehavior: 'override' | 'skip' | 'error';
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const defaultOpenApiGeneratorConfig: OpenApiGeneratorConfig = {
|
|
35
|
-
...defaultSourceBuilderOptions,
|
|
36
|
-
...defaultOpenApiTransformerOptions,
|
|
37
|
-
|
|
38
|
-
outputDir: 'generated',
|
|
39
|
-
clearOutputDir: true,
|
|
40
|
-
existingFileBehavior: 'error',
|
|
41
|
-
};
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type { ApiEndpoint } from '../transform/api-types.js';
|
|
2
|
-
import type { MaybePromise } from '../utils/type.utils.js';
|
|
3
|
-
import { type DefaultGenerationProviderConfig, OpenApiGenerationProviderBase } from './generator.js';
|
|
4
|
-
import { addSourceIfTest } from './internal-utils.js';
|
|
5
|
-
import type {
|
|
6
|
-
AnyConfig,
|
|
7
|
-
OpenApiGenerationProviderContext,
|
|
8
|
-
OpenApiGeneratorContext,
|
|
9
|
-
OpenApiGeneratorInput,
|
|
10
|
-
OpenApiGeneratorOutput,
|
|
11
|
-
} from './types.js';
|
|
12
|
-
|
|
13
|
-
export type OpenApiEndpointsGenerationProviderContext<
|
|
14
|
-
TInput extends OpenApiGeneratorInput,
|
|
15
|
-
TOutput extends OpenApiGeneratorOutput,
|
|
16
|
-
TConfig extends AnyConfig,
|
|
17
|
-
TEndpointOutput extends OpenApiGeneratorOutput,
|
|
18
|
-
> = OpenApiGenerationProviderContext<TInput, TConfig> & {
|
|
19
|
-
existingEndpointResults: Map<string, TEndpointOutput>;
|
|
20
|
-
output: TOutput;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export abstract class OpenApiEndpointsGenerationProviderBase<
|
|
24
|
-
TInput extends OpenApiGeneratorInput,
|
|
25
|
-
TOutput extends OpenApiGeneratorOutput,
|
|
26
|
-
TConfig extends AnyConfig,
|
|
27
|
-
TEndpointOutput extends OpenApiGeneratorOutput,
|
|
28
|
-
TContext extends OpenApiEndpointsGenerationProviderContext<TInput, TOutput, TConfig, TEndpointOutput>,
|
|
29
|
-
> extends OpenApiGenerationProviderBase<TInput, TOutput, TConfig, TContext> {
|
|
30
|
-
protected override getProviderContext(
|
|
31
|
-
context: OpenApiGeneratorContext<TInput>,
|
|
32
|
-
config: Partial<TConfig> | undefined,
|
|
33
|
-
defaultConfig: DefaultGenerationProviderConfig<TConfig>,
|
|
34
|
-
): OpenApiEndpointsGenerationProviderContext<TInput, TOutput, TConfig, TEndpointOutput> {
|
|
35
|
-
const ctx = super.getProviderContext(context, config, defaultConfig);
|
|
36
|
-
return Object.assign(ctx, {
|
|
37
|
-
existingEndpointResults: new Map<string, TEndpointOutput>(),
|
|
38
|
-
output: this.initResult(ctx),
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
protected override async onGenerate(ctx: TContext): Promise<TOutput> {
|
|
43
|
-
for (const endpoint of ctx.data.endpoints) {
|
|
44
|
-
await this.getEndpointResult(ctx, endpoint);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
await this.generateAdditionalFiles(ctx);
|
|
48
|
-
|
|
49
|
-
return ctx.output;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public async getEndpointResult(ctx: TContext, endpoint: ApiEndpoint): Promise<TEndpointOutput> {
|
|
53
|
-
const existingResult = ctx.existingEndpointResults.get(endpoint.id);
|
|
54
|
-
if (existingResult) return existingResult;
|
|
55
|
-
|
|
56
|
-
const result = await this.generateEndpoint(ctx, endpoint);
|
|
57
|
-
addSourceIfTest(ctx.config, result, () => `${endpoint.$src.file}#${endpoint.$src.path}`);
|
|
58
|
-
this.addEndpointResult(ctx, endpoint, result);
|
|
59
|
-
return result;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
protected abstract initResult(ctx: OpenApiGenerationProviderContext<TInput, TConfig>): TOutput;
|
|
63
|
-
|
|
64
|
-
protected abstract generateEndpoint(ctx: TContext, endpoint: ApiEndpoint): Promise<TEndpointOutput>;
|
|
65
|
-
|
|
66
|
-
protected abstract addEndpointResult(ctx: TContext, endpoint: ApiEndpoint, result: TEndpointOutput): void;
|
|
67
|
-
|
|
68
|
-
// deno-lint-ignore no-unused-vars
|
|
69
|
-
protected generateAdditionalFiles(ctx: TContext): MaybePromise<void> {
|
|
70
|
-
// Override if needed
|
|
71
|
-
}
|
|
72
|
-
}
|