@travetto/openapi 3.1.18 → 3.2.0-rc.0

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.18",
3
+ "version": "3.2.0-rc.0",
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": "^3.1.8",
30
- "@travetto/rest": "^3.1.11",
31
- "@travetto/schema": "^3.1.8",
32
- "@travetto/yaml": "^3.1.3",
29
+ "@travetto/config": "^3.2.0-rc.0",
30
+ "@travetto/rest": "^3.2.0-rc.0",
31
+ "@travetto/schema": "^3.2.0-rc.0",
32
+ "@travetto/yaml": "^3.2.0-rc.0",
33
33
  "openapi3-ts": "^3.2.0"
34
34
  },
35
35
  "peerDependencies": {
36
- "@travetto/cli": "^3.1.9",
37
- "@travetto/command": "^3.1.4"
36
+ "@travetto/cli": "^3.2.0-rc.0",
37
+ "@travetto/command": "^3.2.0-rc.0"
38
38
  },
39
39
  "peerDependenciesMeta": {
40
40
  "@travetto/cli": {
package/src/controller.ts CHANGED
@@ -1,34 +1,27 @@
1
- import { Controller, Get, SetHeaders, Undocumented } from '@travetto/rest';
1
+ import { ConfigureInterceptor, Controller, CorsInterceptor, Get, SetHeaders, Undocumented } from '@travetto/rest';
2
2
  import { Inject } from '@travetto/di';
3
3
  import { YamlUtil } from '@travetto/yaml';
4
4
 
5
5
  import { OpenApiService } from './service';
6
6
 
7
- const CORS_HEADERS = {
8
- 'Access-Control-Allow-Origin': '*',
9
- 'Access-Control-Allow-Method': 'GET',
10
- 'Access-Control-Allow-Headers': '*',
11
- 'Access-Control-Allow-Credentials': 'true'
12
- };
13
-
14
7
  /**
15
8
  * Basic controller for surfacing the api spec
16
9
  */
17
10
  @Undocumented()
18
11
  @Controller('/')
12
+ @ConfigureInterceptor(CorsInterceptor, { origins: ['*'] })
19
13
  export class OpenApiController {
20
14
 
21
15
  @Inject()
22
16
  service: OpenApiService;
23
17
 
24
18
  @Get('openapi.json')
25
- @SetHeaders(CORS_HEADERS)
26
19
  async getSpec(): Promise<object> {
27
20
  return this.service.getSpec(); // Force output to be simple
28
21
  }
29
22
 
30
23
  @Get('openapi.yaml')
31
- @SetHeaders({ 'Content-Type': 'text/vnd.yaml', ...CORS_HEADERS })
24
+ @SetHeaders({ 'Content-Type': 'text/vnd.yaml' })
32
25
  async getYmlSpec(): Promise<string> {
33
26
  return YamlUtil.serialize(await this.service.getSpec()); // Force output to be simple
34
27
  }
@@ -291,12 +291,13 @@ export class OpenapiVisitor implements ControllerVisitor<GeneratedSpec> {
291
291
  { parameters: ParameterObject[] } |
292
292
  undefined
293
293
  ) {
294
+ const complex = field.type && SchemaRegistry.has(field.type);
294
295
  if (param.location) {
295
296
  if (param.location === 'body') {
296
297
  return {
297
298
  requestBody: field.specifiers?.includes('file') ? this.#buildUploadBody() : this.#getEndpointBody(field, this.#getHeaderValue(ep, 'accepts'))
298
299
  };
299
- } else if (field.type && SchemaRegistry.has(field.type) && (param.location === 'query' || param.location === 'header')) {
300
+ } else if (complex && (param.location === 'query' || param.location === 'header')) {
300
301
  return { parameters: this.#schemaToDotParams(param.location, field, param.prefix ? `${param.prefix}.` : '') };
301
302
  } else if (param.location !== 'context') {
302
303
  const epParam: ParameterObject = {