@goast/core 0.7.0 → 0.7.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/dist/src/ast/node.d.ts +43 -0
- package/dist/src/ast/node.js +29 -0
- package/dist/src/codegen/config.d.ts +9 -0
- package/dist/src/codegen/config.js +4 -0
- package/dist/src/codegen/endpoints-generator.d.ts +32 -0
- package/dist/src/codegen/endpoints-generator.js +19 -0
- package/dist/src/codegen/generator.d.ts +108 -0
- package/dist/src/codegen/generator.js +103 -0
- package/dist/src/codegen/internal-utils.d.ts +8 -0
- package/dist/src/codegen/internal-utils.js +8 -0
- package/dist/src/codegen/schemas-generator.d.ts +33 -0
- package/dist/src/codegen/schemas-generator.js +20 -0
- package/dist/src/codegen/services-generator.d.ts +24 -0
- package/dist/src/codegen/services-generator.js +11 -0
- package/dist/src/codegen/types.d.ts +56 -0
- package/dist/src/collect/collector.d.ts +8 -0
- package/dist/src/collect/collector.js +8 -0
- package/dist/src/collect/helpers.d.ts +16 -0
- package/dist/src/collect/helpers.js +16 -0
- package/dist/src/collect/types.d.ts +28 -0
- package/dist/src/internal-utils.d.ts +7 -0
- package/dist/src/internal-utils.js +7 -0
- package/dist/src/parse/deref-proxy.d.ts +19 -0
- package/dist/src/parse/deref-proxy.js +19 -0
- package/dist/src/parse/openapi-types.d.ts +168 -0
- package/dist/src/parse/parser.d.ts +38 -0
- package/dist/src/parse/parser.js +38 -0
- package/dist/src/parse/types.d.ts +37 -0
- package/dist/src/parse/types.js +4 -0
- package/dist/src/transform/api-types.d.ts +408 -0
- package/dist/src/transform/helpers.d.ts +73 -0
- package/dist/src/transform/helpers.js +73 -0
- package/dist/src/transform/transform-document.d.ts +7 -0
- package/dist/src/transform/transform-document.js +7 -0
- package/dist/src/transform/transform-endpoint.d.ts +8 -0
- package/dist/src/transform/transform-endpoint.js +8 -0
- package/dist/src/transform/transform-schema.d.ts +10 -0
- package/dist/src/transform/transform-schema.js +10 -0
- package/dist/src/transform/transformer.d.ts +7 -0
- package/dist/src/transform/transformer.js +7 -0
- package/dist/src/transform/types.d.ts +61 -0
- package/dist/src/transform/types.js +4 -0
- package/dist/src/utils/action-provider.d.ts +38 -0
- package/dist/src/utils/action-provider.js +38 -0
- package/dist/src/utils/api-data.utils.d.ts +9 -0
- package/dist/src/utils/api-data.utils.js +9 -0
- package/dist/src/utils/array.utils.d.ts +7 -0
- package/dist/src/utils/array.utils.js +7 -0
- package/dist/src/utils/asset-manager.d.ts +22 -0
- package/dist/src/utils/asset-manager.js +22 -0
- package/dist/src/utils/class.utils.d.ts +22 -0
- package/dist/src/utils/class.utils.js +22 -0
- package/dist/src/utils/common.utils.d.ts +81 -0
- package/dist/src/utils/common.utils.js +81 -0
- package/dist/src/utils/condition.d.ts +22 -0
- package/dist/src/utils/endpoint.utils.d.ts +12 -0
- package/dist/src/utils/endpoint.utils.js +12 -0
- package/dist/src/utils/error.utils.d.ts +6 -0
- package/dist/src/utils/error.utils.js +6 -0
- package/dist/src/utils/factory.d.ts +45 -0
- package/dist/src/utils/factory.js +45 -0
- package/dist/src/utils/file-system.utils.d.ts +37 -0
- package/dist/src/utils/file-system.utils.js +20 -0
- package/dist/src/utils/generator.utils.d.ts +7 -0
- package/dist/src/utils/generator.utils.js +7 -0
- package/dist/src/utils/object.utils.d.ts +16 -0
- package/dist/src/utils/object.utils.js +16 -0
- package/dist/src/utils/schema-factory.d.ts +197 -0
- package/dist/src/utils/schema-factory.js +146 -0
- package/dist/src/utils/schema.utils.d.ts +15 -0
- package/dist/src/utils/schema.utils.js +15 -0
- package/dist/src/utils/source-builder.d.ts +103 -0
- package/dist/src/utils/source-builder.js +58 -0
- package/dist/src/utils/string-builder/string-builder.d.ts +24 -0
- package/dist/src/utils/string-builder/string-builder.js +11 -0
- package/dist/src/utils/string-builder/utils.d.ts +68 -0
- package/dist/src/utils/string-builder/utils.js +33 -0
- package/dist/src/utils/string.utils.d.ts +78 -0
- package/dist/src/utils/string.utils.js +64 -0
- package/dist/src/utils/string.utils.types.d.ts +34 -0
- package/dist/src/utils/type.utils.d.ts +132 -0
- package/dist/src/utils/type.utils.js +19 -0
- package/dist/src/utils/yaml-info.d.ts +35 -0
- package/dist/src/utils/yaml-info.js +25 -0
- package/package.json +1 -1
|
@@ -1,12 +1,50 @@
|
|
|
1
1
|
import type { ApiData } from '../transform/api-types.ts';
|
|
2
2
|
import type { OpenApiDocument } from './openapi-types.ts';
|
|
3
3
|
import { type Deref, type OpenApiParserOptions } from './types.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Loads OpenAPI 2.0, 3.0 and 3.1 documents from files or HTTP(S) URLs, in JSON or YAML, and resolves their `$ref`
|
|
6
|
+
* references, both local and remote. Dereferenced documents are then transformed into `ApiData`.
|
|
7
|
+
*
|
|
8
|
+
* Each document is loaded once per parser instance and cached. Relative file names are resolved against the current
|
|
9
|
+
* working directory, and relative `$ref` targets are resolved against the file that contains the reference.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const parser = new OpenApiParser();
|
|
13
|
+
* const apiData = await parser.parseApisAndTransform('./petstore.yaml');
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
4
16
|
export declare class OpenApiParser {
|
|
5
17
|
private readonly _loadedDocuments;
|
|
6
18
|
private readonly _config;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a parser.
|
|
21
|
+
* @param config Options that override the defaults in `defaultOpenApiParserOptions`.
|
|
22
|
+
*/
|
|
7
23
|
constructor(config?: Partial<OpenApiParserOptions>);
|
|
24
|
+
/**
|
|
25
|
+
* Parses one or more documents and transforms them into a single `ApiData` model. Each argument can be one file name
|
|
26
|
+
* or URL, or an array of them. Documents are parsed in parallel.
|
|
27
|
+
* @param fileNames File paths or HTTP(S) URLs, given individually or as arrays.
|
|
28
|
+
* @returns The API data built from all parsed documents.
|
|
29
|
+
*/
|
|
8
30
|
parseApisAndTransform(...fileNames: (string | string[])[]): Promise<ApiData>;
|
|
31
|
+
/**
|
|
32
|
+
* Loads and dereferences a single document without transforming it. Relative paths are resolved against the current
|
|
33
|
+
* working directory, and HTTP(S) URLs are downloaded.
|
|
34
|
+
* @param fileName File path or HTTP(S) URL of the document.
|
|
35
|
+
* @returns The dereferenced document. Its `$ref` references are followed when properties are read.
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* const doc = await parser.parseApi('./petstore.yaml');
|
|
39
|
+
* const title = doc.info?.title;
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
9
42
|
parseApi(fileName: string): Promise<Deref<OpenApiDocument>>;
|
|
43
|
+
/**
|
|
44
|
+
* Collects and transforms documents that were already dereferenced, for example by `parseApi`.
|
|
45
|
+
* @param apis The dereferenced documents to transform together.
|
|
46
|
+
* @returns The API data built from all given documents.
|
|
47
|
+
*/
|
|
10
48
|
transformApis(apis: Deref<OpenApiDocument>[]): ApiData;
|
|
11
49
|
private dereference;
|
|
12
50
|
private resolveReference;
|
package/dist/src/parse/parser.js
CHANGED
|
@@ -7,23 +7,61 @@ import { isNullish } from '../utils/common.utils.js';
|
|
|
7
7
|
import { getLineInfo, parseYamlWithInfo } from '../utils/yaml-info.js';
|
|
8
8
|
import { createDerefProxy } from './deref-proxy.js';
|
|
9
9
|
import { defaultOpenApiParserOptions } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Loads OpenAPI 2.0, 3.0 and 3.1 documents from files or HTTP(S) URLs, in JSON or YAML, and resolves their `$ref`
|
|
12
|
+
* references, both local and remote. Dereferenced documents are then transformed into `ApiData`.
|
|
13
|
+
*
|
|
14
|
+
* Each document is loaded once per parser instance and cached. Relative file names are resolved against the current
|
|
15
|
+
* working directory, and relative `$ref` targets are resolved against the file that contains the reference.
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const parser = new OpenApiParser();
|
|
19
|
+
* const apiData = await parser.parseApisAndTransform('./petstore.yaml');
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
10
22
|
export class OpenApiParser {
|
|
11
23
|
_loadedDocuments = new Map();
|
|
12
24
|
_config;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a parser.
|
|
27
|
+
* @param config Options that override the defaults in `defaultOpenApiParserOptions`.
|
|
28
|
+
*/
|
|
13
29
|
constructor(config) {
|
|
14
30
|
this._config = { ...defaultOpenApiParserOptions, ...config };
|
|
15
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Parses one or more documents and transforms them into a single `ApiData` model. Each argument can be one file name
|
|
34
|
+
* or URL, or an array of them. Documents are parsed in parallel.
|
|
35
|
+
* @param fileNames File paths or HTTP(S) URLs, given individually or as arrays.
|
|
36
|
+
* @returns The API data built from all parsed documents.
|
|
37
|
+
*/
|
|
16
38
|
async parseApisAndTransform(...fileNames) {
|
|
17
39
|
const flatFileNames = [].concat(...fileNames);
|
|
18
40
|
const apis = await Promise.all(flatFileNames.map((fileName) => this.parseApi(fileName)));
|
|
19
41
|
const transformed = this.transformApis(apis);
|
|
20
42
|
return transformed;
|
|
21
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Loads and dereferences a single document without transforming it. Relative paths are resolved against the current
|
|
46
|
+
* working directory, and HTTP(S) URLs are downloaded.
|
|
47
|
+
* @param fileName File path or HTTP(S) URL of the document.
|
|
48
|
+
* @returns The dereferenced document. Its `$ref` references are followed when properties are read.
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const doc = await parser.parseApi('./petstore.yaml');
|
|
52
|
+
* const title = doc.info?.title;
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
22
55
|
async parseApi(fileName) {
|
|
23
56
|
const absoluteFilePath = this.isUrl(fileName) ? fileName : path.resolve(cwd(), fileName);
|
|
24
57
|
const doc = await this.loadDocument(absoluteFilePath);
|
|
25
58
|
return await this.dereference(absoluteFilePath, [], doc.document);
|
|
26
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Collects and transforms documents that were already dereferenced, for example by `parseApi`.
|
|
62
|
+
* @param apis The dereferenced documents to transform together.
|
|
63
|
+
* @returns The API data built from all given documents.
|
|
64
|
+
*/
|
|
27
65
|
transformApis(apis) {
|
|
28
66
|
const collectedData = collectOpenApi(apis);
|
|
29
67
|
const transformedData = transformOpenApi(collectedData, this._config);
|
|
@@ -1,13 +1,34 @@
|
|
|
1
1
|
import { type OpenApiTransformerOptions } from '../transform/types.ts';
|
|
2
2
|
import type { OpenApiDiscriminator, OpenApiDocument, OpenApiReference, OpenApiSchema } from './openapi-types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Provenance of a dereferenced object, exposed on every such object as `$src`.
|
|
5
|
+
* Records the document the raw object was read from and where it sits in that document.
|
|
6
|
+
* @template T The raw OpenAPI object type that this source describes.
|
|
7
|
+
*/
|
|
3
8
|
export type DerefSource<T> = {
|
|
9
|
+
/**
|
|
10
|
+
* Absolute file path, or URL, of the document the object was loaded from.
|
|
11
|
+
*/
|
|
4
12
|
file: string;
|
|
13
|
+
/**
|
|
14
|
+
* Line and column of the object within that document.
|
|
15
|
+
*/
|
|
5
16
|
pos: {
|
|
6
17
|
line: number;
|
|
7
18
|
col: number;
|
|
8
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Slash-separated path from the document root to the object, such as `/components/schemas/Pet`.
|
|
22
|
+
* Segments are not JSON Pointer-escaped.
|
|
23
|
+
*/
|
|
9
24
|
path: string;
|
|
25
|
+
/**
|
|
26
|
+
* The dereferenced root document of the file that contains the object.
|
|
27
|
+
*/
|
|
10
28
|
document: Deref<OpenApiDocument>;
|
|
29
|
+
/**
|
|
30
|
+
* The raw, unresolved object as it was parsed, before any `$ref` was followed.
|
|
31
|
+
*/
|
|
11
32
|
originalComponent: T;
|
|
12
33
|
};
|
|
13
34
|
type _DerefDiscriminator = Omit<OpenApiDiscriminator, 'mapping'> & {
|
|
@@ -19,8 +40,24 @@ type _Deref<T extends object> = T extends OpenApiDiscriminator ? _DerefDiscrimin
|
|
|
19
40
|
$src: DerefSource<T>;
|
|
20
41
|
$ref?: Deref<T>;
|
|
21
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Consumer-facing view of the OpenAPI value `T`. Object properties and array elements are mapped recursively, the raw
|
|
45
|
+
* `$ref` key is replaced by `$ref?: Deref<T>` pointing at the resolved target, and every object gains
|
|
46
|
+
* `$src: DerefSource<T>`. Properties that a referencing object does not define are read from its target at runtime
|
|
47
|
+
* (see `createDerefProxy`).
|
|
48
|
+
* @template T The raw OpenAPI type being dereferenced.
|
|
49
|
+
* @see DerefSource
|
|
50
|
+
*/
|
|
22
51
|
export type Deref<T> = T extends object ? (T extends (infer A)[] ? Deref<A>[] : _Deref<T>) : T;
|
|
52
|
+
/**
|
|
53
|
+
* Options that control parsing. The parser accepts the same options as the transformer and passes them on unchanged.
|
|
54
|
+
* @see OpenApiTransformerOptions
|
|
55
|
+
*/
|
|
23
56
|
export type OpenApiParserOptions = OpenApiTransformerOptions;
|
|
57
|
+
/**
|
|
58
|
+
* Default parser options, a shallow copy of `defaultOpenApiTransformerOptions`.
|
|
59
|
+
* @see defaultOpenApiTransformerOptions
|
|
60
|
+
*/
|
|
24
61
|
export declare const defaultOpenApiParserOptions: {
|
|
25
62
|
unknownTypeBehavior: 'keep-unknown' | 'object-if-properties' | 'always-object';
|
|
26
63
|
};
|
package/dist/src/parse/types.js
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import { defaultOpenApiTransformerOptions } from '../transform/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Default parser options, a shallow copy of `defaultOpenApiTransformerOptions`.
|
|
4
|
+
* @see defaultOpenApiTransformerOptions
|
|
5
|
+
*/
|
|
2
6
|
export const defaultOpenApiParserOptions = { ...defaultOpenApiTransformerOptions };
|