@travetto/openapi 4.1.4 → 5.0.0-rc.1
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/LICENSE +1 -1
- package/README.md +4 -3
- package/package.json +7 -7
- package/src/config.ts +4 -3
- package/src/controller.ts +2 -2
- package/src/service.ts +2 -2
- package/src/spec-generate.ts +1 -1
- package/support/bin/help.ts +2 -2
- package/support/cli.openapi_client.ts +2 -1
- package/support/cli.openapi_spec.ts +1 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -24,11 +24,12 @@ All of the high level configurations can be found in the following structure:
|
|
|
24
24
|
|
|
25
25
|
**Code: Config: OpenAPI Configuration**
|
|
26
26
|
```typescript
|
|
27
|
+
import path from 'node:path';
|
|
28
|
+
|
|
27
29
|
import type { ServerObject, ContactObject, LicenseObject } from 'openapi3-ts/oas31';
|
|
28
30
|
|
|
29
31
|
import { Config } from '@travetto/config';
|
|
30
|
-
import {
|
|
31
|
-
import { Env } from '@travetto/base';
|
|
32
|
+
import { Env, RuntimeContext } from '@travetto/base';
|
|
32
33
|
import { Required } from '@travetto/schema';
|
|
33
34
|
|
|
34
35
|
/**
|
|
@@ -97,7 +98,7 @@ export class ApiSpecConfig {
|
|
|
97
98
|
if (!this.output || this.output === '-') {
|
|
98
99
|
this.persist = false;
|
|
99
100
|
} else {
|
|
100
|
-
this.output = path.resolve(
|
|
101
|
+
this.output = path.resolve(RuntimeContext.mainSourcePath, this.output);
|
|
101
102
|
this.persist ??= Env.dynamic;
|
|
102
103
|
}
|
|
103
104
|
if (this.persist) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/openapi",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-rc.1",
|
|
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": "^
|
|
30
|
-
"@travetto/rest": "^
|
|
31
|
-
"@travetto/schema": "^
|
|
32
|
-
"
|
|
29
|
+
"@travetto/config": "^5.0.0-rc.1",
|
|
30
|
+
"@travetto/rest": "^5.0.0-rc.1",
|
|
31
|
+
"@travetto/schema": "^5.0.0-rc.0",
|
|
32
|
+
"yaml": "^2.4.5",
|
|
33
33
|
"openapi3-ts": "^4.3.3"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@travetto/cli": "^
|
|
37
|
-
"@travetto/command": "^
|
|
36
|
+
"@travetto/cli": "^5.0.0-rc.1",
|
|
37
|
+
"@travetto/command": "^5.0.0-rc.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@travetto/cli": {
|
package/src/config.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
1
3
|
import type { ServerObject, ContactObject, LicenseObject } from 'openapi3-ts/oas31';
|
|
2
4
|
|
|
3
5
|
import { Config } from '@travetto/config';
|
|
4
|
-
import {
|
|
5
|
-
import { Env } from '@travetto/base';
|
|
6
|
+
import { Env, RuntimeContext } from '@travetto/base';
|
|
6
7
|
import { Required } from '@travetto/schema';
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -71,7 +72,7 @@ export class ApiSpecConfig {
|
|
|
71
72
|
if (!this.output || this.output === '-') {
|
|
72
73
|
this.persist = false;
|
|
73
74
|
} else {
|
|
74
|
-
this.output = path.resolve(
|
|
75
|
+
this.output = path.resolve(RuntimeContext.mainSourcePath, this.output);
|
|
75
76
|
this.persist ??= Env.dynamic;
|
|
76
77
|
}
|
|
77
78
|
if (this.persist) {
|
package/src/controller.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConfigureInterceptor, Controller, CorsInterceptor, Get, SetHeaders, Undocumented } from '@travetto/rest';
|
|
2
2
|
import { Inject } from '@travetto/di';
|
|
3
|
-
import {
|
|
3
|
+
import { stringify } from 'yaml';
|
|
4
4
|
|
|
5
5
|
import { OpenApiService } from './service';
|
|
6
6
|
|
|
@@ -23,6 +23,6 @@ export class OpenApiController {
|
|
|
23
23
|
@Get('openapi.yaml')
|
|
24
24
|
@SetHeaders({ 'Content-Type': 'text/vnd.yaml' })
|
|
25
25
|
async getYmlSpec(): Promise<string> {
|
|
26
|
-
return
|
|
26
|
+
return stringify(await this.service.getSpec()); // Force output to be simple
|
|
27
27
|
}
|
|
28
28
|
}
|
package/src/service.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Util } from '@travetto/base';
|
|
|
4
4
|
import { Injectable, Inject } from '@travetto/di';
|
|
5
5
|
import { ControllerRegistry, ControllerVisitUtil, RestConfig } from '@travetto/rest';
|
|
6
6
|
import { SchemaRegistry } from '@travetto/schema';
|
|
7
|
-
import {
|
|
7
|
+
import { stringify } from 'yaml';
|
|
8
8
|
|
|
9
9
|
import { ApiHostConfig, ApiInfoConfig, ApiSpecConfig } from './config';
|
|
10
10
|
import { OpenapiVisitor } from './spec-generate';
|
|
@@ -78,7 +78,7 @@ export class OpenApiService {
|
|
|
78
78
|
|
|
79
79
|
const output = this.apiSpecConfig.output.endsWith('.json') ?
|
|
80
80
|
JSON.stringify(spec, undefined, 2) :
|
|
81
|
-
|
|
81
|
+
stringify(spec);
|
|
82
82
|
|
|
83
83
|
await Util.bufferedFileWrite(this.apiSpecConfig.output, output);
|
|
84
84
|
} catch (err) {
|
package/src/spec-generate.ts
CHANGED
|
@@ -321,7 +321,7 @@ export class OpenapiVisitor implements ControllerVisitor<GeneratedSpec> {
|
|
|
321
321
|
|
|
322
322
|
const pConf = this.#getEndpointBody(ep.responseType, this.#getHeaderValue(ep, 'content-type'));
|
|
323
323
|
const code = Object.keys(pConf.content).length ? 200 : 201;
|
|
324
|
-
op.responses[code] = pConf;
|
|
324
|
+
op.responses![code] = pConf;
|
|
325
325
|
|
|
326
326
|
const schema = SchemaRegistry.getMethodSchema(ep.class, ep.handlerName);
|
|
327
327
|
for (const field of schema) {
|
package/support/bin/help.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import { spawn } from 'node:child_process';
|
|
3
|
+
import path from 'node:path';
|
|
3
4
|
|
|
4
|
-
import { ExecUtil } from '@travetto/base';
|
|
5
|
-
import { path, RuntimeContext } from '@travetto/manifest';
|
|
5
|
+
import { ExecUtil, RuntimeContext } from '@travetto/base';
|
|
6
6
|
import { cliTpl } from '@travetto/cli';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
2
3
|
|
|
3
4
|
import { CliCommandShape, CliCommand } from '@travetto/cli';
|
|
4
5
|
import { Env } from '@travetto/base';
|
|
5
6
|
import { RootRegistry } from '@travetto/registry';
|
|
6
7
|
import { DependencyRegistry } from '@travetto/di';
|
|
7
|
-
import { path } from '@travetto/manifest';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* CLI for outputting the open api spec to a local file
|