@goast/core 0.5.3 → 0.6.0-beta.2
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/codegen/config.d.ts +11 -2
- package/esm/src/codegen/config.d.ts.map +1 -1
- package/esm/src/parse/openapi-types.d.ts +4 -0
- package/esm/src/parse/openapi-types.d.ts.map +1 -1
- package/esm/src/transform/api-types.d.ts +14 -0
- package/esm/src/transform/api-types.d.ts.map +1 -1
- package/esm/src/transform/helpers.d.ts +6 -0
- package/esm/src/transform/helpers.d.ts.map +1 -1
- package/esm/src/transform/helpers.js +34 -5
- package/esm/src/transform/transform-endpoint.js +1 -0
- package/esm/src/transform/transform-schema.d.ts.map +1 -1
- package/esm/src/transform/transform-schema.js +32 -21
- package/esm/src/utils/file-system.utils.d.ts.map +1 -1
- package/esm/src/utils/file-system.utils.js +36 -4
- package/esm/src/utils/schema.utils.d.ts.map +1 -1
- package/esm/src/utils/schema.utils.js +91 -11
- package/esm/src/utils/string.utils.d.ts +19 -0
- package/esm/src/utils/string.utils.d.ts.map +1 -1
- package/esm/src/utils/string.utils.js +25 -0
- package/package.json +1 -1
- package/script/src/codegen/config.d.ts +11 -2
- package/script/src/codegen/config.d.ts.map +1 -1
- package/script/src/parse/openapi-types.d.ts +4 -0
- package/script/src/parse/openapi-types.d.ts.map +1 -1
- package/script/src/transform/api-types.d.ts +14 -0
- package/script/src/transform/api-types.d.ts.map +1 -1
- package/script/src/transform/helpers.d.ts +6 -0
- package/script/src/transform/helpers.d.ts.map +1 -1
- package/script/src/transform/helpers.js +37 -5
- package/script/src/transform/transform-endpoint.js +1 -0
- package/script/src/transform/transform-schema.d.ts.map +1 -1
- package/script/src/transform/transform-schema.js +31 -20
- package/script/src/utils/file-system.utils.d.ts.map +1 -1
- package/script/src/utils/file-system.utils.js +35 -3
- package/script/src/utils/schema.utils.d.ts.map +1 -1
- package/script/src/utils/schema.utils.js +91 -11
- package/script/src/utils/string.utils.d.ts +19 -0
- package/script/src/utils/string.utils.d.ts.map +1 -1
- package/script/src/utils/string.utils.js +26 -0
- 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
|
@@ -109,6 +109,25 @@ export declare function toCustomCase(str: Nullable<string>, options: CustomCaseO
|
|
|
109
109
|
* @param str The string to escape.
|
|
110
110
|
*/
|
|
111
111
|
export declare function escapeRegExp(str: string): string;
|
|
112
|
+
/**
|
|
113
|
+
* Compares two strings for sorting, case-insensitively, without any dependency on the host locale.
|
|
114
|
+
*
|
|
115
|
+
* Deliberately not `String.prototype.localeCompare`: its collation depends on the host locale and ICU
|
|
116
|
+
* version, so the same input would sort differently on different machines — which would make
|
|
117
|
+
* generated output non-reproducible. `toLowerCase` is Unicode default case conversion and carries no
|
|
118
|
+
* locale dependency.
|
|
119
|
+
*
|
|
120
|
+
* Comparison is case-insensitive so that, for example, `awaitBody` sorts alphabetically beside
|
|
121
|
+
* `WebClient` rather than after every capitalized name. Strings differing only in case fall back to a
|
|
122
|
+
* case-sensitive comparison, so their relative order is still stable. Non-ASCII characters order by
|
|
123
|
+
* code point rather than alphabetically — `Ähre` sorts after `Zebra` — which is less pretty than
|
|
124
|
+
* locale collation but entirely reproducible.
|
|
125
|
+
*
|
|
126
|
+
* @param a The first string.
|
|
127
|
+
* @param b The second string.
|
|
128
|
+
* @returns A negative number if `a` sorts first, a positive number if `b` does, otherwise 0.
|
|
129
|
+
*/
|
|
130
|
+
export declare function compareString(a: string, b: string): number;
|
|
112
131
|
/**
|
|
113
132
|
* Removes characters from a string and, if necessary, inserts new characters in their place, returning the spliced string.
|
|
114
133
|
* @param str The string to splice.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.utils.d.ts","sourceRoot":"","sources":["../../../src/src/utils/string.utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,gBAAgB,EAEhB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,gBA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AgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAEpG;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAI9C;AA6BD,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,GAAE,OAAc,GAAG,MAAM,CAK3E;AACD,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,GAAE,OAAc,GAAG,MAAM,CAK7E;AACD,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,GAAE,OAAc,GAAG,MAAM,CAOxE;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAW1D"}
|
|
@@ -14,6 +14,7 @@ exports.toKebabCase = toKebabCase;
|
|
|
14
14
|
exports.toSnakeCase = toSnakeCase;
|
|
15
15
|
exports.toCustomCase = toCustomCase;
|
|
16
16
|
exports.escapeRegExp = escapeRegExp;
|
|
17
|
+
exports.compareString = compareString;
|
|
17
18
|
exports.spliceString = spliceString;
|
|
18
19
|
exports.trimIndent = trimIndent;
|
|
19
20
|
exports.trimEnd = trimEnd;
|
|
@@ -267,6 +268,31 @@ function toCustomCase(str, options) {
|
|
|
267
268
|
function escapeRegExp(str) {
|
|
268
269
|
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
269
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Compares two strings for sorting, case-insensitively, without any dependency on the host locale.
|
|
273
|
+
*
|
|
274
|
+
* Deliberately not `String.prototype.localeCompare`: its collation depends on the host locale and ICU
|
|
275
|
+
* version, so the same input would sort differently on different machines — which would make
|
|
276
|
+
* generated output non-reproducible. `toLowerCase` is Unicode default case conversion and carries no
|
|
277
|
+
* locale dependency.
|
|
278
|
+
*
|
|
279
|
+
* Comparison is case-insensitive so that, for example, `awaitBody` sorts alphabetically beside
|
|
280
|
+
* `WebClient` rather than after every capitalized name. Strings differing only in case fall back to a
|
|
281
|
+
* case-sensitive comparison, so their relative order is still stable. Non-ASCII characters order by
|
|
282
|
+
* code point rather than alphabetically — `Ähre` sorts after `Zebra` — which is less pretty than
|
|
283
|
+
* locale collation but entirely reproducible.
|
|
284
|
+
*
|
|
285
|
+
* @param a The first string.
|
|
286
|
+
* @param b The second string.
|
|
287
|
+
* @returns A negative number if `a` sorts first, a positive number if `b` does, otherwise 0.
|
|
288
|
+
*/
|
|
289
|
+
function compareString(a, b) {
|
|
290
|
+
const lowerA = a.toLowerCase();
|
|
291
|
+
const lowerB = b.toLowerCase();
|
|
292
|
+
if (lowerA !== lowerB)
|
|
293
|
+
return lowerA < lowerB ? -1 : 1;
|
|
294
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
295
|
+
}
|
|
270
296
|
/**
|
|
271
297
|
* Removes characters from a string and, if necessary, inserts new characters in their place, returning the spliced string.
|
|
272
298
|
* @param str The string to splice.
|
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
|
-
}
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { resolve } from 'node:path';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import fs from 'fs-extra';
|
|
5
|
-
|
|
6
|
-
import { OpenApiParser } from '../parse/parser.js';
|
|
7
|
-
import type { ApiData } from '../transform/api-types.js';
|
|
8
|
-
import { ActionProvider } from '../utils/action-provider.js';
|
|
9
|
-
import { type DirectoryScanOptions, getFiles } from '../utils/file-system.utils.js';
|
|
10
|
-
import type { EmptyConstructor, Merge } from '../utils/type.utils.js';
|
|
11
|
-
import { defaultOpenApiGeneratorConfig, type OpenApiGeneratorConfig } from './config.js';
|
|
12
|
-
import type {
|
|
13
|
-
AnyConfig,
|
|
14
|
-
OpenApiGenerationProvider,
|
|
15
|
-
OpenApiGenerationProviderContext,
|
|
16
|
-
OpenApiGenerationProviderFn,
|
|
17
|
-
OpenApiGeneratorContext,
|
|
18
|
-
OpenApiGeneratorInput,
|
|
19
|
-
OpenApiGeneratorOutput,
|
|
20
|
-
} from './types.js';
|
|
21
|
-
|
|
22
|
-
type OpenApiGenerationProviders = {
|
|
23
|
-
provider: ActionProvider<OpenApiGenerationProviderFn>;
|
|
24
|
-
config: AnyConfig | undefined;
|
|
25
|
-
}[];
|
|
26
|
-
|
|
27
|
-
type VInput<TActual, TExpected> = TExpected extends TActual ? TActual
|
|
28
|
-
: { __error: 'The current output of the generator does not satisfy the input of this generator.' };
|
|
29
|
-
|
|
30
|
-
class _OpenApiGenerator<TOutput extends OpenApiGeneratorInput> {
|
|
31
|
-
private readonly _providers: OpenApiGenerationProviders;
|
|
32
|
-
private readonly _config: OpenApiGeneratorConfig;
|
|
33
|
-
private readonly _parser: OpenApiParser;
|
|
34
|
-
|
|
35
|
-
constructor(config: OpenApiGeneratorConfig, providers: OpenApiGenerationProviders, parser: OpenApiParser) {
|
|
36
|
-
this._providers = providers;
|
|
37
|
-
this._config = config;
|
|
38
|
-
this._parser = parser;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public use<PInput extends OpenApiGeneratorInput, POutput extends OpenApiGeneratorOutput, PConfig extends AnyConfig>(
|
|
42
|
-
provider: ActionProvider<OpenApiGenerationProviderFn<VInput<PInput, TOutput>, POutput, PConfig>>,
|
|
43
|
-
config?: Partial<PConfig>,
|
|
44
|
-
): _OpenApiGenerator<Merge<[TOutput, POutput]>> {
|
|
45
|
-
// deno-lint-ignore no-explicit-any
|
|
46
|
-
this._providers.push({ provider: provider as any, config });
|
|
47
|
-
return new _OpenApiGenerator<Merge<[TOutput, POutput]>>(this._config, [...this._providers], this._parser);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public useType<
|
|
51
|
-
PInput extends OpenApiGeneratorInput,
|
|
52
|
-
POutput extends OpenApiGeneratorOutput,
|
|
53
|
-
PConfig extends AnyConfig,
|
|
54
|
-
>(
|
|
55
|
-
type: EmptyConstructor<OpenApiGenerationProvider<VInput<PInput, TOutput>, POutput, PConfig>>,
|
|
56
|
-
config?: Partial<PConfig>,
|
|
57
|
-
): _OpenApiGenerator<Merge<[TOutput, POutput]>> {
|
|
58
|
-
return this.use(ActionProvider.fromType(type, 'generate'), config);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public useFn<PInput extends TOutput, POutput extends OpenApiGeneratorOutput, PConfig extends AnyConfig>(
|
|
62
|
-
fn: OpenApiGenerationProviderFn<VInput<PInput, TOutput>, POutput, PConfig>,
|
|
63
|
-
config?: Partial<PConfig>,
|
|
64
|
-
): _OpenApiGenerator<Merge<[TOutput, POutput]>> {
|
|
65
|
-
return this.use(ActionProvider.fromFn(fn), config);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
public useValue<PInput extends TOutput, POutput extends OpenApiGeneratorOutput, PConfig extends AnyConfig>(
|
|
69
|
-
value: OpenApiGenerationProvider<VInput<PInput, TOutput>, POutput, PConfig>,
|
|
70
|
-
config?: Partial<PConfig>,
|
|
71
|
-
): _OpenApiGenerator<Merge<[TOutput, POutput]>> {
|
|
72
|
-
return this.use(ActionProvider.fromValue(value, 'generate'), config);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
public async generate<T extends ApiData>(data: T): Promise<TOutput> {
|
|
76
|
-
const absOutputPath = resolve(this._config.outputDir);
|
|
77
|
-
if (this._config.clearOutputDir) {
|
|
78
|
-
await fs.emptyDir(absOutputPath);
|
|
79
|
-
} else {
|
|
80
|
-
await fs.ensureDir(absOutputPath);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
this._providers.forEach(({ config }) => {
|
|
84
|
-
if (config && 'outputDir' in config && config.outputDir && typeof config.outputDir === 'string') {
|
|
85
|
-
const providerOutputDir = resolve(config.outputDir);
|
|
86
|
-
if (this._config.clearOutputDir) {
|
|
87
|
-
fs.emptyDirSync(providerOutputDir);
|
|
88
|
-
} else {
|
|
89
|
-
fs.ensureDirSync(providerOutputDir);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
let input = {} as TOutput;
|
|
95
|
-
for (const generator of this._providers) {
|
|
96
|
-
const context = {
|
|
97
|
-
data,
|
|
98
|
-
input,
|
|
99
|
-
config: this._config,
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const result = await generator.provider.run(context, generator.config);
|
|
103
|
-
if (result) {
|
|
104
|
-
input = mergeDeep(input, result);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return input;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public async parseAndGenerate(...fileNames: (string | string[])[]): Promise<TOutput> {
|
|
112
|
-
const data = await this._parser.parseApisAndTransform(...fileNames);
|
|
113
|
-
return await this.generate(data);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
public async parseAndGenerateFromDir(dir: string, options?: Partial<DirectoryScanOptions>): Promise<TOutput> {
|
|
117
|
-
const filter = (file: string) =>
|
|
118
|
-
(file.endsWith('.yml') || file.endsWith('.yaml') || file.endsWith('.json')) && (options?.filter?.(file) ?? true);
|
|
119
|
-
return this.parseAndGenerate(...(await getFiles(dir, { ...options, filter })));
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// deno-lint-ignore ban-types
|
|
124
|
-
export class OpenApiGenerator extends _OpenApiGenerator<{}> {
|
|
125
|
-
constructor(config?: Partial<OpenApiGeneratorConfig>) {
|
|
126
|
-
super(
|
|
127
|
-
{ ...defaultOpenApiGeneratorConfig, ...config },
|
|
128
|
-
[],
|
|
129
|
-
new OpenApiParser({ ...defaultOpenApiGeneratorConfig, ...config }),
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function mergeDeep<T extends Record<string, unknown>, U extends Record<string, unknown>[]>(
|
|
135
|
-
target: T,
|
|
136
|
-
...sources: U
|
|
137
|
-
): T & U[number] {
|
|
138
|
-
if (!sources.length) return target;
|
|
139
|
-
const source = sources.shift();
|
|
140
|
-
|
|
141
|
-
for (const key in source) {
|
|
142
|
-
const value = source[key];
|
|
143
|
-
if (value && typeof value === 'object') {
|
|
144
|
-
if (!target[key]) Object.assign(target, { [key]: value });
|
|
145
|
-
else mergeDeep(target[key] as Record<string, unknown>, value as Record<string, unknown>);
|
|
146
|
-
} else if (Array.isArray(value)) {
|
|
147
|
-
if (!target[key]) Object.assign(target, { [key]: value });
|
|
148
|
-
else Object.assign(target, { [key]: [...(target[key] as Iterable<unknown>), ...value] });
|
|
149
|
-
} else {
|
|
150
|
-
Object.assign(target, { [key]: value });
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return mergeDeep(target, ...sources);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export type DefaultGenerationProviderConfig<T extends AnyConfig> =
|
|
158
|
-
& Omit<T, keyof OpenApiGeneratorConfig>
|
|
159
|
-
& Partial<Pick<T, keyof OpenApiGeneratorConfig>>;
|
|
160
|
-
|
|
161
|
-
export abstract class OpenApiGenerationProviderBase<
|
|
162
|
-
TInput extends OpenApiGeneratorInput,
|
|
163
|
-
TOutput extends OpenApiGeneratorOutput,
|
|
164
|
-
TConfig extends AnyConfig,
|
|
165
|
-
TContext extends OpenApiGenerationProviderContext<TInput, TConfig>,
|
|
166
|
-
> implements OpenApiGenerationProvider<TInput, TOutput, TConfig> {
|
|
167
|
-
public async generate(
|
|
168
|
-
context: OpenApiGeneratorContext<TInput>,
|
|
169
|
-
config?: Partial<TConfig> | undefined,
|
|
170
|
-
): Promise<TOutput> {
|
|
171
|
-
const ctx = await this.buildContext(context, config);
|
|
172
|
-
return await this.onGenerate(ctx);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
protected getProviderContext(
|
|
176
|
-
context: OpenApiGeneratorContext<TInput>,
|
|
177
|
-
config: Partial<TConfig> | undefined,
|
|
178
|
-
defaultConfig: DefaultGenerationProviderConfig<TConfig>,
|
|
179
|
-
): OpenApiGenerationProviderContext<TInput, TConfig> {
|
|
180
|
-
const c = { ...context.config, ...defaultConfig, ...config } as unknown as OpenApiGeneratorConfig & TConfig;
|
|
181
|
-
return Object.assign(context, {
|
|
182
|
-
config: c,
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
protected abstract buildContext(
|
|
187
|
-
context: OpenApiGeneratorContext<TInput>,
|
|
188
|
-
config?: Partial<TConfig> | undefined,
|
|
189
|
-
): TContext | Promise<TContext>;
|
|
190
|
-
|
|
191
|
-
protected abstract onGenerate(ctx: TContext): TOutput | Promise<TOutput>;
|
|
192
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import type { ApiSchema } from '../transform/api-types.js';
|
|
2
|
-
import { getSchemaReference } from '../utils/schema.utils.js';
|
|
3
|
-
import type { MaybePromise } from '../utils/type.utils.js';
|
|
4
|
-
import { type DefaultGenerationProviderConfig, OpenApiGenerationProviderBase } from './generator.js';
|
|
5
|
-
import { addSourceIfTest } from './internal-utils.js';
|
|
6
|
-
import type {
|
|
7
|
-
AnyConfig,
|
|
8
|
-
OpenApiGenerationProviderContext,
|
|
9
|
-
OpenApiGeneratorContext,
|
|
10
|
-
OpenApiGeneratorInput,
|
|
11
|
-
OpenApiGeneratorOutput,
|
|
12
|
-
} from './types.js';
|
|
13
|
-
|
|
14
|
-
export type OpenApiSchemasGenerationProviderContext<
|
|
15
|
-
TInput extends OpenApiGeneratorInput,
|
|
16
|
-
TOutput extends OpenApiGeneratorOutput,
|
|
17
|
-
TConfig extends AnyConfig,
|
|
18
|
-
TSchemaOutput extends OpenApiGeneratorOutput,
|
|
19
|
-
> = OpenApiGenerationProviderContext<TInput, TConfig> & {
|
|
20
|
-
existingSchemaResults: Map<string, TSchemaOutput>;
|
|
21
|
-
output: TOutput;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export abstract class OpenApiSchemasGenerationProviderBase<
|
|
25
|
-
TInput extends OpenApiGeneratorInput,
|
|
26
|
-
TOutput extends OpenApiGeneratorOutput,
|
|
27
|
-
TConfig extends AnyConfig,
|
|
28
|
-
TSchemaOutput extends OpenApiGeneratorOutput,
|
|
29
|
-
TContext extends OpenApiSchemasGenerationProviderContext<TInput, TOutput, TConfig, TSchemaOutput>,
|
|
30
|
-
> extends OpenApiGenerationProviderBase<TInput, TOutput, TConfig, TContext> {
|
|
31
|
-
protected override getProviderContext(
|
|
32
|
-
context: OpenApiGeneratorContext<TInput>,
|
|
33
|
-
config: Partial<TConfig> | undefined,
|
|
34
|
-
defaultConfig: DefaultGenerationProviderConfig<TConfig>,
|
|
35
|
-
): OpenApiSchemasGenerationProviderContext<TInput, TOutput, TConfig, TSchemaOutput> {
|
|
36
|
-
const ctx = super.getProviderContext(context, config, defaultConfig);
|
|
37
|
-
return Object.assign(ctx, {
|
|
38
|
-
existingSchemaResults: new Map<string, TSchemaOutput>(),
|
|
39
|
-
output: this.initResult(ctx),
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
protected override async onGenerate(ctx: TContext): Promise<TOutput> {
|
|
44
|
-
for (const schema of ctx.data.schemas) {
|
|
45
|
-
await this.getSchemaResult(ctx, schema);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
await this.generateAdditionalFiles(ctx);
|
|
49
|
-
|
|
50
|
-
return ctx.output;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public async getSchemaResult(ctx: TContext, schema: ApiSchema): Promise<TSchemaOutput> {
|
|
54
|
-
const existingResult = ctx.existingSchemaResults.get(schema.id);
|
|
55
|
-
if (existingResult) return existingResult;
|
|
56
|
-
|
|
57
|
-
let result: TSchemaOutput;
|
|
58
|
-
const reference = this.getSchemaReference(ctx, schema);
|
|
59
|
-
if (reference) {
|
|
60
|
-
result = await this.getSchemaResult(ctx, reference);
|
|
61
|
-
} else {
|
|
62
|
-
result = await this.generateSchema(ctx, schema);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
addSourceIfTest(ctx.config, result, () => `${schema.$src.file}#${schema.$src.path}`);
|
|
66
|
-
ctx.existingSchemaResults.set(schema.id, result);
|
|
67
|
-
this.addSchemaResult(ctx, schema, result);
|
|
68
|
-
return result;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// deno-lint-ignore no-unused-vars
|
|
72
|
-
protected getSchemaReference(ctx: TContext, schema: ApiSchema): ApiSchema | undefined {
|
|
73
|
-
const ref = getSchemaReference(schema, ['description']);
|
|
74
|
-
return ref.id !== schema.id ? ref : undefined;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
protected abstract initResult(ctx: OpenApiGenerationProviderContext<TInput, TConfig>): TOutput;
|
|
78
|
-
|
|
79
|
-
protected abstract generateSchema(ctx: TContext, schema: ApiSchema): MaybePromise<TSchemaOutput>;
|
|
80
|
-
|
|
81
|
-
protected abstract addSchemaResult(ctx: TContext, schema: ApiSchema, result: TSchemaOutput): void;
|
|
82
|
-
|
|
83
|
-
// deno-lint-ignore no-unused-vars
|
|
84
|
-
protected generateAdditionalFiles(ctx: TContext): MaybePromise<void> {
|
|
85
|
-
// Override if needed
|
|
86
|
-
}
|
|
87
|
-
}
|