@openapi-qraft/plugin 1.8.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.
- package/CHANGELOG.md +7 -0
- package/README.md +1 -0
- package/dist/lib/GeneratorFile.d.ts +9 -0
- package/dist/lib/GeneratorFile.js +2 -0
- package/dist/lib/GeneratorFile.js.map +1 -0
- package/dist/lib/OutputOptions.d.ts +6 -0
- package/dist/lib/OutputOptions.js +2 -0
- package/dist/lib/OutputOptions.js.map +1 -0
- package/dist/lib/QraftCommand.d.ts +35 -0
- package/dist/lib/QraftCommand.js +103 -0
- package/dist/lib/QraftCommand.js.map +1 -0
- package/dist/lib/QraftCommandPlugin.d.ts +4 -0
- package/dist/lib/QraftCommandPlugin.js +2 -0
- package/dist/lib/QraftCommandPlugin.js.map +1 -0
- package/dist/lib/fileHeader.d.ts +1 -0
- package/dist/lib/fileHeader.js +3 -0
- package/dist/lib/fileHeader.js.map +1 -0
- package/dist/lib/open-api/OpenAPISchemaType.d.ts +31 -0
- package/dist/lib/open-api/OpenAPISchemaType.js +2 -0
- package/dist/lib/open-api/OpenAPISchemaType.js.map +1 -0
- package/dist/lib/open-api/getContent.d.ts +5 -0
- package/dist/lib/open-api/getContent.js +23 -0
- package/dist/lib/open-api/getContent.js.map +1 -0
- package/dist/lib/open-api/getDocumentServices.d.ts +12 -0
- package/dist/lib/open-api/getDocumentServices.js +7 -0
- package/dist/lib/open-api/getDocumentServices.js.map +1 -0
- package/dist/lib/open-api/getOperationName.d.ts +6 -0
- package/dist/lib/open-api/getOperationName.js +20 -0
- package/dist/lib/open-api/getOperationName.js.map +1 -0
- package/dist/lib/open-api/getServiceName.d.ts +5 -0
- package/dist/lib/open-api/getServiceName.js +13 -0
- package/dist/lib/open-api/getServiceName.js.map +1 -0
- package/dist/lib/open-api/getServiceNamesByOperationEndpoint.d.ts +4 -0
- package/dist/lib/open-api/getServiceNamesByOperationEndpoint.js +30 -0
- package/dist/lib/open-api/getServiceNamesByOperationEndpoint.js.map +1 -0
- package/dist/lib/open-api/getServiceNamesByOperationTags.d.ts +1 -0
- package/dist/lib/open-api/getServiceNamesByOperationTags.js +11 -0
- package/dist/lib/open-api/getServiceNamesByOperationTags.js.map +1 -0
- package/dist/lib/open-api/getServices.d.ts +39 -0
- package/dist/lib/open-api/getServices.js +112 -0
- package/dist/lib/open-api/getServices.js.map +1 -0
- package/dist/lib/open-api/readSchema.d.ts +7 -0
- package/dist/lib/open-api/readSchema.js +15 -0
- package/dist/lib/open-api/readSchema.js.map +1 -0
- package/dist/lib/writeGeneratorFiles.d.ts +6 -0
- package/dist/lib/writeGeneratorFiles.js +51 -0
- package/dist/lib/writeGeneratorFiles.js.map +1 -0
- package/package.json +53 -0
- package/src/lib/GeneratorFile.ts +5 -0
- package/src/lib/OutputOptions.ts +6 -0
- package/src/lib/QraftCommand.ts +192 -0
- package/src/lib/QraftCommandPlugin.ts +5 -0
- package/src/lib/fileHeader.ts +2 -0
- package/src/lib/open-api/OpenAPISchemaType.ts +31 -0
- package/src/lib/open-api/getContent.ts +26 -0
- package/src/lib/open-api/getDocumentServices.ts +19 -0
- package/src/lib/open-api/getOperationName.ts +28 -0
- package/src/lib/open-api/getServiceName.ts +14 -0
- package/src/lib/open-api/getServiceNamesByOperationEndpoint.ts +70 -0
- package/src/lib/open-api/getServiceNamesByOperationTags.ts +15 -0
- package/src/lib/open-api/getServices.ts +208 -0
- package/src/lib/open-api/readSchema.ts +27 -0
- package/src/lib/writeGeneratorFiles.ts +83 -0
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# shared
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GeneratorFile.js","sourceRoot":"","sources":["../../src/lib/GeneratorFile.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OutputOptions.js","sourceRoot":"","sources":["../../src/lib/OutputOptions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { Ora } from 'ora';
|
|
3
|
+
import { GeneratorFile } from './GeneratorFile.js';
|
|
4
|
+
import { Service } from './open-api/getServices.js';
|
|
5
|
+
import { OutputOptions } from './OutputOptions.js';
|
|
6
|
+
export declare class QraftCommand extends Command {
|
|
7
|
+
#private;
|
|
8
|
+
constructor();
|
|
9
|
+
action(callback: QraftCommandActionCallback): this;
|
|
10
|
+
}
|
|
11
|
+
export type QraftCommandActionCallback = (options: {
|
|
12
|
+
/**
|
|
13
|
+
* Command inputs, e.g. `bin <input> [options]` where `<input>` is the `inputs` item
|
|
14
|
+
*/
|
|
15
|
+
inputs: string[];
|
|
16
|
+
/**
|
|
17
|
+
* Command arguments, e.g. `bin <input> [options]` where `[options]` is the `args`
|
|
18
|
+
*/
|
|
19
|
+
args: Record<string, any>;
|
|
20
|
+
/**
|
|
21
|
+
* Resolve the generator files
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Spinner instance
|
|
25
|
+
*/
|
|
26
|
+
spinner: Ora;
|
|
27
|
+
/**
|
|
28
|
+
* OpenAPI services
|
|
29
|
+
*/
|
|
30
|
+
services: Service[];
|
|
31
|
+
/**
|
|
32
|
+
* Output options
|
|
33
|
+
*/
|
|
34
|
+
output: OutputOptions;
|
|
35
|
+
}, resolve: (files: GeneratorFile[]) => Promise<void>) => void | Promise<void>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import c from 'ansi-colors';
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { sep } from 'node:path';
|
|
4
|
+
import process from 'node:process';
|
|
5
|
+
import { pathToFileURL, URL } from 'node:url';
|
|
6
|
+
import ora from 'ora';
|
|
7
|
+
import { getDocumentServices } from './open-api/getDocumentServices.js';
|
|
8
|
+
import { writeGeneratorFiles } from './writeGeneratorFiles.js';
|
|
9
|
+
export class QraftCommand extends Command {
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
this.usage('[input] [options]')
|
|
13
|
+
.argument('[input]', 'Input OpenAPI Schema file path, URL (json, yml)', null)
|
|
14
|
+
.requiredOption('-o, --output-dir <path>', 'Output directory for generated services')
|
|
15
|
+
.option('-rm, --clean', 'Clean output directory before generating services')
|
|
16
|
+
.option('--filter-services <glob-pattern>', 'Filter services to be generated by glob pattern. Eg: "/user/**,/post/**". See NPM `micromatch` package for more details.')
|
|
17
|
+
.option('--postfix-services <string>', 'Postfix to be added to the generated service name (eg: Service)')
|
|
18
|
+
.option('--service-name-base <endpoint[<index>] | tags>', 'Use OpenAPI Operation `endpoint[<index>]` path part (e.g.: "/0/1/2") or `tags` as the base name of the service.', 'endpoint[0]');
|
|
19
|
+
}
|
|
20
|
+
action(callback) {
|
|
21
|
+
return super.action(async (...actionArgs) => {
|
|
22
|
+
const { version: packageVersion } = await import('@openapi-qraft/plugin/package.json', {
|
|
23
|
+
assert: { type: 'json' },
|
|
24
|
+
}).then(({ default: packageJSON }) => packageJSON);
|
|
25
|
+
const inputs = actionArgs.filter((arg) => typeof arg === 'string');
|
|
26
|
+
const args = actionArgs.find((arg) => arg && typeof arg === 'object');
|
|
27
|
+
if (!args)
|
|
28
|
+
throw new Error('Arguments object not found');
|
|
29
|
+
if (args.version) {
|
|
30
|
+
console.info(`v${packageVersion}`);
|
|
31
|
+
process.exit(0);
|
|
32
|
+
}
|
|
33
|
+
console.info(`✨ ${c.bold(`OpenAPI Qraft ${packageVersion}`)}`);
|
|
34
|
+
const spinner = ora('Starting the Qraft ⛏︎').start();
|
|
35
|
+
await callback({
|
|
36
|
+
inputs,
|
|
37
|
+
args,
|
|
38
|
+
spinner,
|
|
39
|
+
services: await this.#getServices(inputs[0], args),
|
|
40
|
+
output: {
|
|
41
|
+
dir: normalizeOutputDirPath(args.outputDir),
|
|
42
|
+
clean: args.clean,
|
|
43
|
+
},
|
|
44
|
+
}, async function resolveGeneratorFiles(fileItems) {
|
|
45
|
+
try {
|
|
46
|
+
await writeGeneratorFiles({
|
|
47
|
+
fileItems,
|
|
48
|
+
spinner,
|
|
49
|
+
});
|
|
50
|
+
spinner.succeed(c.green('Qraft has been finished'));
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
spinner.fail(c.red('Error occurred during generation'));
|
|
54
|
+
if (error instanceof Error) {
|
|
55
|
+
console.error(c.red(error.message), c.red(error.stack ?? ''));
|
|
56
|
+
}
|
|
57
|
+
console.error(error);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async #getServices(input, args) {
|
|
64
|
+
const cwd = `${process.cwd()}/`;
|
|
65
|
+
const source = input && typeof input === 'string'
|
|
66
|
+
? new URL(input, pathToFileURL(cwd))
|
|
67
|
+
: process.stdin;
|
|
68
|
+
if (source === process.stdin && source.isTTY) {
|
|
69
|
+
console.error(c.red('Input file not found or stdin is empty. Please specify `--input` option or pipe OpenAPI Schema to stdin.'));
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
return await getDocumentServices({
|
|
73
|
+
output: {
|
|
74
|
+
postfixServices: args.postfixServices,
|
|
75
|
+
serviceNameBase: args.serviceNameBase,
|
|
76
|
+
},
|
|
77
|
+
servicesGlob: parseServicesFilterOption(args.filterServices),
|
|
78
|
+
source,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Normalize an output directory path by adding trailing slash
|
|
84
|
+
*/
|
|
85
|
+
function normalizeOutputDirPath(outputDir) {
|
|
86
|
+
return pathToFileURL(outputDir.endsWith(sep) ? outputDir : `${outputDir}${sep}`);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Parse services filter option to array
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* parseServicesFilterOption('/user/**,/post/**')
|
|
93
|
+
* ```
|
|
94
|
+
* @param endpointGlobs
|
|
95
|
+
*/
|
|
96
|
+
function parseServicesFilterOption(endpointGlobs) {
|
|
97
|
+
return endpointGlobs
|
|
98
|
+
? endpointGlobs
|
|
99
|
+
.split(',')
|
|
100
|
+
.filter((item) => Boolean(typeof item === 'string' && item.trim()))
|
|
101
|
+
: undefined;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=QraftCommand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QraftCommand.js","sourceRoot":"","sources":["../../src/lib/QraftCommand.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,aAAa,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,GAAY,MAAM,KAAK,CAAC;AAG/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAGxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,MAAM,OAAO,YAAa,SAAQ,OAAO;IACvC;QACE,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC;aAC5B,QAAQ,CACP,SAAS,EACT,iDAAiD,EACjD,IAAI,CACL;aACA,cAAc,CACb,yBAAyB,EACzB,yCAAyC,CAC1C;aACA,MAAM,CACL,cAAc,EACd,mDAAmD,CACpD;aACA,MAAM,CACL,kCAAkC,EAClC,0HAA0H,CAC3H;aACA,MAAM,CACL,6BAA6B,EAC7B,iEAAiE,CAClE;aACA,MAAM,CACL,gDAAgD,EAChD,iHAAiH,EACjH,aAAa,CACd,CAAC;IACN,CAAC;IAED,MAAM,CAAC,QAAoC;QACzC,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,UAAU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AAM,EAAE;gBACN,eAAe,EAAE,IAAI,CAAC,eAAe;gBACrC,eAAe,EAAE,IAAI,CAAC,eAAe;aACtC;YACD,YAAY,EAAE,yBAAyB,CAAC,IAAI,CAAC,cAAc,CAAC;YAC5D,MAAM;SACP,CAAC,CAAC;IACL,CAAC;CACF;AAED;;GAEG;AACH,SAAS,sBAAsB,CAAC,SAAiB;IAC/C,OAAO,aAAa,CAClB,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,GAAG,EAAE,CAC3D,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,yBAAyB,CAChC,aAAqB;IAErB,OAAO,aAAa;QAClB,CAAC,CAAC,aAAa;aACV,KAAK,CAAC,GAAG,CAAC;aACV,MAAM,CAAC,CAAC,IAAa,EAAkB,EAAE,CACxC,OAAO,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,CACjD;QACL,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QraftCommandPlugin.js","sourceRoot":"","sources":["../../src/lib/QraftCommandPlugin.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const fileHeader = "/* generated using @openapi-qraft/cli -- do no edit */\n/* istanbul ignore file */";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileHeader.js","sourceRoot":"","sources":["../../src/lib/fileHeader.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG;2BACC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type OpenAPISchemaType = {
|
|
2
|
+
paths: {
|
|
3
|
+
[path: string]: {
|
|
4
|
+
[method: string]: {
|
|
5
|
+
tags?: string[];
|
|
6
|
+
description?: string;
|
|
7
|
+
summary?: string;
|
|
8
|
+
operationId?: string;
|
|
9
|
+
parameters?: Record<string, any>;
|
|
10
|
+
deprecated?: boolean;
|
|
11
|
+
requestBody?: {
|
|
12
|
+
content: {
|
|
13
|
+
[contentType: string]: {
|
|
14
|
+
schema: any;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
responses: {
|
|
19
|
+
[statusCode in number | 'default']: {
|
|
20
|
+
description: string;
|
|
21
|
+
content: {
|
|
22
|
+
[contentType: string]: {
|
|
23
|
+
schema: any;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenAPISchemaType.js","sourceRoot":"","sources":["../../../src/lib/open-api/OpenAPISchemaType.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const BASIC_MEDIA_TYPES = [
|
|
2
|
+
'application/json-patch+json',
|
|
3
|
+
'application/json',
|
|
4
|
+
'application/x-www-form-urlencoded',
|
|
5
|
+
'text/json',
|
|
6
|
+
'text/plain',
|
|
7
|
+
'multipart/form-data',
|
|
8
|
+
'multipart/mixed',
|
|
9
|
+
'multipart/related',
|
|
10
|
+
'multipart/batch',
|
|
11
|
+
];
|
|
12
|
+
export const getContentMediaType = (content) => {
|
|
13
|
+
const basicMediaTypeWithSchema = Object.keys(content)
|
|
14
|
+
.filter((mediaType) => {
|
|
15
|
+
const cleanMediaType = mediaType.split(';')[0].trim();
|
|
16
|
+
return BASIC_MEDIA_TYPES.includes(cleanMediaType);
|
|
17
|
+
})
|
|
18
|
+
.find((mediaType) => content[mediaType]?.schema);
|
|
19
|
+
if (basicMediaTypeWithSchema)
|
|
20
|
+
return basicMediaTypeWithSchema;
|
|
21
|
+
return Object.keys(content).find((mediaType) => content[mediaType]?.schema);
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=getContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getContent.js","sourceRoot":"","sources":["../../../src/lib/open-api/getContent.ts"],"names":[],"mappings":"AAAA,MAAM,iBAAiB,GAAG;IACxB,6BAA6B;IAC7B,kBAAkB;IAClB,mCAAmC;IACnC,WAAW;IACX,YAAY;IACZ,qBAAqB;IACrB,iBAAiB;IACjB,mBAAmB;IACnB,iBAAiB;CAClB,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,OAEnC,EAAE,EAAE;IACH,MAAM,wBAAwB,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;SAClD,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE;QACpB,MAAM,cAAc,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACtD,OAAO,iBAAiB,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;IACpD,CAAC,CAAC;SACD,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,CAAC;IAEnD,IAAI,wBAAwB;QAAE,OAAO,wBAAwB,CAAC;IAE9D,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,CAAC;AAC9E,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
4
|
+
import type { Readable } from 'node:stream';
|
|
5
|
+
import type { URL } from 'node:url';
|
|
6
|
+
import type { OpenAPI3 } from 'openapi-typescript';
|
|
7
|
+
import { ServiceOutputOptions } from './getServices.js';
|
|
8
|
+
export declare const getDocumentServices: ({ source, servicesGlob, output, }: {
|
|
9
|
+
source: string | URL | OpenAPI3 | Readable | Buffer;
|
|
10
|
+
servicesGlob: string[] | undefined;
|
|
11
|
+
output: ServiceOutputOptions;
|
|
12
|
+
}) => Promise<import("./getServices.js").Service[]>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { getServices } from './getServices.js';
|
|
2
|
+
import { readSchema } from './readSchema.js';
|
|
3
|
+
export const getDocumentServices = async ({ source, servicesGlob, output, }) => {
|
|
4
|
+
const schema = await readSchema(source);
|
|
5
|
+
return getServices(schema, output, servicesGlob);
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=getDocumentServices.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDocumentServices.js","sourceRoot":"","sources":["../../../src/lib/open-api/getDocumentServices.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAwB,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAAE,EACxC,MAAM,EACN,YAAY,EACZ,MAAM,GAKP,EAAE,EAAE;IACH,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,CAAC;IACxC,OAAO,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;AACnD,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert the input value to a correct operation (method) classname.
|
|
3
|
+
* This will use the operation ID - if available - and otherwise fallback
|
|
4
|
+
* on a generated name from the URL
|
|
5
|
+
*/
|
|
6
|
+
export declare const getOperationName: (url: string, method: string, operationId?: string) => string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import camelCase from 'camelcase';
|
|
2
|
+
/**
|
|
3
|
+
* Convert the input value to a correct operation (method) classname.
|
|
4
|
+
* This will use the operation ID - if available - and otherwise fallback
|
|
5
|
+
* on a generated name from the URL
|
|
6
|
+
*/
|
|
7
|
+
export const getOperationName = (url, method, operationId) => {
|
|
8
|
+
if (operationId) {
|
|
9
|
+
return camelCase(operationId
|
|
10
|
+
.replace(/^[^a-zA-Z]+/g, '')
|
|
11
|
+
.replace(/[^\w-]+/g, '-')
|
|
12
|
+
.trim());
|
|
13
|
+
}
|
|
14
|
+
const urlWithoutPlaceholders = url
|
|
15
|
+
.replace(/[^/]*?{api-version}.*?\//g, '')
|
|
16
|
+
.replace(/{(.*?)}/g, '')
|
|
17
|
+
.replace(/\//g, '-');
|
|
18
|
+
return camelCase(`${method}-${urlWithoutPlaceholders}`);
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=getOperationName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOperationName.js","sourceRoot":"","sources":["../../../src/lib/open-api/getOperationName.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,GAAW,EACX,MAAc,EACd,WAAoB,EACZ,EAAE;IACV,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,SAAS,CACd,WAAW;aACR,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC;aAC3B,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC;aACxB,IAAI,EAAE,CACV,CAAC;IACJ,CAAC;IAED,MAAM,sBAAsB,GAAG,GAAG;SAC/B,OAAO,CAAC,2BAA2B,EAAE,EAAE,CAAC;SACxC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAEvB,OAAO,SAAS,CAAC,GAAG,MAAM,IAAI,sBAAsB,EAAE,CAAC,CAAC;AAC1D,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import camelCase from 'camelcase';
|
|
2
|
+
/**
|
|
3
|
+
* Convert the input value to the correct service name. This converts
|
|
4
|
+
* the input string to PascalCase.
|
|
5
|
+
*/
|
|
6
|
+
export const getServiceName = (value) => {
|
|
7
|
+
const clean = value
|
|
8
|
+
.replace(/^[^a-zA-Z]+/g, '')
|
|
9
|
+
.replace(/[^\w-]+/g, '-')
|
|
10
|
+
.trim();
|
|
11
|
+
return camelCase(clean, { pascalCase: true });
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=getServiceName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getServiceName.js","sourceRoot":"","sources":["../../../src/lib/open-api/getServiceName.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAU,EAAE;IACtD,MAAM,KAAK,GAAG,KAAK;SAChB,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC;SAC3B,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC;SACxB,IAAI,EAAE,CAAC;IAEV,OAAO,SAAS,CAAC,KAAK,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;AAChD,CAAC,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type ServiceBaseNameByEndpointOption = `endpoint[${number}]`;
|
|
2
|
+
export declare const getServiceNamesByOperationEndpoint: (endpoint: string, format: ServiceBaseNameByEndpointOption, fallbackBaseName: string) => [string];
|
|
3
|
+
export declare const getServiceBaseNameByOperationEndpoint: (endpoint: string, format: ServiceBaseNameByEndpointOption) => string | undefined;
|
|
4
|
+
export declare const getEndpointPartIndex: (endpointOption: ServiceBaseNameByEndpointOption) => number;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getServiceName } from './getServiceName.js';
|
|
2
|
+
export const getServiceNamesByOperationEndpoint = (endpoint, format, fallbackBaseName) => {
|
|
3
|
+
return [
|
|
4
|
+
getServiceName(getServiceBaseNameByOperationEndpoint(endpoint, format) ??
|
|
5
|
+
fallbackBaseName),
|
|
6
|
+
];
|
|
7
|
+
};
|
|
8
|
+
export const getServiceBaseNameByOperationEndpoint = (endpoint, format) => {
|
|
9
|
+
const endpointParts = endpoint.split('/').filter(Boolean);
|
|
10
|
+
for (let endpointIndex = getEndpointPartIndex(format); endpointIndex >= 0; endpointIndex--) {
|
|
11
|
+
const endpointPart = endpointParts[endpointIndex];
|
|
12
|
+
if (endpointPart)
|
|
13
|
+
return endpointPart;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
export const getEndpointPartIndex = (endpointOption) => {
|
|
17
|
+
const startBracketString = 'endpoint[';
|
|
18
|
+
const endpointIndexStart = endpointOption.indexOf(startBracketString);
|
|
19
|
+
if (endpointIndexStart === -1)
|
|
20
|
+
throw new Error(`Expected endpoint to start with '${startBracketString}' but got: '${endpointOption}'`);
|
|
21
|
+
const endBracketString = ']';
|
|
22
|
+
const endpointIndexEnd = endpointOption.indexOf(endBracketString, endpointIndexStart);
|
|
23
|
+
if (endpointIndexEnd === -1)
|
|
24
|
+
throw new Error(`Expected endpoint to end with '${endBracketString}' but got: '${endpointOption}'`);
|
|
25
|
+
const endpointIndex = parseInt(endpointOption.slice(endpointIndexStart + startBracketString.length, endpointIndexEnd));
|
|
26
|
+
if (!isFinite(endpointIndex))
|
|
27
|
+
throw new Error(`Expected endpoint index to be a number but got: '${endpointOption}'`);
|
|
28
|
+
return endpointIndex;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=getServiceNamesByOperationEndpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getServiceNamesByOperationEndpoint.js","sourceRoot":"","sources":["../../../src/lib/open-api/getServiceNamesByOperationEndpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAIrD,MAAM,CAAC,MAAM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gBAAgB,CACjB,CACF,CAAC;IAEF,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,oDAAoD,cAAc,GAAG,CACtE,CAAC;IAEJ,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getServiceNamesByOperationTags: (tags: (string | number | null | undefined)[] | undefined, fallbackBaseName: string) => string[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getServiceName } from './getServiceName.js';
|
|
2
|
+
export const getServiceNamesByOperationTags = (tags, fallbackBaseName) => {
|
|
3
|
+
const filteredTags = tags
|
|
4
|
+
?.filter((tag) => typeof tag === 'string')
|
|
5
|
+
.map(getServiceName)
|
|
6
|
+
.filter(Boolean);
|
|
7
|
+
return filteredTags?.length
|
|
8
|
+
? filteredTags
|
|
9
|
+
: [getServiceName(fallbackBaseName)];
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=getServiceNamesByOperationTags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getServiceNamesByOperationTags.js","sourceRoot":"","sources":["../../../src/lib/open-api/getServiceNamesByOperationTags.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAC5C,IAAwD,EACxD,gBAAwB,EACd,EAAE;IACZ,MAAM,YAAY,GAAG,IAAI;QACvB,EAAE,MAAM,CAAC,CAAC,GAAG,EAAiB,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC;SACxD,GAAG,CAAC,cAAc,CAAC;SACnB,MAAM,CAAC,OAAO,CAAC,CAAC;IAEnB,OAAO,YAAY,EAAE,MAAM;QACzB,CAAC,CAAC,YAAY;QACd,CAAC,CAAC,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC,CAAC;AACzC,CAAC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ServiceBaseNameByEndpointOption } from './getServiceNamesByOperationEndpoint.js';
|
|
2
|
+
import type { OpenAPISchemaType } from './OpenAPISchemaType.js';
|
|
3
|
+
export type ServiceBaseName = ServiceBaseNameByEndpointOption | 'tags';
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated move to separate file
|
|
6
|
+
*/
|
|
7
|
+
export type Service = {
|
|
8
|
+
name: string;
|
|
9
|
+
variableName: string;
|
|
10
|
+
typeName: string;
|
|
11
|
+
fileBaseName: string;
|
|
12
|
+
operations: ServiceOperation[];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated move to separate file
|
|
16
|
+
*/
|
|
17
|
+
export type ServiceOperation = {
|
|
18
|
+
method: 'get' | 'put' | 'post' | 'patch' | 'delete' | 'options' | 'head' | 'trace';
|
|
19
|
+
path: string;
|
|
20
|
+
name: string;
|
|
21
|
+
description: string | undefined;
|
|
22
|
+
summary: string | undefined;
|
|
23
|
+
deprecated: boolean | undefined;
|
|
24
|
+
mediaType: string | undefined;
|
|
25
|
+
errors: Record<string, string | undefined>;
|
|
26
|
+
success: Record<string, string | undefined>;
|
|
27
|
+
parameters: Record<string, any> | undefined;
|
|
28
|
+
};
|
|
29
|
+
export interface ServiceOutputOptions {
|
|
30
|
+
postfixServices?: string;
|
|
31
|
+
serviceNameBase?: ServiceBaseName;
|
|
32
|
+
}
|
|
33
|
+
export declare const getServices: (openApiJson: OpenAPISchemaType, { postfixServices, serviceNameBase, }?: ServiceOutputOptions, servicesGlob?: string[]) => Service[];
|
|
34
|
+
/**
|
|
35
|
+
* Create a function to match service paths
|
|
36
|
+
* @param servicesGlob
|
|
37
|
+
*/
|
|
38
|
+
export declare const createServicePathMatch: (servicesGlob: string[]) => (path: string) => boolean;
|
|
39
|
+
export declare const supportedMethod: (method: unknown) => method is "get" | "put" | "post" | "patch" | "delete" | "options" | "head" | "trace";
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import camelCase from 'camelcase';
|
|
2
|
+
import * as console from 'console';
|
|
3
|
+
import micromatch from 'micromatch';
|
|
4
|
+
import { getContentMediaType } from './getContent.js';
|
|
5
|
+
import { getOperationName } from './getOperationName.js';
|
|
6
|
+
import { getServiceNamesByOperationEndpoint, } from './getServiceNamesByOperationEndpoint.js';
|
|
7
|
+
import { getServiceNamesByOperationTags } from './getServiceNamesByOperationTags.js';
|
|
8
|
+
export const getServices = (openApiJson, { postfixServices = 'Service', serviceNameBase = 'endpoint[0]', } = {}, servicesGlob = ['**']) => {
|
|
9
|
+
const paths = openApiJson.paths;
|
|
10
|
+
const services = new Map();
|
|
11
|
+
const isPathMatch = createServicePathMatch(servicesGlob);
|
|
12
|
+
for (const path in paths) {
|
|
13
|
+
if (!Object.prototype.hasOwnProperty.call(paths, path))
|
|
14
|
+
continue;
|
|
15
|
+
for (const method in paths[path]) {
|
|
16
|
+
if (!Object.prototype.hasOwnProperty.call(paths[path], method))
|
|
17
|
+
continue;
|
|
18
|
+
if (!isPathMatch(path))
|
|
19
|
+
continue;
|
|
20
|
+
if (!supportedMethod(method)) {
|
|
21
|
+
console.warn(`The path "${path}" HTTP method "${method}" is not supported`);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const methodOperation = paths[path][method];
|
|
25
|
+
const { success, errors } = Object.entries(methodOperation.responses).reduce((acc, [statusCode, response]) => {
|
|
26
|
+
if (!response.content || typeof response.content !== 'object') {
|
|
27
|
+
return acc;
|
|
28
|
+
}
|
|
29
|
+
const statusType = statusCode !== 'default' && // See "default" response https://swagger.io/docs/specification/describing-responses/#default
|
|
30
|
+
Number(statusCode) < 400
|
|
31
|
+
? 'success'
|
|
32
|
+
: 'errors';
|
|
33
|
+
return {
|
|
34
|
+
...acc,
|
|
35
|
+
[statusType]: {
|
|
36
|
+
...acc[statusType],
|
|
37
|
+
[statusCode]: getContentMediaType(response.content),
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}, {});
|
|
41
|
+
const serviceFallbackBaseName = 'Default';
|
|
42
|
+
const serviceNames = serviceNameBase === 'tags'
|
|
43
|
+
? getServiceNamesByOperationTags(paths[path][method]?.tags, serviceFallbackBaseName)
|
|
44
|
+
: getServiceNamesByOperationEndpoint(path, serviceNameBase, serviceFallbackBaseName);
|
|
45
|
+
for (const name of serviceNames) {
|
|
46
|
+
if (!services.has(name)) {
|
|
47
|
+
services.set(name, {
|
|
48
|
+
name: camelCase(name),
|
|
49
|
+
variableName: `${camelCase(name, {
|
|
50
|
+
preserveConsecutiveUppercase: false,
|
|
51
|
+
})}${postfixServices}`,
|
|
52
|
+
typeName: `${name}${postfixServices}`,
|
|
53
|
+
fileBaseName: `${name}${postfixServices}`,
|
|
54
|
+
operations: [],
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
for (const name of serviceNames) {
|
|
59
|
+
services.get(name).operations.push({
|
|
60
|
+
method,
|
|
61
|
+
path,
|
|
62
|
+
errors,
|
|
63
|
+
name: getOperationName(path, method, methodOperation.operationId),
|
|
64
|
+
description: methodOperation.description,
|
|
65
|
+
summary: methodOperation.summary,
|
|
66
|
+
deprecated: methodOperation.deprecated,
|
|
67
|
+
parameters: Array.isArray(methodOperation.parameters) &&
|
|
68
|
+
!methodOperation.parameters.length
|
|
69
|
+
? undefined
|
|
70
|
+
: methodOperation.parameters,
|
|
71
|
+
mediaType: methodOperation.requestBody?.content
|
|
72
|
+
? getContentMediaType(methodOperation.requestBody.content)
|
|
73
|
+
: undefined,
|
|
74
|
+
success: success,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return Array.from(services.values());
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Create a function to match service paths
|
|
83
|
+
* @param servicesGlob
|
|
84
|
+
*/
|
|
85
|
+
export const createServicePathMatch = (servicesGlob) => {
|
|
86
|
+
const servicePathGlobs = servicesGlob.reduce((acc, glob) => {
|
|
87
|
+
glob.startsWith('!')
|
|
88
|
+
? acc.ignore.push(glob.slice(1))
|
|
89
|
+
: acc.match.push(glob);
|
|
90
|
+
return acc;
|
|
91
|
+
}, {
|
|
92
|
+
match: [],
|
|
93
|
+
ignore: [],
|
|
94
|
+
});
|
|
95
|
+
return function isServicePatchMatch(path) {
|
|
96
|
+
return micromatch.isMatch(path, servicePathGlobs.match, {
|
|
97
|
+
ignore: servicePathGlobs.ignore,
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
export const supportedMethod = (method) => supportedHTTPMethods.includes(method);
|
|
102
|
+
const supportedHTTPMethods = Object.values({
|
|
103
|
+
get: 'get',
|
|
104
|
+
put: 'put',
|
|
105
|
+
post: 'post',
|
|
106
|
+
patch: 'patch',
|
|
107
|
+
delete: 'delete',
|
|
108
|
+
options: 'options',
|
|
109
|
+
head: 'head',
|
|
110
|
+
trace: 'trace',
|
|
111
|
+
});
|
|
112
|
+
//# sourceMappingURL=getServices.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getServices.js","sourceRoot":"","sources":["../../../src/lib/open-api/getServices.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EACL,kCAAkC,GAEnC,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AA6CrF,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,WAA8B,EAC9B,EACE,eAAe,GAAG,SAAS,EAC3B,eAAe,GAAG,aAAa,MACP,EAAE,EAC5B,YAAY,GAAG,CAAC,IAAI,CAAC,EACrB,EAAE;IAC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AAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,MAAe,EACkC,EAAE,CACnD,oBAAoB,CAAC,QAAQ,CAC3B,MAA+C,CAChD,CAAC;AAEJ,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC;IACzC,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;CACwC,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
4
|
+
import type { Readable } from 'node:stream';
|
|
5
|
+
import type { OpenAPI3 } from 'openapi-typescript';
|
|
6
|
+
import { OpenAPISchemaType } from './OpenAPISchemaType.js';
|
|
7
|
+
export declare const readSchema: (source: string | URL | OpenAPI3 | Readable | Buffer) => Promise<OpenAPISchemaType>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createConfig } from '@redocly/openapi-core';
|
|
2
|
+
import { validateAndBundle } from 'openapi-typescript/dist/lib/redoc.js';
|
|
3
|
+
export const readSchema = async (source) => {
|
|
4
|
+
const redoc = await createConfig({
|
|
5
|
+
rules: {
|
|
6
|
+
'operation-operationId-unique': { severity: 'error' }, // throw error on duplicate operationIDs
|
|
7
|
+
},
|
|
8
|
+
}, { extends: ['minimal'] });
|
|
9
|
+
const parsed = await validateAndBundle(source, {
|
|
10
|
+
redoc,
|
|
11
|
+
silent: false,
|
|
12
|
+
});
|
|
13
|
+
return parsed;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=readSchema.js.map
|