Skip to content

Commit 0f2a214

Browse files
committed
fix: redocly config selective use
1 parent 2142553 commit 0f2a214

9 files changed

Lines changed: 222 additions & 132 deletions

File tree

e2e/projects/typescript-nodenext-qraft-cli-unified/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"scripts": {
77
"build": "tsc",
88
"codegen": "qraft redocly --redocly redocly.yaml",
9-
"e2e:pre-build": "npm run codegen",
9+
"codegen:selective-openapi": "qraft redocly openapi-selective --redocly redocly-selective.yaml",
10+
"codegen:selective-asyncapi": "qraft redocly asyncapi-selective --redocly redocly-selective.yaml",
11+
"e2e:pre-build": "npm run codegen && npm run codegen:selective-openapi && npm run codegen:selective-asyncapi",
1012
"e2e:post-build": "echo 'Build completed'"
1113
},
1214
"dependencies": {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apis:
2+
openapi-selective:
3+
root: https://raw.githubusercontent.com/swagger-api/swagger-petstore/7767363b841961221a38c0be9c6b1066a5120051/src/main/resources/openapi.yaml
4+
x-openapi-qraft:
5+
plugin:
6+
openapi-typescript: true
7+
output-dir: src/openapi-selective
8+
clean: true
9+
10+
asyncapi-selective:
11+
root: ./asyncapi.json
12+
x-asyncapi-qraft:
13+
plugin:
14+
asyncapi-typescript: true
15+
output-dir: src/asyncapi-selective
16+
clean: true
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
1+
import type * as AsyncAPISelectiveSchema from './asyncapi-selective/schema.js';
12
import type * as AsyncAPISchema from './asyncapi/schema.js';
3+
import type * as OpenAPISelectiveSchema from './openapi-selective/schema.js';
24
import type * as OpenAPISchema from './openapi/schema.js';
35
import { createAPIClient } from './openapi/index.js';
46
import { services } from './openapi/services/index.js';
57

68
type OpenAPISchemaComponents = OpenAPISchema.components['schemas'];
79
type AsyncAPISchemaComponents = AsyncAPISchema.components['schemas'];
10+
type OpenAPISelectiveComponents = OpenAPISelectiveSchema.components['schemas'];
11+
type AsyncAPISelectiveComponents =
12+
AsyncAPISelectiveSchema.components['schemas'];
813

914
const _openAPITest: OpenAPISchemaComponents = {} as OpenAPISchemaComponents;
1015
const _asyncAPITest: AsyncAPISchemaComponents = {} as AsyncAPISchemaComponents;
16+
const _openAPISelectiveTest: OpenAPISelectiveComponents =
17+
{} as OpenAPISelectiveComponents;
18+
const _asyncAPISelectiveTest: AsyncAPISelectiveComponents =
19+
{} as AsyncAPISelectiveComponents;
1120

12-
export type { OpenAPISchema, AsyncAPISchema };
21+
export type {
22+
OpenAPISchema,
23+
AsyncAPISchema,
24+
OpenAPISelectiveSchema,
25+
AsyncAPISelectiveSchema,
26+
};
1327

1428
export { createAPIClient, services };

packages/cli/src/bin.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import {
1010
} from '@qraft/plugin/lib/RedoclyConfigCommand';
1111
import c from 'ansi-colors';
1212
import { Command } from 'commander';
13-
import { runAsyncAPI } from './commands/runAsyncAPI.js';
14-
import { runOpenAPI } from './commands/runOpenAPI.js';
1513
import { packageVersion } from './packageVersion.js';
1614

1715
export async function main(
@@ -64,13 +62,20 @@ export async function main(
6462
.action(async (apis: string[], options: { redocly: string | boolean }) => {
6563
const redoclyArgv = buildRedoclyArgv(apis, options.redocly);
6664

67-
await new RedoclyConfigCommand(undefined, {
68-
configKey: OPENAPI_QRAFT_REDOC_CONFIG_KEY,
69-
}).parseConfig(runOpenAPI, redoclyArgv, { from: 'user' });
70-
71-
await new RedoclyConfigCommand(undefined, {
72-
configKey: ASYNCAPI_QRAFT_REDOC_CONFIG_KEY,
73-
}).parseConfig(runAsyncAPI, redoclyArgv, { from: 'user' });
65+
await new RedoclyConfigCommand().parseConfig(
66+
{
67+
[OPENAPI_QRAFT_REDOC_CONFIG_KEY]: async (argv, parseOptions) => {
68+
const { runOpenAPI } = await import('./commands/runOpenAPI.js');
69+
return runOpenAPI(argv, parseOptions);
70+
},
71+
[ASYNCAPI_QRAFT_REDOC_CONFIG_KEY]: async (argv, parseOptions) => {
72+
const { runAsyncAPI } = await import('./commands/runAsyncAPI.js');
73+
return runAsyncAPI(argv, parseOptions);
74+
},
75+
},
76+
redoclyArgv,
77+
{ from: 'user' }
78+
);
7479
});
7580

7681
program.addHelpText(

packages/cli/src/commands/asyncapi.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ export async function qraftAsyncapi(
88
const { RedoclyConfigCommand, ASYNCAPI_QRAFT_REDOC_CONFIG_KEY } =
99
await import('@qraft/plugin/lib/RedoclyConfigCommand');
1010

11-
const redoclyConfigParseResult = await new RedoclyConfigCommand(undefined, {
12-
configKey: ASYNCAPI_QRAFT_REDOC_CONFIG_KEY,
13-
}).parseConfig(runAsyncAPI, processArgv, processArgvParseOptions);
11+
const redoclyConfigParseResult = await new RedoclyConfigCommand().parseConfig(
12+
{ [ASYNCAPI_QRAFT_REDOC_CONFIG_KEY]: runAsyncAPI },
13+
processArgv,
14+
processArgvParseOptions
15+
);
1416

1517
if (redoclyConfigParseResult?.length) return;
1618

packages/cli/src/commands/openapi.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ export async function qraftOpenapi(
88
const { RedoclyConfigCommand, OPENAPI_QRAFT_REDOC_CONFIG_KEY } =
99
await import('@qraft/plugin/lib/RedoclyConfigCommand');
1010

11-
const redoclyConfigParseResult = await new RedoclyConfigCommand(undefined, {
12-
configKey: OPENAPI_QRAFT_REDOC_CONFIG_KEY,
13-
}).parseConfig(runOpenAPI, processArgv, processArgvParseOptions);
11+
const redoclyConfigParseResult = await new RedoclyConfigCommand().parseConfig(
12+
{ [OPENAPI_QRAFT_REDOC_CONFIG_KEY]: runOpenAPI },
13+
processArgv,
14+
processArgvParseOptions
15+
);
1416

1517
if (redoclyConfigParseResult?.length) return;
1618

packages/openapi-cli/src/bin.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ export async function main(
2121
) {
2222
const argv = handleDeprecatedOptions(processArgv);
2323

24-
const redoclyConfigParseResult = await new RedoclyConfigCommand(undefined, {
25-
configKey: OPENAPI_QRAFT_REDOC_CONFIG_KEY,
26-
}).parseConfig(qraft, argv, processArgvParseOptions);
24+
const redoclyConfigParseResult = await new RedoclyConfigCommand().parseConfig(
25+
{ [OPENAPI_QRAFT_REDOC_CONFIG_KEY]: qraft },
26+
argv,
27+
processArgvParseOptions
28+
);
2729

2830
if (redoclyConfigParseResult?.length) return;
2931

packages/plugin/src/lib/RedoclyConfigCommand.spec.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ describe('RedoclyConfigCommand', () => {
1515
const { RedoclyConfigCommand, OPENAPI_QRAFT_REDOC_CONFIG_KEY } =
1616
await import('./RedoclyConfigCommand.js');
1717

18-
const command = new RedoclyConfigCommand(undefined, {
19-
configKey: OPENAPI_QRAFT_REDOC_CONFIG_KEY,
20-
});
18+
const command = new RedoclyConfigCommand();
2119

2220
await expect(
2321
command.parseConfig(
24-
(processArgv, processArgvParseOptions) => [
25-
processArgv,
26-
processArgvParseOptions,
27-
],
22+
{
23+
[OPENAPI_QRAFT_REDOC_CONFIG_KEY]: (
24+
processArgv,
25+
processArgvParseOptions
26+
) => [processArgv, processArgvParseOptions],
27+
},
2828
['--redocly', redoclyConfigPath],
2929
{
3030
from: 'user',
@@ -91,16 +91,16 @@ describe('RedoclyConfigCommand', () => {
9191
const { RedoclyConfigCommand, OPENAPI_QRAFT_REDOC_CONFIG_KEY } =
9292
await import('./RedoclyConfigCommand.js');
9393

94-
const command = new RedoclyConfigCommand(undefined, {
95-
configKey: OPENAPI_QRAFT_REDOC_CONFIG_KEY,
96-
});
94+
const command = new RedoclyConfigCommand();
9795

9896
await expect(
9997
command.parseConfig(
100-
(processArgv, processArgvParseOptions) => [
101-
processArgv,
102-
processArgvParseOptions,
103-
],
98+
{
99+
[OPENAPI_QRAFT_REDOC_CONFIG_KEY]: (
100+
processArgv,
101+
processArgvParseOptions
102+
) => [processArgv, processArgvParseOptions],
103+
},
104104
[
105105
'dummy-node',
106106
'dummy-qraft-bin',
@@ -137,16 +137,16 @@ describe('RedoclyConfigCommand', () => {
137137
const { RedoclyConfigCommand, OPENAPI_QRAFT_REDOC_CONFIG_KEY } =
138138
await import('./RedoclyConfigCommand.js');
139139

140-
const command = new RedoclyConfigCommand(undefined, {
141-
configKey: OPENAPI_QRAFT_REDOC_CONFIG_KEY,
142-
});
140+
const command = new RedoclyConfigCommand();
143141

144142
await expect(
145143
command.parseConfig(
146-
(processArgv, processArgvParseOptions) => [
147-
processArgv,
148-
processArgvParseOptions,
149-
],
144+
{
145+
[OPENAPI_QRAFT_REDOC_CONFIG_KEY]: (
146+
processArgv,
147+
processArgvParseOptions
148+
) => [processArgv, processArgvParseOptions],
149+
},
150150
[
151151
'dummy-node',
152152
'dummy-qraft-bin',

0 commit comments

Comments
 (0)