@grandlinex/swagger-mate 1.2.0 → 1.2.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.
@@ -118,17 +118,27 @@ class SwaggerUtil {
118
118
  parameters: route.meta?.parameters,
119
119
  };
120
120
  if (route.meta) {
121
- if (route.meta.requestSchema && !conf.requestBody) {
122
- conf.requestBody = index_js_2.SPathUtil.jsonBody(route.meta.requestSchema);
121
+ // Handle requestBody
122
+ if (!conf.requestBody) {
123
+ if (route.meta.requestSchema) {
124
+ conf.requestBody = index_js_2.SPathUtil.jsonBody(route.meta.requestSchema);
125
+ }
123
126
  }
124
- if (route.meta.responseSchema && !conf.responses) {
127
+ // Handle responses
128
+ if (route.meta.responseSchema) {
125
129
  const ax = route.meta.responseCodes?.slice(1) || [];
126
- conf.responses = index_js_2.SPathUtil.jsonResponse(route.meta.responseCodes?.[0] || '200', route.meta.responseSchema, route.meta.responseType === 'LIST', ...ax);
130
+ if (typeof route.meta.responseSchema === 'string' ||
131
+ (0, core_1.instanceOfEntity)(route.meta.responseSchema)) {
132
+ conf.responses = index_js_2.SPathUtil.refResponse(route.meta.responseCodes?.[0] || '200', route.meta.responseSchema, route.meta.responseType === 'LIST', ...ax);
133
+ }
134
+ else {
135
+ conf.responses = index_js_2.SPathUtil.jsonResponse(route.meta.responseCodes?.[0] || '200', route.meta.responseSchema, route.meta.responseType === 'LIST', ...ax);
136
+ }
127
137
  }
128
138
  else if (route.meta.responseCodes) {
129
139
  conf.responses = index_js_2.SPathUtil.defaultResponse(...route.meta.responseCodes);
130
140
  }
131
- else {
141
+ if (!conf.responses) {
132
142
  conf.responses = index_js_2.SPathUtil.defaultResponse('200');
133
143
  }
134
144
  }
@@ -1,5 +1,5 @@
1
1
  import 'reflect-metadata';
2
- import { ObjectLike } from '@grandlinex/core';
2
+ import { CoreEntity, ObjectLike } from '@grandlinex/core';
3
3
  import { SSchemaEl, SwaggerRPathConf } from '../Meta/SwaggerTypes.js';
4
4
  import { HttpStatusTypes } from '../Meta/SwaggerTypesStatic.js';
5
5
  export declare enum ActionMode {
@@ -13,7 +13,7 @@ export type RouteMeta = {
13
13
  pathOverride?: string;
14
14
  mode?: ActionMode;
15
15
  requestSchema?: SSchemaEl;
16
- responseSchema?: SSchemaEl;
16
+ responseSchema?: SSchemaEl | CoreEntity | string;
17
17
  responseType?: ResponseTypes;
18
18
  responseCodes?: HttpStatusTypes[];
19
19
  } & SwaggerRPathConf;
@@ -22,5 +22,5 @@ export type RouteData = {
22
22
  path: string;
23
23
  meta?: RouteMeta;
24
24
  };
25
- export declare const Route: (type: RouteData["type"], path: RouteData["path"], meta: RouteMeta) => ClassDecorator;
25
+ export declare const Route: (type: RouteData["type"], path: RouteData["path"], meta?: RouteMeta) => ClassDecorator;
26
26
  export declare function getRouteMeta<T extends ObjectLike>(target: T): RouteData | undefined;
@@ -1,7 +1,7 @@
1
1
  import * as Path from 'path';
2
2
  import * as fs from 'fs';
3
3
  import jsyaml from 'js-yaml';
4
- import { CMap } from '@grandlinex/core';
4
+ import { CMap, instanceOfEntity } from '@grandlinex/core';
5
5
  import express from 'express';
6
6
  import * as process from 'process';
7
7
  import { getSComponent, getSPath, getSwaggerMeta } from './Meta/Swagger.js';
@@ -80,17 +80,27 @@ export default class SwaggerUtil {
80
80
  parameters: route.meta?.parameters,
81
81
  };
82
82
  if (route.meta) {
83
- if (route.meta.requestSchema && !conf.requestBody) {
84
- conf.requestBody = SPathUtil.jsonBody(route.meta.requestSchema);
83
+ // Handle requestBody
84
+ if (!conf.requestBody) {
85
+ if (route.meta.requestSchema) {
86
+ conf.requestBody = SPathUtil.jsonBody(route.meta.requestSchema);
87
+ }
85
88
  }
86
- if (route.meta.responseSchema && !conf.responses) {
89
+ // Handle responses
90
+ if (route.meta.responseSchema) {
87
91
  const ax = route.meta.responseCodes?.slice(1) || [];
88
- conf.responses = SPathUtil.jsonResponse(route.meta.responseCodes?.[0] || '200', route.meta.responseSchema, route.meta.responseType === 'LIST', ...ax);
92
+ if (typeof route.meta.responseSchema === 'string' ||
93
+ instanceOfEntity(route.meta.responseSchema)) {
94
+ conf.responses = SPathUtil.refResponse(route.meta.responseCodes?.[0] || '200', route.meta.responseSchema, route.meta.responseType === 'LIST', ...ax);
95
+ }
96
+ else {
97
+ conf.responses = SPathUtil.jsonResponse(route.meta.responseCodes?.[0] || '200', route.meta.responseSchema, route.meta.responseType === 'LIST', ...ax);
98
+ }
89
99
  }
90
100
  else if (route.meta.responseCodes) {
91
101
  conf.responses = SPathUtil.defaultResponse(...route.meta.responseCodes);
92
102
  }
93
- else {
103
+ if (!conf.responses) {
94
104
  conf.responses = SPathUtil.defaultResponse('200');
95
105
  }
96
106
  }
@@ -1,5 +1,5 @@
1
1
  import 'reflect-metadata';
2
- import { ObjectLike } from '@grandlinex/core';
2
+ import { CoreEntity, ObjectLike } from '@grandlinex/core';
3
3
  import { SSchemaEl, SwaggerRPathConf } from '../Meta/SwaggerTypes.js';
4
4
  import { HttpStatusTypes } from '../Meta/SwaggerTypesStatic.js';
5
5
  export declare enum ActionMode {
@@ -13,7 +13,7 @@ export type RouteMeta = {
13
13
  pathOverride?: string;
14
14
  mode?: ActionMode;
15
15
  requestSchema?: SSchemaEl;
16
- responseSchema?: SSchemaEl;
16
+ responseSchema?: SSchemaEl | CoreEntity | string;
17
17
  responseType?: ResponseTypes;
18
18
  responseCodes?: HttpStatusTypes[];
19
19
  } & SwaggerRPathConf;
@@ -22,5 +22,5 @@ export type RouteData = {
22
22
  path: string;
23
23
  meta?: RouteMeta;
24
24
  };
25
- export declare const Route: (type: RouteData["type"], path: RouteData["path"], meta: RouteMeta) => ClassDecorator;
25
+ export declare const Route: (type: RouteData["type"], path: RouteData["path"], meta?: RouteMeta) => ClassDecorator;
26
26
  export declare function getRouteMeta<T extends ObjectLike>(target: T): RouteData | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grandlinex/swagger-mate",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {