@travetto/openapi 3.1.3 → 3.1.5
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 +5 -6
- package/package.json +5 -5
- package/src/controller.ts +2 -1
- package/src/spec-generate.ts +36 -21
package/README.md
CHANGED
|
@@ -69,7 +69,7 @@ export class ApiHostConfig {
|
|
|
69
69
|
/**
|
|
70
70
|
* OpenAPI Version
|
|
71
71
|
*/
|
|
72
|
-
openapi = '3.
|
|
72
|
+
openapi = '3.0.0';
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/**
|
|
@@ -95,10 +95,10 @@ export class ApiSpecConfig {
|
|
|
95
95
|
exposeAllSchemas: boolean = false;
|
|
96
96
|
|
|
97
97
|
async postConstruct(): Promise<void> {
|
|
98
|
-
this.output = path.resolve(this.output);
|
|
99
98
|
if (!this.output || this.output === '-') {
|
|
100
99
|
this.persist = false;
|
|
101
100
|
} else {
|
|
101
|
+
this.output = path.resolve(RootIndex.mainModule.sourcePath, this.output);
|
|
102
102
|
this.persist ??= GlobalEnv.dynamic;
|
|
103
103
|
}
|
|
104
104
|
if (this.persist) {
|
|
@@ -152,10 +152,9 @@ Options:
|
|
|
152
152
|
|
|
153
153
|
Available Presets
|
|
154
154
|
----------------------------------
|
|
155
|
-
* @travetto/
|
|
156
|
-
* @travetto/
|
|
157
|
-
* @travetto/
|
|
158
|
-
* @travetto/fetch -- typescript-fetch
|
|
155
|
+
* @travetto/angular14 -- typescript-angular supportsES6=true,stringEnums=true,ngVersion=14.0,fileNaming=kebab-case
|
|
156
|
+
* @travetto/angular15 -- typescript-angular supportsES6=true,stringEnums=true,ngVersion=15.0,fileNaming=kebab-case
|
|
157
|
+
* @travetto/fetch -- typescript-fetch stringEnums=true
|
|
159
158
|
```
|
|
160
159
|
|
|
161
160
|
This tool relies upon a custom build of [OpenAPI client generation tools](https://github.com/OpenAPITools/openapi-generator), which supports watching. This allows for fast responsive client generation as the shape of the API changes.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/openapi",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.5",
|
|
4
4
|
"description": "OpenAPI integration support for the Travetto framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rest",
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
"directory": "module/openapi"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@travetto/config": "^3.1.
|
|
30
|
-
"@travetto/rest": "^3.1.
|
|
31
|
-
"@travetto/schema": "^3.1.
|
|
29
|
+
"@travetto/config": "^3.1.2",
|
|
30
|
+
"@travetto/rest": "^3.1.3",
|
|
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.
|
|
36
|
+
"@travetto/cli": "^3.1.2"
|
|
37
37
|
},
|
|
38
38
|
"peerDependenciesMeta": {
|
|
39
39
|
"@travetto/cli": {
|
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
|
@@ -5,12 +5,12 @@ import type {
|
|
|
5
5
|
} from 'openapi3-ts';
|
|
6
6
|
|
|
7
7
|
import { ControllerRegistry, EndpointConfig, ControllerConfig, ParamConfig, EndpointIOType } from '@travetto/rest';
|
|
8
|
+
import { RootIndex } from '@travetto/manifest';
|
|
8
9
|
import { Class } from '@travetto/base';
|
|
9
10
|
import { SchemaRegistry, FieldConfig } from '@travetto/schema';
|
|
10
11
|
import { AllViewⲐ } from '@travetto/schema/src/internal/types';
|
|
11
12
|
|
|
12
13
|
import { ApiSpecConfig } from './config';
|
|
13
|
-
import { OpenApiController } from './controller';
|
|
14
14
|
|
|
15
15
|
const DEFINITION = '#/components/schemas';
|
|
16
16
|
|
|
@@ -224,9 +224,21 @@ export class SpecGenerator {
|
|
|
224
224
|
properties[fieldName] = this.#processSchemaField(def.schema[fieldName], required);
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
+
const extra: Record<string, unknown> = {};
|
|
228
|
+
if (RootIndex.getFunctionMetadata(type)?.abstract) {
|
|
229
|
+
const map = SchemaRegistry.getSubTypesForClass(type);
|
|
230
|
+
if (map) {
|
|
231
|
+
extra.oneOf = [...new Set(map.values())].map(c => {
|
|
232
|
+
this.#processSchema(c);
|
|
233
|
+
return this.#getType(c);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
227
238
|
Object.assign(this.#allSchemas[typeId], {
|
|
228
239
|
properties,
|
|
229
|
-
...(required.length ? { required } : {})
|
|
240
|
+
...(required.length ? { required } : {}),
|
|
241
|
+
...extra
|
|
230
242
|
});
|
|
231
243
|
} else {
|
|
232
244
|
this.#allSchemas[typeId] = { title: typeId };
|
|
@@ -341,29 +353,20 @@ export class SpecGenerator {
|
|
|
341
353
|
};
|
|
342
354
|
}
|
|
343
355
|
|
|
344
|
-
/**
|
|
345
|
-
* Process each controller
|
|
346
|
-
*/
|
|
347
|
-
processController(cls: Class): void {
|
|
348
|
-
const ctrl = ControllerRegistry.get(cls);
|
|
349
|
-
|
|
350
|
-
this.#tags.push({
|
|
351
|
-
name: this.#getTypeTag(ctrl.class),
|
|
352
|
-
description: ctrl.description || ctrl.title
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
for (const ep of ctrl.endpoints) {
|
|
356
|
-
this.processEndpoint(ctrl, ep);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
|
|
360
356
|
/**
|
|
361
357
|
* Generate full specification
|
|
362
358
|
*/
|
|
363
359
|
generate(config: Partial<ApiSpecConfig> = {}): GeneratedSpec {
|
|
364
360
|
|
|
365
361
|
for (const cls of ControllerRegistry.getClasses()) {
|
|
366
|
-
|
|
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
|
+
}
|
|
367
370
|
if (ep.requestType) {
|
|
368
371
|
this.#processSchema(ep.requestType.type);
|
|
369
372
|
}
|
|
@@ -378,8 +381,20 @@ export class SpecGenerator {
|
|
|
378
381
|
|
|
379
382
|
if (!config.skipRoutes) {
|
|
380
383
|
for (const cls of ControllerRegistry.getClasses()) {
|
|
381
|
-
|
|
382
|
-
|
|
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);
|
|
383
398
|
}
|
|
384
399
|
}
|
|
385
400
|
}
|