@travetto/openapi 2.2.6 → 3.0.0-rc.2

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@travetto/openapi",
3
3
  "displayName": "OpenAPI Specification",
4
- "version": "2.2.6",
4
+ "version": "3.0.0-rc.2",
5
5
  "description": "OpenAPI integration support for the travetto framework",
6
6
  "keywords": [
7
7
  "rest",
@@ -28,14 +28,19 @@
28
28
  "directory": "module/openapi"
29
29
  },
30
30
  "dependencies": {
31
- "@travetto/config": "^2.2.4",
32
- "@travetto/rest": "^2.2.6",
33
- "@travetto/schema": "^2.2.4",
34
- "@travetto/yaml": "^2.2.4",
31
+ "@travetto/config": "^3.0.0-rc.2",
32
+ "@travetto/rest": "^3.0.0-rc.2",
33
+ "@travetto/schema": "^3.0.0-rc.2",
34
+ "@travetto/yaml": "^3.0.0-rc.0",
35
35
  "openapi3-ts": "^2.0.2"
36
36
  },
37
- "optionalPeerDependencies": {
38
- "@travetto/cli": "^2.2.4"
37
+ "peerDependencies": {
38
+ "@travetto/cli": "^3.0.0-rc.0"
39
+ },
40
+ "peerDependenciesMeta": {
41
+ "@travetto/cli": {
42
+ "optional": true
43
+ }
39
44
  },
40
45
  "publishConfig": {
41
46
  "access": "public"
package/src/service.ts CHANGED
@@ -71,12 +71,16 @@ export class OpenApiService {
71
71
  * Persist to local file
72
72
  */
73
73
  async persist(): Promise<void> {
74
- console.debug('Generating OpenAPI Spec', { output: this.apiSpecConfig.output });
74
+ try {
75
+ console.debug('Generating OpenAPI Spec', { output: this.apiSpecConfig.output });
75
76
 
76
- const output = this.apiSpecConfig.output.endsWith('.json') ?
77
- JSON.stringify(this.spec, undefined, 2) :
78
- YamlUtil.serialize(this.spec);
77
+ const output = this.apiSpecConfig.output.endsWith('.json') ?
78
+ JSON.stringify(this.spec, undefined, 2) :
79
+ YamlUtil.serialize(this.spec);
79
80
 
80
- await fs.writeFile(this.apiSpecConfig.output, output);
81
+ await fs.writeFile(this.apiSpecConfig.output, output);
82
+ } catch (err) {
83
+ console.error('Unable to persist openapi spec', err);
84
+ }
81
85
  }
82
86
  }
@@ -1,7 +1,7 @@
1
1
  import { Readable } from 'stream';
2
- import {
2
+ import type {
3
3
  SchemaObject, SchemasObject, ParameterObject, OperationObject,
4
- RequestBodyObject, TagObject, PathItemObject, OpenAPIObject
4
+ RequestBodyObject, TagObject, PathsObject
5
5
  } from 'openapi3-ts/src/model/OpenApi';
6
6
 
7
7
  import { ControllerRegistry, EndpointConfig, ControllerConfig, ParamConfig, EndpointIOType } from '@travetto/rest';
@@ -18,6 +18,14 @@ function isFieldConfig(val: object): val is FieldConfig {
18
18
  return !!val && 'owner' in val && 'type' in val;
19
19
  }
20
20
 
21
+ type GeneratedSpec = {
22
+ tags: TagObject[];
23
+ paths: PathsObject;
24
+ components: {
25
+ schemas: SchemasObject;
26
+ };
27
+ };
28
+
21
29
  /**
22
30
  * Spec generation utilities
23
31
  */
@@ -25,7 +33,7 @@ export class SpecGenerator {
25
33
  #tags: TagObject[] = [];
26
34
  #allSchemas: SchemasObject = {};
27
35
  #schemas: SchemasObject = {};
28
- #paths: { [key: string]: PathItemObject } = {};
36
+ #paths: PathsObject = {};
29
37
 
30
38
  /**
31
39
  * Get type id
@@ -353,7 +361,7 @@ export class SpecGenerator {
353
361
  /**
354
362
  * Generate full specification
355
363
  */
356
- generate(config: Partial<ApiSpecConfig> = {}): Pick<OpenAPIObject, 'tags' | 'paths' | 'components'> {
364
+ generate(config: Partial<ApiSpecConfig> = {}): GeneratedSpec {
357
365
 
358
366
  for (const cls of ControllerRegistry.getClasses()) {
359
367
  for (const ep of ControllerRegistry.get(cls).endpoints) {