@travetto/openapi 3.1.5 → 3.1.7

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/openapi",
3
- "version": "3.1.5",
3
+ "version": "3.1.7",
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.3",
30
+ "@travetto/rest": "^3.1.4",
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
@@ -19,7 +19,7 @@ export class OpenApiController {
19
19
  return this.service.spec; // Force output to be simple
20
20
  }
21
21
 
22
- @Get(/openapi[.]ya?ml$/)
22
+ @Get('openapi.yaml')
23
23
  @SetHeaders({ 'Content-Type': 'text/vnd.yaml' })
24
24
  async getYmlSpec(): Promise<string> {
25
25
  return YamlUtil.serialize(this.service.spec); // Force output to be simple
@@ -1,8 +1,7 @@
1
- import fs from 'fs/promises';
2
-
3
1
  import { path } from '@travetto/manifest';
4
- import { ExecUtil, ShutdownManager } from '@travetto/base';
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
- // Ensure its there
37
- await fs.mkdir(this.output, { recursive: true });
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
- let propMap = Object.fromEntries(this.props?.map(p => p.split('=')) ?? []);
64
+ const propList = await this.getPropList(format);
40
65
 
41
- if (format.startsWith('@travetto/')) {
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 { result } = ExecUtil.spawn('docker', args, { stdio: [0, 1, 2] });
69
- await result.catch(err => ShutdownManager.exit(1));
77
+ const result = await res;
78
+ if (!result.valid) {
79
+ ShutdownManager.exit(1);
80
+ }
70
81
  }
71
82
  }