@openapi-qraft/cli 1.7.0 → 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 +8 -0
- package/dist/bin.d.ts +7 -1
- package/dist/bin.js +54 -58
- package/dist/bin.js.map +1 -1
- package/package.json +14 -12
- package/src/bin.ts +71 -0
- package/dist/lib/fileHeader.d.ts +0 -1
- package/dist/lib/fileHeader.js +0 -5
- package/dist/lib/fileHeader.js.map +0 -1
- package/dist/lib/open-api/OpenAPISchemaType.d.ts +0 -31
- package/dist/lib/open-api/OpenAPISchemaType.js +0 -2
- package/dist/lib/open-api/OpenAPISchemaType.js.map +0 -1
- package/dist/lib/open-api/getContent.d.ts +0 -5
- package/dist/lib/open-api/getContent.js +0 -23
- package/dist/lib/open-api/getContent.js.map +0 -1
- package/dist/lib/open-api/getOperationName.d.ts +0 -6
- package/dist/lib/open-api/getOperationName.js +0 -20
- package/dist/lib/open-api/getOperationName.js.map +0 -1
- package/dist/lib/open-api/getServiceName.d.ts +0 -5
- package/dist/lib/open-api/getServiceName.js +0 -13
- package/dist/lib/open-api/getServiceName.js.map +0 -1
- package/dist/lib/open-api/getServiceNamesByOperationEndpoint.d.ts +0 -4
- package/dist/lib/open-api/getServiceNamesByOperationEndpoint.js +0 -30
- package/dist/lib/open-api/getServiceNamesByOperationEndpoint.js.map +0 -1
- package/dist/lib/open-api/getServiceNamesByOperationTags.d.ts +0 -1
- package/dist/lib/open-api/getServiceNamesByOperationTags.js +0 -11
- package/dist/lib/open-api/getServiceNamesByOperationTags.js.map +0 -1
- package/dist/lib/open-api/getServices.d.ts +0 -32
- package/dist/lib/open-api/getServices.js +0 -112
- package/dist/lib/open-api/getServices.js.map +0 -1
- package/dist/lib/open-api/readSchema.d.ts +0 -7
- package/dist/lib/open-api/readSchema.js +0 -15
- package/dist/lib/open-api/readSchema.js.map +0 -1
- package/dist/lib/ts-factory/astToString.d.ts +0 -8
- package/dist/lib/ts-factory/astToString.js +0 -14
- package/dist/lib/ts-factory/astToString.js.map +0 -1
- package/dist/lib/ts-factory/getClientFactory.d.ts +0 -7
- package/dist/lib/ts-factory/getClientFactory.js +0 -82
- package/dist/lib/ts-factory/getClientFactory.js.map +0 -1
- package/dist/lib/ts-factory/getIndexFactory.d.ts +0 -5
- package/dist/lib/ts-factory/getIndexFactory.js +0 -17
- package/dist/lib/ts-factory/getIndexFactory.js.map +0 -1
- package/dist/lib/ts-factory/getServiceFactory.d.ts +0 -10
- package/dist/lib/ts-factory/getServiceFactory.js +0 -120
- package/dist/lib/ts-factory/getServiceFactory.js.map +0 -1
- package/dist/lib/ts-factory/getServiceIndexFactory.d.ts +0 -7
- package/dist/lib/ts-factory/getServiceIndexFactory.js +0 -26
- package/dist/lib/ts-factory/getServiceIndexFactory.js.map +0 -1
- package/dist/writeOpenAPIServices.d.ts +0 -23
- package/dist/writeOpenAPIServices.js +0 -97
- package/dist/writeOpenAPIServices.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @openapi-qraft/cli
|
|
2
2
|
|
|
3
|
+
## 1.8.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 878c002: Replaced string-based path handling with URL objects to ensure path normalization and enhance security.
|
|
8
|
+
- Updated dependencies [27d501a]
|
|
9
|
+
- @openapi-qraft/tanstack-query-react-plugin@1.8.0
|
|
10
|
+
|
|
3
11
|
## 1.7.0
|
|
4
12
|
|
|
5
13
|
## 1.6.0
|
package/dist/bin.d.ts
CHANGED
package/dist/bin.js
CHANGED
|
@@ -1,63 +1,59 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
.option('-rm, --clean', 'Clean output directory before generating services')
|
|
14
|
-
.option('--filter-services <glob-pattern>', 'Filter services to be generated by glob pattern. Eg: "/user/**,/post/**". See NPM `micromatch` package for more details.')
|
|
15
|
-
.option('--operation-generics-import-path <path>', 'Path to operation generics file', '@openapi-qraft/react')
|
|
16
|
-
.option('--file-header <string>', 'Header to be added to the generated file (eg: /* eslint-disable */)')
|
|
17
|
-
.option('--postfix-services <string>', 'Postfix to be added to the generated service name (eg: Service)')
|
|
18
|
-
.option('--explicit-import-extensions', 'All import statements will include explicit `.js` extensions. Ideal for projects using ECMAScript modules.')
|
|
19
|
-
.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]')
|
|
20
|
-
.action(async (input, args) => {
|
|
21
|
-
const { version: packageVersion, name: packageName } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
22
|
-
if (args.version) {
|
|
23
|
-
console.info(`v${packageVersion}`);
|
|
24
|
-
process.exit(0);
|
|
2
|
+
import { QraftCommand } from '@openapi-qraft/plugin/lib/QraftCommand';
|
|
3
|
+
import process from 'node:process';
|
|
4
|
+
const command = new QraftCommand();
|
|
5
|
+
const { argv, plugins } = extractArgvPluginOptions(process.argv); // todo::move parsing to the QraftCommand `parse` method
|
|
6
|
+
if (plugins) {
|
|
7
|
+
if (plugins?.includes('tanstack-query-react')) {
|
|
8
|
+
import('@openapi-qraft/tanstack-query-react-plugin').then(({ default: plugin }) => {
|
|
9
|
+
plugin.setupCommand(command);
|
|
10
|
+
addCommandUsageWithPlugins(command, plugins);
|
|
11
|
+
command.parse(argv);
|
|
12
|
+
});
|
|
25
13
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
? new URL(input, new URL(`file://${process.cwd()}/`))
|
|
29
|
-
: process.stdin;
|
|
30
|
-
if (source === process.stdin && source.isTTY) {
|
|
31
|
-
console.error(c.red('Input file not found or stdin is empty. Please specify `--input` option or pipe OpenAPI Schema to stdin.'));
|
|
32
|
-
process.exit(1);
|
|
14
|
+
else {
|
|
15
|
+
throw new Error(`Unknown plugin: '${plugins.join(', ')}'`);
|
|
33
16
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
openapiTypesImportPath: args.openapiTypesImportPath,
|
|
44
|
-
},
|
|
45
|
-
servicesGlob,
|
|
46
|
-
output: {
|
|
47
|
-
dir: args.outputDir,
|
|
48
|
-
clean: args.clean,
|
|
49
|
-
fileHeader: args.fileHeader ?? fileHeader,
|
|
50
|
-
postfixServices: args.postfixServices,
|
|
51
|
-
explicitImportExtensions: args.explicitImportExtensions,
|
|
52
|
-
servicesDirName: 'services',
|
|
53
|
-
serviceNameBase: args.serviceNameBase,
|
|
54
|
-
},
|
|
55
|
-
}).catch((error) => {
|
|
56
|
-
if (error instanceof Error)
|
|
57
|
-
console.error(c.red(error.message), c.red(error.stack ?? ''));
|
|
58
|
-
console.error(error);
|
|
59
|
-
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
// default - setup tanstack-query-react plugin
|
|
20
|
+
import('@openapi-qraft/tanstack-query-react-plugin').then(({ default: plugin }) => {
|
|
21
|
+
plugin.setupCommand(command);
|
|
22
|
+
command.option('--plugin <name>', 'Client generator plugin name', () => {
|
|
23
|
+
throw new Error('Plugin option must be handled before parsing the command and should not be passed to the commander');
|
|
24
|
+
});
|
|
25
|
+
command.parse(argv);
|
|
60
26
|
});
|
|
61
|
-
}
|
|
62
|
-
|
|
27
|
+
}
|
|
28
|
+
function addCommandUsageWithPlugins(command, plugins) {
|
|
29
|
+
const pluginUsage = plugins.map((plugin) => `--plugin ${plugin}`).join(' ');
|
|
30
|
+
command.usage(`${pluginUsage} [input] [options]`);
|
|
31
|
+
}
|
|
32
|
+
export function extractArgvPluginOptions(argv) {
|
|
33
|
+
const pluginIndex = argv.indexOf('--plugin');
|
|
34
|
+
if (pluginIndex === -1)
|
|
35
|
+
return { argv };
|
|
36
|
+
const filteredArgv = argv.slice(0, pluginIndex);
|
|
37
|
+
const plugins = [];
|
|
38
|
+
for (let i = pluginIndex; i < argv.length; i++) {
|
|
39
|
+
if (argv[i] === '--plugin') {
|
|
40
|
+
const pluginName = argv.at(i + 1);
|
|
41
|
+
if (!pluginName)
|
|
42
|
+
throw new Error(`Missing plugin name after '--plugin'`);
|
|
43
|
+
if (pluginName?.startsWith('--'))
|
|
44
|
+
throw new Error(`Invalid plugin name: '${pluginName}'`);
|
|
45
|
+
plugins.push(pluginName);
|
|
46
|
+
i++; // Skip next item
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
filteredArgv.push(argv[i]);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (plugins.length > 1)
|
|
53
|
+
throw new Error(`Only one plugin can be specified, got: '${plugins.join(', ')}'`);
|
|
54
|
+
return {
|
|
55
|
+
argv: filteredArgv,
|
|
56
|
+
plugins,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
63
59
|
//# sourceMappingURL=bin.js.map
|
package/dist/bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AAEtE,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,MAAM,OAAO,GAAG,IAAI,YAAY,EAAE,CAAC;AAEnC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,wBAAwB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,wDAAwD;AAE1H,IAAI,OAAO,EAAE,CAAC;IACZ,IAAI,OAAO,EAAE,QAAQ,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K,CAAC,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAExC,MAAM,YAAY,GAAa,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAa,EAAE,CAAC;IAE7B,KAAK,IAAI,CAAC,GAAG,WAAW,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC/C,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,UAAU,EAAE,CAAC;YAC3B,MAAM,UAAU,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAClC,IAAI,CAAC,UAAU;gBAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;YACzE,IAAI,UAAU,EAAE,UAAU,CAAC,IAAI,CAAC;gBAC9B,MAAM,IAAI,KAAK,CAAC,yBAAyB,UAAU,GAAG,CAAC,CAAC;YAC1D,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACzB,CAAC,EAAE,CAAC,CAAC,iBAAiB;QACxB,CAAC;aAAM,CAAC;YACN,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,2CAA2C,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CACjE,CAAC;IAEJ,OAAO;QACL,IAAI,EAAE,YAAY;QAClB,OAAO;KACR,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,36 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openapi-qraft/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "CLI for generating typed Tanstack Query React Hooks and services from OpenAPI Schemas, improving type safety in React apps",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rimraf dist/ && tsc --project tsconfig.build.json",
|
|
7
7
|
"dev": "yarn build --watch",
|
|
8
8
|
"test": "vitest run",
|
|
9
|
-
"typecheck": "tsc --noEmit"
|
|
9
|
+
"typecheck": "tsc --noEmit",
|
|
10
|
+
"lint": "eslint"
|
|
10
11
|
},
|
|
11
12
|
"type": "module",
|
|
12
13
|
"bin": {
|
|
13
14
|
"openapi-qraft": "./bin.mjs"
|
|
14
15
|
},
|
|
15
16
|
"dependencies": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"commander": "^11.1.0",
|
|
19
|
-
"micromatch": "^4.0.5",
|
|
20
|
-
"openapi-typescript": "7.0.0-next.7",
|
|
21
|
-
"ora": "^8.0.1",
|
|
22
|
-
"typescript": "^5.3.3",
|
|
23
|
-
"yaml": "^2.3.4"
|
|
17
|
+
"@openapi-qraft/tanstack-query-react-plugin": "~1.8.0",
|
|
18
|
+
"commander": "^11.1.0"
|
|
24
19
|
},
|
|
25
20
|
"devDependencies": {
|
|
26
|
-
"@
|
|
21
|
+
"@openapi-qraft/eslint-config": "~1.0.0",
|
|
27
22
|
"@types/node": "^18.19.4",
|
|
23
|
+
"eslint": "^9.0.0",
|
|
24
|
+
"globals": "^15.0.0",
|
|
28
25
|
"rimraf": "^5.0.5",
|
|
26
|
+
"typescript": "^5.3.3",
|
|
29
27
|
"vitest": "^1.4.0"
|
|
30
28
|
},
|
|
31
29
|
"files": [
|
|
32
30
|
"dist",
|
|
33
|
-
"
|
|
31
|
+
"src",
|
|
32
|
+
"!dist/**/*.test.*",
|
|
33
|
+
"!dist/**/*.spec.*",
|
|
34
|
+
"!src/**/*.test.*",
|
|
35
|
+
"!src/**/*.spec.*"
|
|
34
36
|
],
|
|
35
37
|
"exports": {
|
|
36
38
|
"./package.json": "./package.json",
|
package/src/bin.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { QraftCommand } from '@openapi-qraft/plugin/lib/QraftCommand';
|
|
3
|
+
|
|
4
|
+
import process from 'node:process';
|
|
5
|
+
|
|
6
|
+
const command = new QraftCommand();
|
|
7
|
+
|
|
8
|
+
const { argv, plugins } = extractArgvPluginOptions(process.argv); // todo::move parsing to the QraftCommand `parse` method
|
|
9
|
+
|
|
10
|
+
if (plugins) {
|
|
11
|
+
if (plugins?.includes('tanstack-query-react')) {
|
|
12
|
+
import('@openapi-qraft/tanstack-query-react-plugin').then(
|
|
13
|
+
({ default: plugin }) => {
|
|
14
|
+
plugin.setupCommand(command);
|
|
15
|
+
addCommandUsageWithPlugins(command, plugins);
|
|
16
|
+
command.parse(argv);
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
} else {
|
|
20
|
+
throw new Error(`Unknown plugin: '${plugins.join(', ')}'`);
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
// default - setup tanstack-query-react plugin
|
|
24
|
+
import('@openapi-qraft/tanstack-query-react-plugin').then(
|
|
25
|
+
({ default: plugin }) => {
|
|
26
|
+
plugin.setupCommand(command);
|
|
27
|
+
command.option('--plugin <name>', 'Client generator plugin name', () => {
|
|
28
|
+
throw new Error(
|
|
29
|
+
'Plugin option must be handled before parsing the command and should not be passed to the commander'
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
command.parse(argv);
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function addCommandUsageWithPlugins(command: QraftCommand, plugins: string[]) {
|
|
38
|
+
const pluginUsage = plugins.map((plugin) => `--plugin ${plugin}`).join(' ');
|
|
39
|
+
command.usage(`${pluginUsage} [input] [options]`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function extractArgvPluginOptions(argv: string[]) {
|
|
43
|
+
const pluginIndex = argv.indexOf('--plugin');
|
|
44
|
+
if (pluginIndex === -1) return { argv };
|
|
45
|
+
|
|
46
|
+
const filteredArgv: string[] = argv.slice(0, pluginIndex);
|
|
47
|
+
const plugins: string[] = [];
|
|
48
|
+
|
|
49
|
+
for (let i = pluginIndex; i < argv.length; i++) {
|
|
50
|
+
if (argv[i] === '--plugin') {
|
|
51
|
+
const pluginName = argv.at(i + 1);
|
|
52
|
+
if (!pluginName) throw new Error(`Missing plugin name after '--plugin'`);
|
|
53
|
+
if (pluginName?.startsWith('--'))
|
|
54
|
+
throw new Error(`Invalid plugin name: '${pluginName}'`);
|
|
55
|
+
plugins.push(pluginName);
|
|
56
|
+
i++; // Skip next item
|
|
57
|
+
} else {
|
|
58
|
+
filteredArgv.push(argv[i]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (plugins.length > 1)
|
|
63
|
+
throw new Error(
|
|
64
|
+
`Only one plugin can be specified, got: '${plugins.join(', ')}'`
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
argv: filteredArgv,
|
|
69
|
+
plugins,
|
|
70
|
+
};
|
|
71
|
+
}
|
package/dist/lib/fileHeader.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const fileHeader = "/* generated using @openapi-qraft/cli -- do no edit */\n/* istanbul ignore file */\n/* tslint:disable */\n/* eslint-disable */";
|
package/dist/lib/fileHeader.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fileHeader.js","sourceRoot":"","sources":["../../src/lib/fileHeader.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG;;;qBAGL,CAAC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAPISchemaType.js","sourceRoot":"","sources":["../../../src/lib/open-api/OpenAPISchemaType.ts"],"names":[],"mappings":""}
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,6 +0,0 @@
|
|
|
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;
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,WAAW,EAAE,GAAG,CAAC;aACzB,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"}
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,4 +0,0 @@
|
|
|
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;
|
|
@@ -1,30 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,kCAAkC,GAAG,CAChD,QAAgB,EAChB,MAAuC,EACvC,gBAAwB,EACd,EAAE;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;QAC1B,MAAM,IAAI,KAAK,CACb,oDAAoD,cAAc,GAAG,CACtE,CAAC;IAEJ,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const getServiceNamesByOperationTags: (tags: (string | number | null | undefined)[] | undefined, fallbackBaseName: string) => string[];
|
|
@@ -1,11 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { ServiceBaseNameByEndpointOption } from './getServiceNamesByOperationEndpoint.js';
|
|
2
|
-
import type { OpenAPISchemaType } from './OpenAPISchemaType.js';
|
|
3
|
-
export type ServiceBaseName = ServiceBaseNameByEndpointOption | 'tags';
|
|
4
|
-
export type Service = {
|
|
5
|
-
name: string;
|
|
6
|
-
variableName: string;
|
|
7
|
-
typeName: string;
|
|
8
|
-
fileBaseName: string;
|
|
9
|
-
operations: ServiceOperation[];
|
|
10
|
-
};
|
|
11
|
-
export type ServiceOperation = {
|
|
12
|
-
method: 'get' | 'put' | 'post' | 'patch' | 'delete' | 'options' | 'head' | 'trace';
|
|
13
|
-
path: string;
|
|
14
|
-
name: string;
|
|
15
|
-
description: string | undefined;
|
|
16
|
-
summary: string | undefined;
|
|
17
|
-
deprecated: boolean | undefined;
|
|
18
|
-
mediaType: string | undefined;
|
|
19
|
-
errors: Record<string, string | undefined>;
|
|
20
|
-
success: Record<string, string | undefined>;
|
|
21
|
-
parameters: Record<string, any> | undefined;
|
|
22
|
-
};
|
|
23
|
-
export declare const getServices: (openApiJson: OpenAPISchemaType, { postfixServices, serviceNameBase, }?: {
|
|
24
|
-
postfixServices?: string | undefined;
|
|
25
|
-
serviceNameBase?: ServiceBaseName | undefined;
|
|
26
|
-
}, servicesGlob?: string[]) => Service[];
|
|
27
|
-
/**
|
|
28
|
-
* Create a function to match service paths
|
|
29
|
-
* @param servicesGlob
|
|
30
|
-
*/
|
|
31
|
-
export declare const createServicePathMatch: (servicesGlob: string[]) => (path: string) => boolean;
|
|
32
|
-
export declare const supportedMethod: (method: unknown) => method is "get" | "put" | "post" | "patch" | "delete" | "options" | "head" | "trace";
|
|
@@ -1,112 +0,0 @@
|
|
|
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 (!paths.hasOwnProperty(path))
|
|
14
|
-
continue;
|
|
15
|
-
for (const method in paths[path]) {
|
|
16
|
-
if (!paths[path].hasOwnProperty(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
|
|
@@ -1 +0,0 @@
|
|
|
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;AAkCrF,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,WAA8B,EAC9B,EACE,eAAe,GAAG,SAAS,EAC3B,eAAe,GAAG,aAAa,MACoC,EAAE,EACvE,YAAY,GAAG,CAAC,IAAI,CAAC,EACrB,EAAE;IACF,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC;IAEhC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAmB,CAAC;IAE5C,MAAM,WAAW,GAAG,sBAAsB,CAAC,YAAY,CAAC,CAAC;IAEzD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,KAAK,CAAC,cA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AM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;CACwC,CAAC,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
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>;
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"readSchema.js","sourceRoot":"","sources":["../../../src/lib/open-api/readSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAIrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAIzE,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAC7B,MAAmD,EACnD,EAAE;IACF,MAAM,KAAK,GAAG,MAAM,YAAY,CAC9B;QACE,KAAK,EAAE;YACL,8BAA8B,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,wCAAwC;SAChG;KACF,EACD,EAAE,OAAO,EAAE,CAAC,SAAS,CAAC,EAAE,CACzB,CAAC;IAEF,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE;QAC7C,KAAK;QACL,MAAM,EAAE,KAAK;KACd,CAAC,CAAC;IAEH,OAAO,MAA2B,CAAC;AACrC,CAAC,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
export interface AstToStringOptions {
|
|
3
|
-
fileName?: string;
|
|
4
|
-
sourceText?: string;
|
|
5
|
-
formatOptions?: ts.PrinterOptions;
|
|
6
|
-
}
|
|
7
|
-
/** Convert TypeScript AST to string */
|
|
8
|
-
export declare function astToString(ast: ts.Node | ts.Node[] | ts.TypeElement | ts.TypeElement[], options?: AstToStringOptions): string;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
/** Convert TypeScript AST to string */
|
|
3
|
-
export function astToString(ast, options) {
|
|
4
|
-
const sourceFile = ts.createSourceFile(options?.fileName ?? "openapi-ts.ts", options?.sourceText ?? "", ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
|
|
5
|
-
// @ts-expect-error it’s OK to overwrite statements once
|
|
6
|
-
sourceFile.statements = ts.factory.createNodeArray(Array.isArray(ast) ? ast : [ast]);
|
|
7
|
-
const printer = ts.createPrinter({
|
|
8
|
-
newLine: ts.NewLineKind.LineFeed,
|
|
9
|
-
removeComments: false,
|
|
10
|
-
...options?.formatOptions,
|
|
11
|
-
});
|
|
12
|
-
return printer.printFile(sourceFile);
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=astToString.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"astToString.js","sourceRoot":"","sources":["../../../src/lib/ts-factory/astToString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAQ5B,uCAAuC;AACvC,MAAM,UAAU,WAAW,CACzB,GAA4D,EAC5D,OAA4B;IAE5B,MAAM,UAAU,GAAG,EAAE,CAAC,gBAAgB,CACpC,OAAO,EAAE,QAAQ,IAAI,eAAe,EACpC,OAAO,EAAE,UAAU,IAAI,EAAE,EACzB,EAAE,CAAC,YAAY,CAAC,MAAM,EACtB,KAAK,EACL,EAAE,CAAC,UAAU,CAAC,EAAE,CACjB,CAAC;IAEF,wDAAwD;IACxD,UAAU,CAAC,UAAU,GAAG,EAAE,CAAC,OAAO,CAAC,eAAe,CAChD,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CACjC,CAAC;IAEF,MAAM,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC;QAC/B,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ;QAChC,cAAc,EAAE,KAAK;QACrB,GAAG,OAAO,EAAE,aAAa;KAC1B,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
export const getClientFactory = (options) => {
|
|
3
|
-
return [
|
|
4
|
-
...getClientImportsFactory(options),
|
|
5
|
-
getCallbacksVariableFactory(),
|
|
6
|
-
getCreateClientFunctionFactory(),
|
|
7
|
-
];
|
|
8
|
-
};
|
|
9
|
-
const getClientImportsFactory = ({ servicesDirName, explicitImportExtensions, }) => {
|
|
10
|
-
const factory = ts.factory;
|
|
11
|
-
return [
|
|
12
|
-
factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
13
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier('qraftAPIClient')),
|
|
14
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier('QraftClientOptions')),
|
|
15
|
-
])), factory.createStringLiteral('@openapi-qraft/react'), undefined),
|
|
16
|
-
...serviceCallbacks.map((propertyName) => factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
17
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier(propertyName)),
|
|
18
|
-
])), factory.createStringLiteral(`@openapi-qraft/react/callbacks/${propertyName}`), undefined)),
|
|
19
|
-
factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
20
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier('services')),
|
|
21
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier('Services')),
|
|
22
|
-
])), factory.createStringLiteral(`./${servicesDirName}/index${explicitImportExtensions ? '.js' : ''}`), undefined),
|
|
23
|
-
];
|
|
24
|
-
};
|
|
25
|
-
const getCallbacksVariableFactory = () => {
|
|
26
|
-
const factory = ts.factory;
|
|
27
|
-
return factory.createVariableStatement(undefined, factory.createVariableDeclarationList([
|
|
28
|
-
factory.createVariableDeclaration(factory.createIdentifier('callbacks'), undefined, undefined, factory.createObjectLiteralExpression(serviceCallbacks.map((propertyName) => factory.createShorthandPropertyAssignment(factory.createIdentifier(propertyName), undefined)), true)),
|
|
29
|
-
], ts.NodeFlags.Const));
|
|
30
|
-
};
|
|
31
|
-
const getCreateClientFunctionFactory = () => {
|
|
32
|
-
const factory = ts.factory;
|
|
33
|
-
return factory.createFunctionDeclaration([factory.createToken(ts.SyntaxKind.ExportKeyword)], undefined, factory.createIdentifier('createAPIClient'), undefined, [
|
|
34
|
-
factory.createParameterDeclaration(undefined, undefined, factory.createIdentifier('options'), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(factory.createIdentifier('QraftClientOptions'), undefined), undefined),
|
|
35
|
-
], factory.createTypeReferenceNode(factory.createIdentifier('Services'), undefined), factory.createBlock([
|
|
36
|
-
factory.createReturnStatement(factory.createCallExpression(factory.createIdentifier('qraftAPIClient'), [
|
|
37
|
-
factory.createTypeReferenceNode(factory.createIdentifier('Services'), undefined),
|
|
38
|
-
factory.createTypeQueryNode(factory.createIdentifier('callbacks'), undefined),
|
|
39
|
-
], [
|
|
40
|
-
factory.createIdentifier('services'),
|
|
41
|
-
factory.createIdentifier('callbacks'),
|
|
42
|
-
factory.createIdentifier('options'),
|
|
43
|
-
])),
|
|
44
|
-
], true));
|
|
45
|
-
};
|
|
46
|
-
const serviceCallbacks = [
|
|
47
|
-
'getInfiniteQueryData',
|
|
48
|
-
'getInfiniteQueryKey',
|
|
49
|
-
'getMutationKey',
|
|
50
|
-
'getQueryData',
|
|
51
|
-
'getQueriesData',
|
|
52
|
-
'getQueryKey',
|
|
53
|
-
'mutationFn',
|
|
54
|
-
'queryFn',
|
|
55
|
-
'setInfiniteQueryData',
|
|
56
|
-
'setQueryData',
|
|
57
|
-
'setQueriesData',
|
|
58
|
-
'useInfiniteQuery',
|
|
59
|
-
'useMutation',
|
|
60
|
-
'useQuery',
|
|
61
|
-
'useSuspenseQuery',
|
|
62
|
-
'useSuspenseInfiniteQuery',
|
|
63
|
-
'useMutationState',
|
|
64
|
-
'useIsMutating',
|
|
65
|
-
'useQueries',
|
|
66
|
-
'useSuspenseQueries',
|
|
67
|
-
'invalidateQueries',
|
|
68
|
-
'cancelQueries',
|
|
69
|
-
'resetQueries',
|
|
70
|
-
'removeQueries',
|
|
71
|
-
'refetchQueries',
|
|
72
|
-
'isFetching',
|
|
73
|
-
'isMutating',
|
|
74
|
-
'useIsFetching',
|
|
75
|
-
'fetchQuery',
|
|
76
|
-
'prefetchQuery',
|
|
77
|
-
'fetchInfiniteQuery',
|
|
78
|
-
'prefetchInfiniteQuery',
|
|
79
|
-
'getQueryState',
|
|
80
|
-
'getInfiniteQueryState',
|
|
81
|
-
];
|
|
82
|
-
//# sourceMappingURL=getClientFactory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getClientFactory.js","sourceRoot":"","sources":["../../../src/lib/ts-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AAY;IACZ,YAAY;IACZ,eAAe;IACf,YAAY;IACZ,eAAe;IACf,oBAAoB;IACpB,uBAAuB;IACvB,eAAe;IACf,uBAAuB;CACf,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
export const getIndexFactory = ({ servicesDirName, explicitImportExtensions, }) => {
|
|
3
|
-
const factory = ts.factory;
|
|
4
|
-
const importExtension = explicitImportExtensions ? '.js' : '';
|
|
5
|
-
return [
|
|
6
|
-
factory.createExportDeclaration(undefined, false, factory.createNamedExports([
|
|
7
|
-
factory.createExportSpecifier(false, undefined, factory.createIdentifier('services')),
|
|
8
|
-
]), factory.createStringLiteral(`./${servicesDirName}/index${importExtension}`), undefined),
|
|
9
|
-
factory.createExportDeclaration(undefined, true, factory.createNamedExports([
|
|
10
|
-
factory.createExportSpecifier(false, undefined, factory.createIdentifier('Services')),
|
|
11
|
-
]), factory.createStringLiteral(`./${servicesDirName}/index${importExtension}`), undefined),
|
|
12
|
-
factory.createExportDeclaration(undefined, false, factory.createNamedExports([
|
|
13
|
-
factory.createExportSpecifier(false, undefined, factory.createIdentifier('createAPIClient')),
|
|
14
|
-
]), factory.createStringLiteral(`./create-api-client${importExtension}`), undefined),
|
|
15
|
-
];
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=getIndexFactory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getIndexFactory.js","sourceRoot":"","sources":["../../../src/lib/ts-factory/getIndexFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAC9B,eAAe,EACf,wBAAwB,GAIzB,EAAE,EAAE;IACH,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC;IAC3B,MAAM,eAAe,GAAG,wBAAwB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAE9D,OAAO;QACL,OAAO,CAAC,uBAAuB,CAC7B,SAAS,EACT,KAAK,EACL,OAAO,CAAC,kBAAkB,CAAC;YACzB,OAAO,CAAC,qBAAqB,CAC3B,KAAK,EACL,SAAS,EACT,OAAO,CAAC,gBAAgB,CAAC,UAAU,CAAC,CACrC;SACF,CAAC,EACF,OAAO,CAAC,mBAAmB,CACzB,KAAK,eAAe,SAAS,eAAe,EAAE,CAC/C,EACD,SAAS,CACV;QACD,OAAO,CAAC,uBAAuB,CAC7B,SAAS,EACT,IAAI,EACJ,OAAO,CAAC,kBAAkB,CAAC;YACzB,OAAO,CAAC,qBAAqB,CAC3B,KAAK,EACL,SAAS,EACT,OAAO,CAAC,gBAAgB,CAAC,UAAU,CAAC,CACrC;SACF,CAAC,EACF,OAAO,CAAC,mBAAmB,CACzB,KAAK,eAAe,SAAS,eAAe,EAAE,CAC/C,EACD,SAAS,CACV;QACD,OAAO,CAAC,uBAAuB,CAC7B,SAAS,EACT,KAAK,EACL,OAAO,CAAC,kBAAkB,CAAC;YACzB,OAAO,CAAC,qBAAqB,CAC3B,KAAK,EACL,SAAS,EACT,OAAO,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAC5C;SACF,CAAC,EACF,OAAO,CAAC,mBAAmB,CAAC,sBAAsB,eAAe,EAAE,CAAC,EACpE,SAAS,CACV;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
import { ServiceOperation } from '../open-api/getServices.js';
|
|
3
|
-
export type ServiceImportsFactoryOptions = {
|
|
4
|
-
openapiTypesImportPath: string;
|
|
5
|
-
operationGenericsImportPath: string;
|
|
6
|
-
};
|
|
7
|
-
export declare const getServiceFactory: (service: {
|
|
8
|
-
typeName: string;
|
|
9
|
-
variableName: string;
|
|
10
|
-
}, operations: ServiceOperation[], { openapiTypesImportPath, operationGenericsImportPath, }: ServiceImportsFactoryOptions) => (ts.ImportDeclaration | ts.VariableStatement | ts.InterfaceDeclaration)[];
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
const SERVICE_OPERATION_QUERY = 'ServiceOperationQuery';
|
|
3
|
-
const SERVICE_OPERATION_MUTATION = 'ServiceOperationMutation';
|
|
4
|
-
const factory = ts.factory;
|
|
5
|
-
export const getServiceFactory = (service, operations, { openapiTypesImportPath, operationGenericsImportPath, }) => {
|
|
6
|
-
return [
|
|
7
|
-
getOpenAPISchemaImportsFactory(openapiTypesImportPath),
|
|
8
|
-
getServiceOperationGenericsPathImportsFactory(operationGenericsImportPath, operations),
|
|
9
|
-
getServiceInterfaceFactory(service, operations),
|
|
10
|
-
getServiceVariableFactory(service, operations),
|
|
11
|
-
];
|
|
12
|
-
};
|
|
13
|
-
const getOpenAPISchemaImportsFactory = (schemaTypesPath) => {
|
|
14
|
-
const factory = ts.factory;
|
|
15
|
-
return factory.createImportDeclaration(undefined, factory.createImportClause(true, undefined, factory.createNamedImports([
|
|
16
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier('paths')),
|
|
17
|
-
])), factory.createStringLiteral(schemaTypesPath));
|
|
18
|
-
};
|
|
19
|
-
const getServiceOperationGenericsPathImportsFactory = (operationGenericsPath, operations) => {
|
|
20
|
-
const factory = ts.factory;
|
|
21
|
-
const queryMethods = ['get', 'head', 'options'];
|
|
22
|
-
return factory.createImportDeclaration(undefined, factory.createImportClause(true, undefined, factory.createNamedImports([
|
|
23
|
-
operations.some((operation) => queryMethods.some((method) => method === operation.method))
|
|
24
|
-
? factory.createImportSpecifier(false, undefined, factory.createIdentifier('ServiceOperationQuery'))
|
|
25
|
-
: null,
|
|
26
|
-
operations.some((operation) => !queryMethods.some((method) => method === operation.method))
|
|
27
|
-
? factory.createImportSpecifier(false, undefined, factory.createIdentifier('ServiceOperationMutation'))
|
|
28
|
-
: null,
|
|
29
|
-
].filter((node) => Boolean(node)))), factory.createStringLiteral(operationGenericsPath));
|
|
30
|
-
};
|
|
31
|
-
const getServiceInterfaceFactory = ({ typeName }, operations) => {
|
|
32
|
-
return factory.createInterfaceDeclaration([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier(typeName), undefined, undefined, operations.map(getServiceInterfaceOperationFactory));
|
|
33
|
-
};
|
|
34
|
-
const getServiceInterfaceOperationFactory = (operation) => {
|
|
35
|
-
const node = factory.createPropertySignature(undefined, factory.createIdentifier(operation.name), undefined, factory.createTypeReferenceNode(factory.createIdentifier(operation.method === 'get'
|
|
36
|
-
? SERVICE_OPERATION_QUERY
|
|
37
|
-
: SERVICE_OPERATION_MUTATION), [
|
|
38
|
-
getOperationSchemaFactory(operation),
|
|
39
|
-
operation.method !== 'get' ? getOperationBodyFactory(operation) : null,
|
|
40
|
-
getOperationResponseFactory(operation, 'success'),
|
|
41
|
-
getOperationParametersFactory(operation),
|
|
42
|
-
getOperationResponseFactory(operation, 'errors'),
|
|
43
|
-
].filter((node) => Boolean(node))));
|
|
44
|
-
const comment = createMultilineComment([
|
|
45
|
-
operation.deprecated ? '@deprecated' : null,
|
|
46
|
-
operation.summary ? `@summary ${operation.summary}` : null,
|
|
47
|
-
operation.description ? `@description ${operation.description}` : null,
|
|
48
|
-
].filter((comment) => Boolean(comment)));
|
|
49
|
-
if (comment)
|
|
50
|
-
ts.addSyntheticLeadingComment(node, ts.SyntaxKind.MultiLineCommentTrivia, comment, true);
|
|
51
|
-
return node;
|
|
52
|
-
};
|
|
53
|
-
const getOperationSchemaFactory = (operation) => {
|
|
54
|
-
return factory.createTypeLiteralNode([
|
|
55
|
-
factory.createPropertySignature(undefined, factory.createIdentifier('method'), undefined, factory.createLiteralTypeNode(factory.createStringLiteral(operation.method))),
|
|
56
|
-
factory.createPropertySignature(undefined, factory.createIdentifier('url'), undefined, factory.createLiteralTypeNode(factory.createStringLiteral(operation.path))),
|
|
57
|
-
operation.mediaType
|
|
58
|
-
? factory.createPropertySignature(undefined, factory.createIdentifier('mediaType'), undefined, factory.createLiteralTypeNode(factory.createStringLiteral(operation.mediaType)))
|
|
59
|
-
: null,
|
|
60
|
-
].filter((node) => Boolean(node)));
|
|
61
|
-
};
|
|
62
|
-
const getOperationResponseFactory = (operation, type) => {
|
|
63
|
-
if (!operation[type])
|
|
64
|
-
return factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword);
|
|
65
|
-
const responses = Object.entries(operation[type]);
|
|
66
|
-
if (!responses.length)
|
|
67
|
-
return factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword);
|
|
68
|
-
return factory.createUnionTypeNode(responses.map(([statusCode, mediaType]) => {
|
|
69
|
-
if (!mediaType)
|
|
70
|
-
return factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword);
|
|
71
|
-
return factory.createIndexedAccessTypeNode(factory.createIndexedAccessTypeNode(factory.createIndexedAccessTypeNode(factory.createIndexedAccessTypeNode(factory.createIndexedAccessTypeNode(factory.createIndexedAccessTypeNode(factory.createTypeReferenceNode(factory.createIdentifier('paths'), undefined), factory.createLiteralTypeNode(factory.createStringLiteral(operation.path))), factory.createLiteralTypeNode(factory.createStringLiteral(operation.method))), factory.createLiteralTypeNode(factory.createStringLiteral('responses'))), factory.createLiteralTypeNode(factory.createStringLiteral(statusCode))), factory.createLiteralTypeNode(factory.createStringLiteral('content'))), factory.createLiteralTypeNode(factory.createStringLiteral(mediaType)));
|
|
72
|
-
}));
|
|
73
|
-
};
|
|
74
|
-
const getOperationBodyFactory = (operation) => {
|
|
75
|
-
if (!operation.mediaType)
|
|
76
|
-
return factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword);
|
|
77
|
-
return factory.createIndexedAccessTypeNode(factory.createIndexedAccessTypeNode(factory.createTypeReferenceNode(factory.createIdentifier('NonNullable'), [
|
|
78
|
-
factory.createIndexedAccessTypeNode(factory.createIndexedAccessTypeNode(factory.createIndexedAccessTypeNode(factory.createTypeReferenceNode(factory.createIdentifier('paths'), undefined), factory.createLiteralTypeNode(factory.createStringLiteral(operation.path))), factory.createLiteralTypeNode(factory.createStringLiteral(operation.method))), factory.createLiteralTypeNode(factory.createStringLiteral('requestBody'))),
|
|
79
|
-
]),
|
|
80
|
-
// todo::Add optional NonNullable inference, see `POST /entities/{entity_id}/documents`
|
|
81
|
-
factory.createLiteralTypeNode(factory.createStringLiteral('content'))), factory.createLiteralTypeNode(factory.createStringLiteral(operation.mediaType)));
|
|
82
|
-
};
|
|
83
|
-
const getOperationParametersFactory = (operation) => {
|
|
84
|
-
if (!operation.parameters)
|
|
85
|
-
return factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword);
|
|
86
|
-
return factory.createIndexedAccessTypeNode(factory.createIndexedAccessTypeNode(factory.createIndexedAccessTypeNode(factory.createTypeReferenceNode(factory.createIdentifier('paths'), undefined), factory.createLiteralTypeNode(factory.createStringLiteral(operation.path))), factory.createLiteralTypeNode(factory.createStringLiteral(operation.method))), factory.createLiteralTypeNode(factory.createStringLiteral('parameters')));
|
|
87
|
-
};
|
|
88
|
-
const getServiceVariableFactory = ({ typeName, variableName }, operations) => {
|
|
89
|
-
return factory.createVariableStatement([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([
|
|
90
|
-
factory.createVariableDeclaration(factory.createIdentifier(variableName), undefined, getServiceVariableTypeFactory({ typeName }), factory.createAsExpression(factory.createObjectLiteralExpression(operations.map(getServiceVariablePropertyFactory), true), factory.createTypeReferenceNode(factory.createIdentifier('const'), undefined))),
|
|
91
|
-
], ts.NodeFlags.Const));
|
|
92
|
-
};
|
|
93
|
-
const getServiceVariableTypeFactory = ({ typeName }) => {
|
|
94
|
-
return factory.createMappedTypeNode(undefined, factory.createTypeParameterDeclaration(undefined, factory.createIdentifier('key'), factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, factory.createTypeReferenceNode(factory.createIdentifier(typeName), undefined)), undefined), undefined, undefined, factory.createTypeReferenceNode(factory.createIdentifier('Pick'), [
|
|
95
|
-
factory.createIndexedAccessTypeNode(factory.createTypeReferenceNode(factory.createIdentifier(typeName), undefined), factory.createTypeReferenceNode(factory.createIdentifier('key'), undefined)),
|
|
96
|
-
factory.createLiteralTypeNode(factory.createStringLiteral('schema')),
|
|
97
|
-
]), undefined);
|
|
98
|
-
};
|
|
99
|
-
const getServiceVariablePropertyFactory = (operation) => {
|
|
100
|
-
return factory.createPropertyAssignment(factory.createIdentifier(operation.name), factory.createObjectLiteralExpression([
|
|
101
|
-
factory.createPropertyAssignment(factory.createIdentifier('schema'), factory.createObjectLiteralExpression([
|
|
102
|
-
factory.createPropertyAssignment(factory.createIdentifier('method'), factory.createStringLiteral(operation.method)),
|
|
103
|
-
factory.createPropertyAssignment(factory.createIdentifier('url'), factory.createStringLiteral(operation.path)),
|
|
104
|
-
operation.mediaType
|
|
105
|
-
? factory.createPropertyAssignment(factory.createIdentifier('mediaType'), factory.createStringLiteral(operation.mediaType))
|
|
106
|
-
: null,
|
|
107
|
-
].filter((node) => Boolean(node)), true)),
|
|
108
|
-
], true));
|
|
109
|
-
};
|
|
110
|
-
const createMultilineComment = (comment) => {
|
|
111
|
-
const output = comment.flatMap((line) => line.includes('\n') ? line.split('\n') : line);
|
|
112
|
-
if (output.length) {
|
|
113
|
-
const text = output.length === 1
|
|
114
|
-
? `* ${output.join('\n')} `
|
|
115
|
-
: `*\n * ${output.join('\n * ')}\n `;
|
|
116
|
-
return text.replace(/\*\//g, '*\\/'); // prevent inner comments from leaking
|
|
117
|
-
}
|
|
118
|
-
return '';
|
|
119
|
-
};
|
|
120
|
-
//# sourceMappingURL=getServiceFactory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getServiceFactory.js","sourceRoot":"","sources":["../../../src/lib/ts-factory/getServiceFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAI5B,MAAM,uBAAuB,GAAG,uBAAuB,CAAC;AACxD,MAAM,0BAA0B,GAAG,0BAA0B,CAAC;AAE9D,MAAM,OAAO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AC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAC9C,CAAC;IAEF,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClB,MAAM,IAAI,GACR,MAAM,CAAC,MAAM,KAAK,CAAC;YACjB,CAAC,CAAC,KAAK,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;YAC3B,CAAC,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;QAEzC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,sCAAsC;IAC9E,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
import { Service } from '../open-api/getServices.js';
|
|
3
|
-
type Options = {
|
|
4
|
-
explicitImportExtensions: boolean;
|
|
5
|
-
};
|
|
6
|
-
export declare const getServiceIndexFactory: (services: Service[], options: Options) => (ts.ImportDeclaration | ts.VariableStatement | ts.TypeAliasDeclaration)[];
|
|
7
|
-
export {};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
export const getServiceIndexFactory = (services, options) => {
|
|
3
|
-
return [
|
|
4
|
-
...getServicesImportsFactory(services, options),
|
|
5
|
-
getServiceIndexInterfaceFactory(services),
|
|
6
|
-
getServiceIndexVariableFactory(services),
|
|
7
|
-
];
|
|
8
|
-
};
|
|
9
|
-
const getServiceIndexInterfaceFactory = (services) => {
|
|
10
|
-
const factory = ts.factory;
|
|
11
|
-
return factory.createTypeAliasDeclaration([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier('Services'), undefined, factory.createTypeLiteralNode(services.map(({ name, typeName }) => factory.createPropertySignature(undefined, factory.createIdentifier(name), undefined, factory.createTypeReferenceNode(factory.createIdentifier(typeName), undefined)))));
|
|
12
|
-
};
|
|
13
|
-
const getServiceIndexVariableFactory = (services) => {
|
|
14
|
-
const factory = ts.factory;
|
|
15
|
-
return factory.createVariableStatement([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([
|
|
16
|
-
factory.createVariableDeclaration(factory.createIdentifier('services'), undefined, undefined, factory.createAsExpression(factory.createObjectLiteralExpression(services.map(({ name, variableName }) => factory.createPropertyAssignment(factory.createIdentifier(name), factory.createIdentifier(variableName))), true), factory.createTypeReferenceNode(factory.createIdentifier('const'), undefined))),
|
|
17
|
-
], ts.NodeFlags.Const));
|
|
18
|
-
};
|
|
19
|
-
const getServicesImportsFactory = (services, { explicitImportExtensions }) => {
|
|
20
|
-
const factory = ts.factory;
|
|
21
|
-
return services.map(({ variableName, typeName, fileBaseName }) => factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
22
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier(typeName)),
|
|
23
|
-
factory.createImportSpecifier(false, undefined, factory.createIdentifier(variableName)),
|
|
24
|
-
])), factory.createStringLiteral(`./${fileBaseName}${explicitImportExtensions ? '.js' : ''}`)));
|
|
25
|
-
};
|
|
26
|
-
//# sourceMappingURL=getServiceIndexFactory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getServiceIndexFactory.js","sourceRoot":"","sources":["../../../src/lib/ts-factory/getServiceIndexFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAM5B,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,QAAmB,EACnB,OAAgB,EAChB,EAAE;IACF,OAAO;QACL,GAAG,yBAAyB,CAAC,QAAQ,EAAE,OAAO,CAAC;QAC/C,+BAA+B,CAAC,QAAQ,CAAC;QACzC,8BAA8B,CAAC,QAAQ,CAAC;KACzC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,+BAA+B,GAAG,CAAC,QAAmB,EAAE,EA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AAO,CAAC,EACjC,SAAS,CACV,CACF,CACF;KACF,EACD,EAAE,CAAC,SAAS,CAAC,KAAK,CACnB,CACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,yBAAyB,GAAG,CAChC,QAAmB,EACnB,EAAE,wBAAwB,EAAW,EACrC,EAAE;IACF,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC;IAE3B,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,EAAE,CAC/D,OAAO,CAAC,uBAAuB,CAC7B,SAAS,EACT,OAAO,CAAC,kBAAkB,CACxB,KAAK,EACL,SAAS,EACT,OAAO,CAAC,kBAAkB,CAAC;QACzB,OAAO,CAAC,qBAAqB,CAC3B,KAAK,EACL,SAAS,EACT,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CACnC;QACD,OAAO,CAAC,qBAAqB,CAC3B,KAAK,EACL,SAAS,EACT,OAAO,CAAC,gBAAgB,CAAC,YAAY,CAAC,CACvC;KACF,CAAC,CACH,EACD,OAAO,CAAC,mBAAmB,CACzB,KAAK,YAAY,GAAG,wBAAwB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAC5D,CACF,CACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
4
|
-
import { Readable } from 'node:stream';
|
|
5
|
-
import { OpenAPI3 } from 'openapi-typescript';
|
|
6
|
-
import { ServiceBaseName } from './lib/open-api/getServices.js';
|
|
7
|
-
import { ServiceImportsFactoryOptions } from './lib/ts-factory/getServiceFactory.js';
|
|
8
|
-
type OutputOptions = {
|
|
9
|
-
fileHeader?: string;
|
|
10
|
-
dir: string;
|
|
11
|
-
clean: boolean;
|
|
12
|
-
postfixServices?: string;
|
|
13
|
-
explicitImportExtensions?: boolean;
|
|
14
|
-
servicesDirName: string;
|
|
15
|
-
serviceNameBase?: ServiceBaseName;
|
|
16
|
-
};
|
|
17
|
-
export declare const writeOpenAPIServices: ({ source, servicesGlob, serviceImports, output, }: {
|
|
18
|
-
source: string | URL | OpenAPI3 | Readable | Buffer;
|
|
19
|
-
servicesGlob: string[] | undefined;
|
|
20
|
-
serviceImports: ServiceImportsFactoryOptions;
|
|
21
|
-
output: OutputOptions;
|
|
22
|
-
}) => Promise<void>;
|
|
23
|
-
export {};
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import c from 'ansi-colors';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import { resolve } from 'node:path';
|
|
4
|
-
import ora from 'ora';
|
|
5
|
-
import { getServices, } from './lib/open-api/getServices.js';
|
|
6
|
-
import { readSchema } from './lib/open-api/readSchema.js';
|
|
7
|
-
import { astToString } from './lib/ts-factory/astToString.js';
|
|
8
|
-
import { getClientFactory } from './lib/ts-factory/getClientFactory.js';
|
|
9
|
-
import { getIndexFactory } from './lib/ts-factory/getIndexFactory.js';
|
|
10
|
-
import { getServiceFactory, } from './lib/ts-factory/getServiceFactory.js';
|
|
11
|
-
import { getServiceIndexFactory } from './lib/ts-factory/getServiceIndexFactory.js';
|
|
12
|
-
export const writeOpenAPIServices = async ({ source, servicesGlob, serviceImports, output, }) => {
|
|
13
|
-
const schema = await readSchema(source);
|
|
14
|
-
const services = getServices(schema, output, servicesGlob);
|
|
15
|
-
await writeServices(services, serviceImports, output);
|
|
16
|
-
await writeServiceIndex(services, output);
|
|
17
|
-
await writeClient(output);
|
|
18
|
-
await writeIndex(output);
|
|
19
|
-
};
|
|
20
|
-
const writeServices = async (services, serviceImports, output) => {
|
|
21
|
-
const servicesDir = resolve(output.dir, output.servicesDirName);
|
|
22
|
-
if (output.clean)
|
|
23
|
-
await fs.promises.rm(servicesDir, {
|
|
24
|
-
recursive: true,
|
|
25
|
-
force: true,
|
|
26
|
-
});
|
|
27
|
-
await fs.promises.mkdir(servicesDir, { recursive: true });
|
|
28
|
-
const spinner = ora(`Generating services`).start();
|
|
29
|
-
for (const service of services) {
|
|
30
|
-
const { operations, name, typeName, variableName, fileBaseName } = service;
|
|
31
|
-
spinner.text = `Generating ${c.magenta(name)} service`;
|
|
32
|
-
try {
|
|
33
|
-
const code = getFileHeader(output) +
|
|
34
|
-
astToString(getServiceFactory({
|
|
35
|
-
typeName,
|
|
36
|
-
variableName,
|
|
37
|
-
}, operations, serviceImports));
|
|
38
|
-
await fs.promises.writeFile(resolve(servicesDir, `${fileBaseName}.ts`), code);
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
spinner.fail(c.redBright(`Error occurred during ${c.magenta(name)} service generation`));
|
|
42
|
-
throw error;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
spinner.succeed(c.green('Services has been generated'));
|
|
46
|
-
};
|
|
47
|
-
const writeServiceIndex = async (services, output) => {
|
|
48
|
-
const spinner = ora('Generating services index').start();
|
|
49
|
-
try {
|
|
50
|
-
const code = getFileHeader(output) +
|
|
51
|
-
astToString(getServiceIndexFactory(services, {
|
|
52
|
-
explicitImportExtensions: Boolean(output.explicitImportExtensions),
|
|
53
|
-
}));
|
|
54
|
-
await fs.promises.writeFile(resolve(output.dir, output.servicesDirName, 'index.ts'), code);
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
spinner.fail(c.redBright('Error occurred during services index generation'));
|
|
58
|
-
throw error;
|
|
59
|
-
}
|
|
60
|
-
spinner.succeed(c.green('Services index has been generated'));
|
|
61
|
-
};
|
|
62
|
-
const writeClient = async (output) => {
|
|
63
|
-
const spinner = ora('Generating client').start();
|
|
64
|
-
try {
|
|
65
|
-
const code = getFileHeader(output) +
|
|
66
|
-
astToString(getClientFactory({
|
|
67
|
-
servicesDirName: output.servicesDirName,
|
|
68
|
-
explicitImportExtensions: Boolean(output.explicitImportExtensions),
|
|
69
|
-
}));
|
|
70
|
-
await fs.promises.writeFile(resolve(output.dir, 'create-api-client.ts'), code);
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
spinner.fail(c.redBright('Error occurred during client generation'));
|
|
74
|
-
throw error;
|
|
75
|
-
}
|
|
76
|
-
spinner.succeed(c.green('Client has been generated'));
|
|
77
|
-
};
|
|
78
|
-
const writeIndex = async (output) => {
|
|
79
|
-
const spinner = ora('Generating index').start();
|
|
80
|
-
try {
|
|
81
|
-
const code = getFileHeader(output) +
|
|
82
|
-
astToString(getIndexFactory({
|
|
83
|
-
servicesDirName: output.servicesDirName,
|
|
84
|
-
explicitImportExtensions: Boolean(output.explicitImportExtensions),
|
|
85
|
-
}));
|
|
86
|
-
await fs.promises.writeFile(resolve(output.dir, 'index.ts'), code);
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
spinner.fail(c.redBright('Error occurred during index generation'));
|
|
90
|
-
throw error;
|
|
91
|
-
}
|
|
92
|
-
spinner.succeed(c.green('Index has been generated'));
|
|
93
|
-
};
|
|
94
|
-
const getFileHeader = ({ fileHeader }) => {
|
|
95
|
-
return fileHeader && `${fileHeader}\n`;
|
|
96
|
-
};
|
|
97
|
-
//# sourceMappingURL=writeOpenAPIServices.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"writeOpenAPIServices.js","sourceRoot":"","sources":["../src/writeOpenAPIServices.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,aAAa,CAAC;AAC5B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,OAAO,EACL,WAAW,GAGZ,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,C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