@travetto/openapi 5.0.0-rc.0 → 5.0.0-rc.10
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/README.md +6 -7
- package/package.json +6 -6
- package/src/config.ts +6 -7
- package/src/service.ts +2 -2
- package/src/spec-generate.ts +3 -4
- package/support/bin/help.ts +2 -3
- package/support/cli.openapi_client.ts +1 -1
- package/support/cli.openapi_spec.ts +2 -2
package/README.md
CHANGED
|
@@ -29,8 +29,7 @@ import path from 'node:path';
|
|
|
29
29
|
import type { ServerObject, ContactObject, LicenseObject } from 'openapi3-ts/oas31';
|
|
30
30
|
|
|
31
31
|
import { Config } from '@travetto/config';
|
|
32
|
-
import {
|
|
33
|
-
import { Env } from '@travetto/base';
|
|
32
|
+
import { Runtime } from '@travetto/runtime';
|
|
34
33
|
import { Required } from '@travetto/schema';
|
|
35
34
|
|
|
36
35
|
/**
|
|
@@ -52,9 +51,9 @@ export class ApiInfoConfig {
|
|
|
52
51
|
version: string;
|
|
53
52
|
|
|
54
53
|
postConstruct(): void {
|
|
55
|
-
this.title ??=
|
|
56
|
-
this.version ??=
|
|
57
|
-
this.description ??=
|
|
54
|
+
this.title ??= Runtime.main.name;
|
|
55
|
+
this.version ??= Runtime.main.version;
|
|
56
|
+
this.description ??= Runtime.main.description;
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
59
|
|
|
@@ -99,8 +98,8 @@ export class ApiSpecConfig {
|
|
|
99
98
|
if (!this.output || this.output === '-') {
|
|
100
99
|
this.persist = false;
|
|
101
100
|
} else {
|
|
102
|
-
this.output = path.resolve(
|
|
103
|
-
this.persist ??=
|
|
101
|
+
this.output = path.resolve(Runtime.mainSourcePath, this.output);
|
|
102
|
+
this.persist ??= Runtime.dynamic;
|
|
104
103
|
}
|
|
105
104
|
if (this.persist) {
|
|
106
105
|
if (!/[.](json|ya?ml) $/.test(this.output)) { // Assume a folder
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/openapi",
|
|
3
|
-
"version": "5.0.0-rc.
|
|
3
|
+
"version": "5.0.0-rc.10",
|
|
4
4
|
"description": "OpenAPI integration support for the Travetto framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rest",
|
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
"directory": "module/openapi"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@travetto/config": "^5.0.0-rc.
|
|
30
|
-
"@travetto/rest": "^5.0.0-rc.
|
|
31
|
-
"@travetto/schema": "^5.0.0-rc.
|
|
29
|
+
"@travetto/config": "^5.0.0-rc.10",
|
|
30
|
+
"@travetto/rest": "^5.0.0-rc.10",
|
|
31
|
+
"@travetto/schema": "^5.0.0-rc.10",
|
|
32
32
|
"yaml": "^2.4.5",
|
|
33
33
|
"openapi3-ts": "^4.3.3"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@travetto/cli": "^5.0.0-rc.
|
|
37
|
-
"@travetto/command": "^5.0.0-rc.
|
|
36
|
+
"@travetto/cli": "^5.0.0-rc.10",
|
|
37
|
+
"@travetto/command": "^5.0.0-rc.9"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@travetto/cli": {
|
package/src/config.ts
CHANGED
|
@@ -3,8 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import type { ServerObject, ContactObject, LicenseObject } from 'openapi3-ts/oas31';
|
|
4
4
|
|
|
5
5
|
import { Config } from '@travetto/config';
|
|
6
|
-
import {
|
|
7
|
-
import { Env } from '@travetto/base';
|
|
6
|
+
import { Runtime } from '@travetto/runtime';
|
|
8
7
|
import { Required } from '@travetto/schema';
|
|
9
8
|
|
|
10
9
|
/**
|
|
@@ -26,9 +25,9 @@ export class ApiInfoConfig {
|
|
|
26
25
|
version: string;
|
|
27
26
|
|
|
28
27
|
postConstruct(): void {
|
|
29
|
-
this.title ??=
|
|
30
|
-
this.version ??=
|
|
31
|
-
this.description ??=
|
|
28
|
+
this.title ??= Runtime.main.name;
|
|
29
|
+
this.version ??= Runtime.main.version;
|
|
30
|
+
this.description ??= Runtime.main.description;
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
33
|
|
|
@@ -73,8 +72,8 @@ export class ApiSpecConfig {
|
|
|
73
72
|
if (!this.output || this.output === '-') {
|
|
74
73
|
this.persist = false;
|
|
75
74
|
} else {
|
|
76
|
-
this.output = path.resolve(
|
|
77
|
-
this.persist ??=
|
|
75
|
+
this.output = path.resolve(Runtime.mainSourcePath, this.output);
|
|
76
|
+
this.persist ??= Runtime.dynamic;
|
|
78
77
|
}
|
|
79
78
|
if (this.persist) {
|
|
80
79
|
if (!/[.](json|ya?ml)$/.test(this.output)) { // Assume a folder
|
package/src/service.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { OpenAPIObject } from 'openapi3-ts/oas31';
|
|
2
2
|
|
|
3
|
-
import { Util } from '@travetto/
|
|
3
|
+
import { Util } from '@travetto/runtime';
|
|
4
4
|
import { Injectable, Inject } from '@travetto/di';
|
|
5
5
|
import { ControllerRegistry, ControllerVisitUtil, RestConfig } from '@travetto/rest';
|
|
6
6
|
import { SchemaRegistry } from '@travetto/schema';
|
|
@@ -80,7 +80,7 @@ export class OpenApiService {
|
|
|
80
80
|
JSON.stringify(spec, undefined, 2) :
|
|
81
81
|
stringify(spec);
|
|
82
82
|
|
|
83
|
-
await Util.bufferedFileWrite(this.apiSpecConfig.output, output);
|
|
83
|
+
await Util.bufferedFileWrite(this.apiSpecConfig.output, output, true);
|
|
84
84
|
} catch (err) {
|
|
85
85
|
console.error('Unable to persist openapi spec', err);
|
|
86
86
|
}
|
package/src/spec-generate.ts
CHANGED
|
@@ -5,8 +5,7 @@ import type {
|
|
|
5
5
|
} from 'openapi3-ts/oas31';
|
|
6
6
|
|
|
7
7
|
import { EndpointConfig, ControllerConfig, ParamConfig, EndpointIOType, ControllerVisitor } from '@travetto/rest';
|
|
8
|
-
import {
|
|
9
|
-
import { Class } from '@travetto/base';
|
|
8
|
+
import { Class, describeFunction } from '@travetto/runtime';
|
|
10
9
|
import { SchemaRegistry, FieldConfig, ClassConfig, SchemaNameResolver } from '@travetto/schema';
|
|
11
10
|
import { AllViewⲐ } from '@travetto/schema/src/internal/types';
|
|
12
11
|
|
|
@@ -218,11 +217,11 @@ export class OpenapiVisitor implements ControllerVisitor<GeneratedSpec> {
|
|
|
218
217
|
}
|
|
219
218
|
|
|
220
219
|
const extra: Record<string, unknown> = {};
|
|
221
|
-
if (
|
|
220
|
+
if (describeFunction(cls)?.abstract) {
|
|
222
221
|
const map = SchemaRegistry.getSubTypesForClass(cls);
|
|
223
222
|
if (map) {
|
|
224
223
|
extra.oneOf = map
|
|
225
|
-
.filter(x => !
|
|
224
|
+
.filter(x => !describeFunction(x)?.abstract)
|
|
226
225
|
.map(c => {
|
|
227
226
|
this.onSchema(SchemaRegistry.get(c));
|
|
228
227
|
return this.#getType(c);
|
package/support/bin/help.ts
CHANGED
|
@@ -2,8 +2,7 @@ import fs from 'node:fs/promises';
|
|
|
2
2
|
import { spawn } from 'node:child_process';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
|
|
5
|
-
import { ExecUtil } from '@travetto/
|
|
6
|
-
import { RuntimeContext } from '@travetto/manifest';
|
|
5
|
+
import { ExecUtil, Runtime } from '@travetto/runtime';
|
|
7
6
|
import { cliTpl } from '@travetto/cli';
|
|
8
7
|
|
|
9
8
|
/**
|
|
@@ -12,7 +11,7 @@ import { cliTpl } from '@travetto/cli';
|
|
|
12
11
|
export class OpenApiClientHelp {
|
|
13
12
|
|
|
14
13
|
static async getListOfFormats(dockerImage: string): Promise<string[]> {
|
|
15
|
-
const formatCache =
|
|
14
|
+
const formatCache = Runtime.toolPath('openapi-formats.json');
|
|
16
15
|
if (!await fs.stat(formatCache).catch(() => false)) {
|
|
17
16
|
const { stdout } = await ExecUtil.getResult(spawn('docker', ['run', '--rm', dockerImage, 'list'], { shell: false }));
|
|
18
17
|
const lines = stdout
|
|
@@ -2,7 +2,7 @@ import path from 'node:path';
|
|
|
2
2
|
|
|
3
3
|
import { CliCommandShape, CliCommand, CliFlag } from '@travetto/cli';
|
|
4
4
|
import { DockerContainer } from '@travetto/command';
|
|
5
|
-
import { ExecUtil } from '@travetto/
|
|
5
|
+
import { ExecUtil } from '@travetto/runtime';
|
|
6
6
|
|
|
7
7
|
import { OpenApiClientHelp } from './bin/help';
|
|
8
8
|
|
|
@@ -2,14 +2,14 @@ import fs from 'node:fs/promises';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
|
|
4
4
|
import { CliCommandShape, CliCommand } from '@travetto/cli';
|
|
5
|
-
import { Env } from '@travetto/
|
|
5
|
+
import { Env } from '@travetto/runtime';
|
|
6
6
|
import { RootRegistry } from '@travetto/registry';
|
|
7
7
|
import { DependencyRegistry } from '@travetto/di';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* CLI for outputting the open api spec to a local file
|
|
11
11
|
*/
|
|
12
|
-
@CliCommand({
|
|
12
|
+
@CliCommand({ with: { module: true } })
|
|
13
13
|
export class OpenApiSpecCommand implements CliCommandShape {
|
|
14
14
|
|
|
15
15
|
/** Output files */
|