@travetto/openapi 3.1.4 → 3.1.6
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/package.json +7 -3
- package/src/controller.ts +2 -1
- package/src/spec-generate.ts +22 -20
- package/support/cli.openapi_client.ts +38 -27
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/openapi",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.6",
|
|
4
4
|
"description": "OpenAPI integration support for the Travetto framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rest",
|
|
@@ -27,17 +27,21 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@travetto/config": "^3.1.2",
|
|
30
|
-
"@travetto/rest": "^3.1.
|
|
30
|
+
"@travetto/rest": "^3.1.3",
|
|
31
31
|
"@travetto/schema": "^3.1.2",
|
|
32
32
|
"@travetto/yaml": "^3.1.1",
|
|
33
33
|
"openapi3-ts": "^3.1.2"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@travetto/cli": "^3.1.2"
|
|
36
|
+
"@travetto/cli": "^3.1.2",
|
|
37
|
+
"@travetto/command": "^3.1.2"
|
|
37
38
|
},
|
|
38
39
|
"peerDependenciesMeta": {
|
|
39
40
|
"@travetto/cli": {
|
|
40
41
|
"optional": true
|
|
42
|
+
},
|
|
43
|
+
"@travetto/command": {
|
|
44
|
+
"optional": true
|
|
41
45
|
}
|
|
42
46
|
},
|
|
43
47
|
"travetto": {
|
package/src/controller.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Controller, Get, SetHeaders } from '@travetto/rest';
|
|
1
|
+
import { Controller, Get, SetHeaders, Undocumented } from '@travetto/rest';
|
|
2
2
|
import { Inject } from '@travetto/di';
|
|
3
3
|
import { YamlUtil } from '@travetto/yaml';
|
|
4
4
|
|
|
@@ -7,6 +7,7 @@ import { OpenApiService } from './service';
|
|
|
7
7
|
/**
|
|
8
8
|
* Basic controller for surfacing the api spec
|
|
9
9
|
*/
|
|
10
|
+
@Undocumented()
|
|
10
11
|
@Controller('/')
|
|
11
12
|
export class OpenApiController {
|
|
12
13
|
|
package/src/spec-generate.ts
CHANGED
|
@@ -11,7 +11,6 @@ import { SchemaRegistry, FieldConfig } from '@travetto/schema';
|
|
|
11
11
|
import { AllViewⲐ } from '@travetto/schema/src/internal/types';
|
|
12
12
|
|
|
13
13
|
import { ApiSpecConfig } from './config';
|
|
14
|
-
import { OpenApiController } from './controller';
|
|
15
14
|
|
|
16
15
|
const DEFINITION = '#/components/schemas';
|
|
17
16
|
|
|
@@ -354,29 +353,20 @@ export class SpecGenerator {
|
|
|
354
353
|
};
|
|
355
354
|
}
|
|
356
355
|
|
|
357
|
-
/**
|
|
358
|
-
* Process each controller
|
|
359
|
-
*/
|
|
360
|
-
processController(cls: Class): void {
|
|
361
|
-
const ctrl = ControllerRegistry.get(cls);
|
|
362
|
-
|
|
363
|
-
this.#tags.push({
|
|
364
|
-
name: this.#getTypeTag(ctrl.class),
|
|
365
|
-
description: ctrl.description || ctrl.title
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
for (const ep of ctrl.endpoints) {
|
|
369
|
-
this.processEndpoint(ctrl, ep);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
356
|
/**
|
|
374
357
|
* Generate full specification
|
|
375
358
|
*/
|
|
376
359
|
generate(config: Partial<ApiSpecConfig> = {}): GeneratedSpec {
|
|
377
360
|
|
|
378
361
|
for (const cls of ControllerRegistry.getClasses()) {
|
|
379
|
-
|
|
362
|
+
const controller = ControllerRegistry.get(cls);
|
|
363
|
+
if (controller.documented === false) {
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
for (const ep of controller.endpoints) {
|
|
367
|
+
if (ep.documented === false) {
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
380
370
|
if (ep.requestType) {
|
|
381
371
|
this.#processSchema(ep.requestType.type);
|
|
382
372
|
}
|
|
@@ -391,8 +381,20 @@ export class SpecGenerator {
|
|
|
391
381
|
|
|
392
382
|
if (!config.skipRoutes) {
|
|
393
383
|
for (const cls of ControllerRegistry.getClasses()) {
|
|
394
|
-
|
|
395
|
-
|
|
384
|
+
const controller = ControllerRegistry.get(cls);
|
|
385
|
+
if (controller.documented === false) {
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
this.#tags.push({
|
|
389
|
+
name: this.#getTypeTag(controller.class),
|
|
390
|
+
description: controller.description || controller.title
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
for (const ep of controller.endpoints) {
|
|
394
|
+
if (ep.documented === false) {
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
this.processEndpoint(controller, ep);
|
|
396
398
|
}
|
|
397
399
|
}
|
|
398
400
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
|
|
3
1
|
import { path } from '@travetto/manifest';
|
|
4
|
-
import {
|
|
2
|
+
import { ShutdownManager } from '@travetto/base';
|
|
5
3
|
import { CliCommandShape, CliCommand, CliFlag } from '@travetto/cli';
|
|
4
|
+
import { DockerContainer } from '@travetto/command';
|
|
6
5
|
|
|
7
6
|
import { OpenApiClientHelp } from './bin/help';
|
|
8
7
|
import { OpenApiClientPresets } from './bin/presets';
|
|
@@ -25,6 +24,27 @@ export class OpenApiClientCommand implements CliCommandShape {
|
|
|
25
24
|
@CliFlag({ desc: 'Watch for file changes' })
|
|
26
25
|
watch?: boolean;
|
|
27
26
|
|
|
27
|
+
async getPropList(format: string): Promise<string> {
|
|
28
|
+
let propMap = Object.fromEntries(this.props?.map(p => p.split('=')) ?? []);
|
|
29
|
+
|
|
30
|
+
if (format.startsWith('@travetto/')) {
|
|
31
|
+
const key = format.split('@travetto/')[1];
|
|
32
|
+
const [, props] = (await OpenApiClientPresets.getPresets())[key];
|
|
33
|
+
propMap = { ...props, ...propMap };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return OpenApiClientPresets.presetMap(propMap);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async getResolvedFormat(format: string): Promise<string> {
|
|
40
|
+
if (format.startsWith('@travetto/')) {
|
|
41
|
+
const key = format.split('@travetto/')[1];
|
|
42
|
+
const [fmt] = (await OpenApiClientPresets.getPresets())[key];
|
|
43
|
+
return fmt;
|
|
44
|
+
}
|
|
45
|
+
return format;
|
|
46
|
+
}
|
|
47
|
+
|
|
28
48
|
async help(): Promise<string[]> {
|
|
29
49
|
return OpenApiClientHelp.help(this.dockerImage, this.extendedHelp ?? false);
|
|
30
50
|
}
|
|
@@ -33,39 +53,30 @@ export class OpenApiClientCommand implements CliCommandShape {
|
|
|
33
53
|
this.output = path.resolve(this.output);
|
|
34
54
|
this.input = path.resolve(this.input);
|
|
35
55
|
|
|
36
|
-
|
|
37
|
-
|
|
56
|
+
const cmd = new DockerContainer(this.dockerImage)
|
|
57
|
+
.setUser(process.geteuid?.() ?? 0, process.getgid?.() ?? 0)
|
|
58
|
+
.addVolume(this.output, '/workspace')
|
|
59
|
+
.addVolume(path.dirname(this.input), '/input')
|
|
60
|
+
.setInteractive(true)
|
|
61
|
+
.setTTY(false)
|
|
62
|
+
.setDeleteOnFinish(true);
|
|
38
63
|
|
|
39
|
-
|
|
64
|
+
const propList = await this.getPropList(format);
|
|
40
65
|
|
|
41
|
-
|
|
42
|
-
const key = format.split('@travetto/')[1];
|
|
43
|
-
const [fmt, props] = (await OpenApiClientPresets.getPresets())[key];
|
|
44
|
-
format = fmt;
|
|
45
|
-
propMap = { ...props, ...propMap };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const propList = OpenApiClientPresets.presetMap(propMap);
|
|
49
|
-
|
|
50
|
-
const args = [
|
|
51
|
-
'run',
|
|
52
|
-
'--user', `${process.geteuid?.()}:${process.getgid?.()}`,
|
|
53
|
-
'-v', `${this.output}:/workspace`,
|
|
54
|
-
'-v', `${path.dirname(this.input)}:/input`,
|
|
55
|
-
'-it',
|
|
56
|
-
'--rm',
|
|
57
|
-
this.dockerImage,
|
|
66
|
+
const res = cmd.run([
|
|
58
67
|
'generate',
|
|
59
68
|
'--skip-validate-spec',
|
|
60
69
|
'--remove-operation-id-prefix',
|
|
61
|
-
'-g', format,
|
|
70
|
+
'-g', await this.getResolvedFormat(format),
|
|
62
71
|
'-o', '/workspace',
|
|
63
72
|
'-i', `/input/${path.basename(this.input)}`,
|
|
64
73
|
...(this.watch ? ['-w'] : []),
|
|
65
74
|
...(propList ? ['--additional-properties', propList] : [])
|
|
66
|
-
];
|
|
75
|
+
]);
|
|
67
76
|
|
|
68
|
-
const
|
|
69
|
-
|
|
77
|
+
const result = await res;
|
|
78
|
+
if (!result.valid) {
|
|
79
|
+
ShutdownManager.exit(1);
|
|
80
|
+
}
|
|
70
81
|
}
|
|
71
82
|
}
|