@rvoh/psychic 1.8.4 → 1.8.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/CHANGELOG.md +279 -0
- package/dist/cjs/src/openapi-renderer/app.js +44 -35
- package/dist/cjs/src/psychic-app/openapi-cache.js +5 -1
- package/dist/esm/src/openapi-renderer/app.js +44 -35
- package/dist/esm/src/psychic-app/openapi-cache.js +4 -1
- package/dist/types/src/openapi-renderer/app.d.ts +3 -1
- package/dist/types/src/psychic-app/openapi-cache.d.ts +1 -0
- package/package.json +2 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
## 1.8.5
|
|
2
|
+
|
|
3
|
+
Do not hard crash when initializing a psychic application when one of the openapi routes is not found for an openapi-decorated controller endpoint. We will continue to raise this exception when building openapi specs, but not when booting up the psychic application, since one can define routes that are i.e. not available in certain environments, and we don't want this to cause hard crashes when our app boots in those environments.
|
|
4
|
+
|
|
5
|
+
## 1.8.4
|
|
6
|
+
|
|
7
|
+
- OpenAPI decorator with default 204 status does not throw an exception when passed a Dream model without a `serializers` getter
|
|
8
|
+
- OpenAPI decorator that defines an explicit OpenAPI shape for the default status code does not throw an exception when passed a Dream model without a `serializers` getter
|
|
9
|
+
|
|
10
|
+
## 1.8.3
|
|
11
|
+
|
|
12
|
+
- don't build openapi when `bypassModelIntegrityCheck: true`
|
|
13
|
+
|
|
14
|
+
## 1.8.2
|
|
15
|
+
|
|
16
|
+
- openapi validation properly coerces non-array query params to arrays when validating, since both express and ajv fail to do this under the hood properly. This solves issues where sending up array params with only a single item in them are not treated as arrays.
|
|
17
|
+
|
|
18
|
+
## 1.8.1
|
|
19
|
+
|
|
20
|
+
- do not coerce types in ajv when processing request or response bodies during validation. Type coercion will still happen for headers and query params, since they will need to respect the schema type specified in the openapi docuement.
|
|
21
|
+
|
|
22
|
+
## 1.8.0
|
|
23
|
+
|
|
24
|
+
- remove unused `clientRoot` config
|
|
25
|
+
|
|
26
|
+
## 1.7.2
|
|
27
|
+
|
|
28
|
+
- generate admin routes in routes.admin.ts (requires `routes.admin.ts` next to `routes.ts`)
|
|
29
|
+
|
|
30
|
+
## 1.7.1
|
|
31
|
+
|
|
32
|
+
- compute openapi doc during intiialization, rather than problematically reading from a file cache
|
|
33
|
+
|
|
34
|
+
## 1.7.0
|
|
35
|
+
|
|
36
|
+
- `sanitizeResponseJson` config to automatically escape `<`, `>`, `&`, `/`, `\`, `'`, and `"` unicode representations when rendering json to satisfy security reviews (e.g., a pentest report recently called this out on one of our applications). For all practical purposes, this doesn't protect against anything (now that we have the `nosniff` header) since `JSON.parse` on the other end restores the original, dangerous string. Modern front end web frameworks already handle safely displaying arbitrary content, so further sanitization generally isn't needed. This version does provide the `sanitizeString` function that could be used to sanitize individual strings, replacing the above characters with string representations of the unicode characters that will survive Psychic converting to json and then parsing that json (i.e.: `<` will end up as the string "\u003c")
|
|
37
|
+
|
|
38
|
+
- Fix openapi serializer fallback issue introduced in 1.6.3, where we mistakenly double render data that has already been serialized.
|
|
39
|
+
|
|
40
|
+
## 1.6.4
|
|
41
|
+
|
|
42
|
+
Raise an exception if attempting to import an openapi file during PsychicApp.init when in production. We will still swallow the exception in non-prod environments so that one can create a new openapi configuration and run sync without getting an error.
|
|
43
|
+
|
|
44
|
+
## 1.6.3
|
|
45
|
+
|
|
46
|
+
- castParam accepts raw openapi shapes as type arguments, correctly casting the result to an interface representing the provided openapi shape.
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
class MyController extends ApplicationController {
|
|
50
|
+
public index() {
|
|
51
|
+
const myParam = this.castParam('myParam', {
|
|
52
|
+
type: 'array',
|
|
53
|
+
items: {
|
|
54
|
+
anyOf: [{ type: 'string' }, { type: 'number' }],
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
myParam[0] // string | number
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
- simplify the needlessly-robust new psychic router patterns by making expressApp optional, essentially reverting us back to the same psychic router we had prior to the recent openapi validation changes.
|
|
63
|
+
|
|
64
|
+
- fallback to serializer specified in openapi decorator before falling back to dream serializer when rendering dreams
|
|
65
|
+
|
|
66
|
+
## 1.6.2
|
|
67
|
+
|
|
68
|
+
fix OpenAPI spec generation by DRYing up generation of request and response body
|
|
69
|
+
|
|
70
|
+
## 1.6.1
|
|
71
|
+
|
|
72
|
+
fix issue preventing validation fallbacks from properly overriding on OpenAPI decorator calls when explicitly opting out of validation
|
|
73
|
+
|
|
74
|
+
## 1.6.0
|
|
75
|
+
|
|
76
|
+
enables validation to be added to both openapi configurations, as well as to `OpenAPI` decorator calls, enabling the developer to granularly control validation logic for their endpoints.
|
|
77
|
+
|
|
78
|
+
To leverage global config:
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
// conf/app.ts
|
|
82
|
+
export default async (psy: PsychicApp) => {
|
|
83
|
+
...
|
|
84
|
+
|
|
85
|
+
psy.set('openapi', {
|
|
86
|
+
// ...
|
|
87
|
+
validate: {
|
|
88
|
+
headers: true,
|
|
89
|
+
requestBody: true,
|
|
90
|
+
query: true,
|
|
91
|
+
responseBody: AppEnv.isTest,
|
|
92
|
+
},
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
To leverage endpoint config:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
// controllers/PetsController
|
|
101
|
+
export default class PetsController {
|
|
102
|
+
@OpenAPI(Pet, {
|
|
103
|
+
...
|
|
104
|
+
validate: {
|
|
105
|
+
headers: true,
|
|
106
|
+
requestBody: true,
|
|
107
|
+
query: true,
|
|
108
|
+
responseBody: AppEnv.isTest,
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
public async index() {
|
|
112
|
+
...
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
This PR additionally formally introduces a new possible error type for 400 status codes, and to help distinguish, it also introduces a `type` field, which can be either `openapi` or `dream` to aid the developer in easily handling the various cases.
|
|
118
|
+
|
|
119
|
+
We have made a conscious decision to render openapi errors in the exact format that ajv returns, since it empowers the developer to utilize tools which can already respond to ajv errors.
|
|
120
|
+
|
|
121
|
+
For added flexibility, this PR includes the ability to provide configuration overrides for the ajv instance, as well as the ability to provide an initialization function to override ajv behavior, since much of the configuration for ajv is driven by method calls, rather than simple config.
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
// controllers/PetsController
|
|
125
|
+
export default class PetsController {
|
|
126
|
+
@OpenAPI(Pet, {
|
|
127
|
+
...
|
|
128
|
+
validate: {
|
|
129
|
+
ajvOptions: {
|
|
130
|
+
// this is off by default, but you will
|
|
131
|
+
// always want to keep this off in prod
|
|
132
|
+
// to avoid DoS vulnerabilities
|
|
133
|
+
allErrors: AppEnv.isTest,
|
|
134
|
+
|
|
135
|
+
// provide a custom init function to further
|
|
136
|
+
// configure your ajv instance before validating
|
|
137
|
+
init: ajv => {
|
|
138
|
+
ajv.addFormat('myFormat', {
|
|
139
|
+
type: 'string',
|
|
140
|
+
validate: data => MY_FORMAT_REGEX.test(data),
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
public async index() {
|
|
147
|
+
...
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## 1.5.5
|
|
153
|
+
|
|
154
|
+
- ensure that openapi-typescript and typescript are not required dependencies when running migrations with --skip-sync flag
|
|
155
|
+
|
|
156
|
+
## 1.5.4
|
|
157
|
+
|
|
158
|
+
- fix issue when providing the `including` argument exclusively to an OpenAPI decorator's `requestBody`
|
|
159
|
+
|
|
160
|
+
## 1.5.3
|
|
161
|
+
|
|
162
|
+
- add missing peer dependency for openapi-typescript, allow BIGINT type when generating openapi-typescript bigints
|
|
163
|
+
|
|
164
|
+
## 1.5.2
|
|
165
|
+
|
|
166
|
+
- ensure that bigints are converted to number | string when generating openapi-typescript type files
|
|
167
|
+
|
|
168
|
+
## 1.5.1
|
|
169
|
+
|
|
170
|
+
- fix issue with enum syncing related to multi-db engine support regression
|
|
171
|
+
|
|
172
|
+
## 1.5.0
|
|
173
|
+
|
|
174
|
+
- add support for multiple database engines in dream
|
|
175
|
+
|
|
176
|
+
## 1.2.3
|
|
177
|
+
|
|
178
|
+
- add support for the connectionName argument when generating a resource
|
|
179
|
+
|
|
180
|
+
## 1.2.2
|
|
181
|
+
|
|
182
|
+
- bump supertest and express-session to close dependabot issues [53](https://github.com/rvohealth/psychic/security/dependabot/53), [56](https://github.com/rvohealth/psychic/security/dependabot/56), and [57](https://github.com/rvohealth/psychic/security/dependabot/57)
|
|
183
|
+
|
|
184
|
+
## 1.2.1
|
|
185
|
+
|
|
186
|
+
- add ability to set custom import extension, which will be used when generating new files for your application
|
|
187
|
+
|
|
188
|
+
## 1.2.0
|
|
189
|
+
|
|
190
|
+
- update for Dream 1.4.0
|
|
191
|
+
|
|
192
|
+
## 1.1.11
|
|
193
|
+
|
|
194
|
+
- 400 is more appropriate than 422 for `DataTypeColumnTypeMismatch`
|
|
195
|
+
|
|
196
|
+
## 1.1.10
|
|
197
|
+
|
|
198
|
+
- Don't include deletedAt in generated create/update actions in resource specs since deletedAt is for deleting
|
|
199
|
+
|
|
200
|
+
- return 422 if Dream throws `NotNullViolation` or `CheckConstraintViolation`
|
|
201
|
+
|
|
202
|
+
## 1.1.9
|
|
203
|
+
|
|
204
|
+
- return 422 if dream throws `DataTypeColumnTypeMismatch`, which happens when a dream is saved to the database with data that cannot be inserted into the respective columns, usually because of a type mismatch.
|
|
205
|
+
|
|
206
|
+
- castParam will now encase params in an array when being explicitly casted as an array type, bypassing a known bug in express from causing arrays with single items in them to be treated as non-arrays.
|
|
207
|
+
|
|
208
|
+
## 1.1.8
|
|
209
|
+
|
|
210
|
+
- Tap into CliFileWriter provided by dream to tap into file reversion for sync files, since the auto-sync function in psychic can fail and leave your file tree in a bad state.
|
|
211
|
+
|
|
212
|
+
## 1.1.7
|
|
213
|
+
|
|
214
|
+
- Add support for middleware arrays, enabling express plugins like passport
|
|
215
|
+
|
|
216
|
+
## 1.1.6
|
|
217
|
+
|
|
218
|
+
- fix regression caused by missing --schema-only option in psychic cli
|
|
219
|
+
|
|
220
|
+
## 1.1.5
|
|
221
|
+
|
|
222
|
+
- pass packageManager through to dream, now that it accepts a packageManager setting.
|
|
223
|
+
- update dream shadowing within psychic application initialization to take place after initializers and plugins are processed, so that those initializers and plugins have an opportunity to adjust the settings.
|
|
224
|
+
|
|
225
|
+
## 1.1.4
|
|
226
|
+
|
|
227
|
+
- fix regressions to redux bindings caused by default openapi path location changes
|
|
228
|
+
- resource generator can handle prefixing slashes
|
|
229
|
+
|
|
230
|
+
## 1.1.3
|
|
231
|
+
|
|
232
|
+
- fix more minor issues with redux openapi bindings
|
|
233
|
+
|
|
234
|
+
## 1.1.2
|
|
235
|
+
|
|
236
|
+
- Fix various issues with openapi redux bindings
|
|
237
|
+
- raise hard exception if accidentally using openapi route params in an expressjs route path
|
|
238
|
+
|
|
239
|
+
## 1.1.1
|
|
240
|
+
|
|
241
|
+
Fix route printing regression causing route printouts to show the path instead of the action
|
|
242
|
+
|
|
243
|
+
## v1.1.0
|
|
244
|
+
|
|
245
|
+
Provides easier access to express middleware by exposing `PsychicApp#use`, which enables a developer to provide express middleware directly through the psychcic application, without tapping into any hooks.
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
psy.use((_, res) => {
|
|
249
|
+
res.send(
|
|
250
|
+
'this will be run after psychic middleware (i.e. cors and bodyParser) are processed, but before routes are processed',
|
|
251
|
+
)
|
|
252
|
+
})
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Some middleware needs to be run before other middleware, so we expose an optional first argument which can be provided so explicitly send your middleware into express at various stages of the psychic configuration process. For example, to inject your middleware before cors and bodyParser are configured, provide `before-middleware` as the first argument. To initialize your middleware after the psychic default middleware, but before your routes have been processed, provide `after-middleware` as the first argument (or simply provide a callback function directly, since this is the default). To run after routes have been processed, provide `after-routes` as the first argument.
|
|
256
|
+
|
|
257
|
+
```ts
|
|
258
|
+
psy.use('before-middleware', (_, res) => {
|
|
259
|
+
res.send('this will be run before psychic has configured any default middleware')
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
psy.use('after-middleware', (_, res) => {
|
|
263
|
+
res.send('this will be run after psychic has configured default middleware')
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
psy.use('after-routes', (_, res) => {
|
|
267
|
+
res.send('this will be run after psychic has processed all the routes in your conf/routes.ts file')
|
|
268
|
+
})
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
Additionally, a new overload has been added to all CRUD methods on the PsychicRouter class, enabling you to provide RequestHandler middleware directly to psychic, like so:
|
|
272
|
+
|
|
273
|
+
```ts
|
|
274
|
+
// conf/routes.ts
|
|
275
|
+
|
|
276
|
+
r.get('helloworld', (req, res, next) => {
|
|
277
|
+
res.json({ hello: 'world' })
|
|
278
|
+
})
|
|
279
|
+
```
|
|
@@ -10,6 +10,7 @@ const openapiJsonPath_js_1 = __importDefault(require("../helpers/openapiJsonPath
|
|
|
10
10
|
const index_js_1 = __importDefault(require("../psychic-app/index.js"));
|
|
11
11
|
const types_js_1 = require("../router/types.js");
|
|
12
12
|
const defaults_js_1 = require("./defaults.js");
|
|
13
|
+
const endpoint_js_1 = require("./endpoint.js");
|
|
13
14
|
const suppressResponseEnumsConfig_js_1 = __importDefault(require("./helpers/suppressResponseEnumsConfig.js"));
|
|
14
15
|
const debugEnabled = (0, node_util_1.debuglog)('psychic').enabled;
|
|
15
16
|
class OpenapiAppRenderer {
|
|
@@ -46,7 +47,7 @@ class OpenapiAppRenderer {
|
|
|
46
47
|
});
|
|
47
48
|
return output;
|
|
48
49
|
}
|
|
49
|
-
static _toObject(routes, openapiName) {
|
|
50
|
+
static _toObject(routes, openapiName, { bypassMissingRoutes = false } = {}) {
|
|
50
51
|
const renderOpts = {
|
|
51
52
|
casing: 'camel',
|
|
52
53
|
suppressResponseEnums: (0, suppressResponseEnumsConfig_js_1.default)(openapiName),
|
|
@@ -97,41 +98,49 @@ class OpenapiAppRenderer {
|
|
|
97
98
|
const renderer = controller.openapi[key];
|
|
98
99
|
if (renderer === undefined)
|
|
99
100
|
throw new UnexpectedUndefined_js_1.default();
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
finalOutput.paths[path]
|
|
101
|
+
try {
|
|
102
|
+
const endpointPayloadAndReferencedSerializers = renderer.toPathObject(routes, {
|
|
103
|
+
openapiName,
|
|
104
|
+
renderOpts,
|
|
105
|
+
});
|
|
106
|
+
const serializersAppearingInHandWrittenOpenapi = endpointPayloadAndReferencedSerializers.referencedSerializers;
|
|
107
|
+
const endpointPayload = endpointPayloadAndReferencedSerializers.openapi;
|
|
108
|
+
if (endpointPayload === undefined)
|
|
109
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
110
|
+
const path = Object.keys(endpointPayload)[0];
|
|
111
|
+
if (path === undefined)
|
|
112
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
113
|
+
const endpointPayloadPath = endpointPayload[path];
|
|
114
|
+
if (endpointPayloadPath === undefined)
|
|
115
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
116
|
+
const method = Object.keys(endpointPayloadPath).find(key => types_js_1.HttpMethods.includes(key));
|
|
117
|
+
if (!finalOutput.paths[path]) {
|
|
118
|
+
finalOutput.paths[path] = { parameters: [] };
|
|
119
|
+
}
|
|
120
|
+
const finalPathObject = finalOutput.paths[path];
|
|
121
|
+
finalPathObject[method] = endpointPayloadPath[method];
|
|
122
|
+
finalPathObject.parameters = this.combineParameters([
|
|
123
|
+
...finalPathObject.parameters,
|
|
124
|
+
...endpointPayloadPath.parameters,
|
|
125
|
+
]);
|
|
126
|
+
renderer.toSchemaObject({
|
|
127
|
+
openapiName,
|
|
128
|
+
renderOpts,
|
|
129
|
+
renderedSchemasOpenapi,
|
|
130
|
+
alreadyExtractedDescendantSerializers,
|
|
131
|
+
serializersAppearingInHandWrittenOpenapi,
|
|
132
|
+
});
|
|
133
|
+
finalOutput.components.schemas = {
|
|
134
|
+
...finalOutput.components.schemas,
|
|
135
|
+
...renderedSchemasOpenapi,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
if (err instanceof endpoint_js_1.MissingControllerActionPairingInRoutes && bypassMissingRoutes) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
throw err;
|
|
117
143
|
}
|
|
118
|
-
const finalPathObject = finalOutput.paths[path];
|
|
119
|
-
finalPathObject[method] = endpointPayloadPath[method];
|
|
120
|
-
finalPathObject.parameters = this.combineParameters([
|
|
121
|
-
...finalPathObject.parameters,
|
|
122
|
-
...endpointPayloadPath.parameters,
|
|
123
|
-
]);
|
|
124
|
-
renderer.toSchemaObject({
|
|
125
|
-
openapiName,
|
|
126
|
-
renderOpts,
|
|
127
|
-
renderedSchemasOpenapi,
|
|
128
|
-
alreadyExtractedDescendantSerializers,
|
|
129
|
-
serializersAppearingInHandWrittenOpenapi,
|
|
130
|
-
});
|
|
131
|
-
finalOutput.components.schemas = {
|
|
132
|
-
...finalOutput.components.schemas,
|
|
133
|
-
...renderedSchemasOpenapi,
|
|
134
|
-
};
|
|
135
144
|
}
|
|
136
145
|
}
|
|
137
146
|
const components = finalOutput.components;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getCachedOpenapiDocOrFail = getCachedOpenapiDocOrFail;
|
|
7
7
|
exports.cacheOpenapiDoc = cacheOpenapiDoc;
|
|
8
8
|
exports.ignoreOpenapiDoc = ignoreOpenapiDoc;
|
|
9
|
+
exports._testOnlyClearOpenapiCache = _testOnlyClearOpenapiCache;
|
|
9
10
|
const must_call_psychic_app_init_first_js_1 = __importDefault(require("../error/psychic-app/must-call-psychic-app-init-first.js"));
|
|
10
11
|
const app_js_1 = __importDefault(require("../openapi-renderer/app.js"));
|
|
11
12
|
const _openapiData = {};
|
|
@@ -36,7 +37,7 @@ function getCachedOpenapiDocOrFail(openapiName) {
|
|
|
36
37
|
function cacheOpenapiDoc(openapiName, routes) {
|
|
37
38
|
if (_openapiData[openapiName])
|
|
38
39
|
return;
|
|
39
|
-
const openapiDoc = app_js_1.default._toObject(routes, openapiName);
|
|
40
|
+
const openapiDoc = app_js_1.default._toObject(routes, openapiName, { bypassMissingRoutes: true });
|
|
40
41
|
_openapiData[openapiName] = openapiDoc?.components
|
|
41
42
|
? { components: openapiDoc.components }
|
|
42
43
|
: FILE_DOES_NOT_EXIST;
|
|
@@ -53,5 +54,8 @@ function cacheOpenapiDoc(openapiName, routes) {
|
|
|
53
54
|
function ignoreOpenapiDoc(openapiName) {
|
|
54
55
|
_openapiData[openapiName] = FILE_WAS_IGNORED;
|
|
55
56
|
}
|
|
57
|
+
function _testOnlyClearOpenapiCache(openapiName) {
|
|
58
|
+
_openapiData[openapiName] = undefined;
|
|
59
|
+
}
|
|
56
60
|
const FILE_DOES_NOT_EXIST = 'FILE_DOES_NOT_EXIST';
|
|
57
61
|
const FILE_WAS_IGNORED = 'FILE_WAS_IGNORED';
|
|
@@ -5,6 +5,7 @@ import openapiJsonPath from '../helpers/openapiJsonPath.js';
|
|
|
5
5
|
import PsychicApp from '../psychic-app/index.js';
|
|
6
6
|
import { HttpMethods } from '../router/types.js';
|
|
7
7
|
import { DEFAULT_OPENAPI_COMPONENT_RESPONSES, DEFAULT_OPENAPI_COMPONENT_SCHEMAS } from './defaults.js';
|
|
8
|
+
import { MissingControllerActionPairingInRoutes, } from './endpoint.js';
|
|
8
9
|
import suppressResponseEnumsConfig from './helpers/suppressResponseEnumsConfig.js';
|
|
9
10
|
const debugEnabled = debuglog('psychic').enabled;
|
|
10
11
|
export default class OpenapiAppRenderer {
|
|
@@ -41,7 +42,7 @@ export default class OpenapiAppRenderer {
|
|
|
41
42
|
});
|
|
42
43
|
return output;
|
|
43
44
|
}
|
|
44
|
-
static _toObject(routes, openapiName) {
|
|
45
|
+
static _toObject(routes, openapiName, { bypassMissingRoutes = false } = {}) {
|
|
45
46
|
const renderOpts = {
|
|
46
47
|
casing: 'camel',
|
|
47
48
|
suppressResponseEnums: suppressResponseEnumsConfig(openapiName),
|
|
@@ -92,41 +93,49 @@ export default class OpenapiAppRenderer {
|
|
|
92
93
|
const renderer = controller.openapi[key];
|
|
93
94
|
if (renderer === undefined)
|
|
94
95
|
throw new UnexpectedUndefined();
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
finalOutput.paths[path]
|
|
96
|
+
try {
|
|
97
|
+
const endpointPayloadAndReferencedSerializers = renderer.toPathObject(routes, {
|
|
98
|
+
openapiName,
|
|
99
|
+
renderOpts,
|
|
100
|
+
});
|
|
101
|
+
const serializersAppearingInHandWrittenOpenapi = endpointPayloadAndReferencedSerializers.referencedSerializers;
|
|
102
|
+
const endpointPayload = endpointPayloadAndReferencedSerializers.openapi;
|
|
103
|
+
if (endpointPayload === undefined)
|
|
104
|
+
throw new UnexpectedUndefined();
|
|
105
|
+
const path = Object.keys(endpointPayload)[0];
|
|
106
|
+
if (path === undefined)
|
|
107
|
+
throw new UnexpectedUndefined();
|
|
108
|
+
const endpointPayloadPath = endpointPayload[path];
|
|
109
|
+
if (endpointPayloadPath === undefined)
|
|
110
|
+
throw new UnexpectedUndefined();
|
|
111
|
+
const method = Object.keys(endpointPayloadPath).find(key => HttpMethods.includes(key));
|
|
112
|
+
if (!finalOutput.paths[path]) {
|
|
113
|
+
finalOutput.paths[path] = { parameters: [] };
|
|
114
|
+
}
|
|
115
|
+
const finalPathObject = finalOutput.paths[path];
|
|
116
|
+
finalPathObject[method] = endpointPayloadPath[method];
|
|
117
|
+
finalPathObject.parameters = this.combineParameters([
|
|
118
|
+
...finalPathObject.parameters,
|
|
119
|
+
...endpointPayloadPath.parameters,
|
|
120
|
+
]);
|
|
121
|
+
renderer.toSchemaObject({
|
|
122
|
+
openapiName,
|
|
123
|
+
renderOpts,
|
|
124
|
+
renderedSchemasOpenapi,
|
|
125
|
+
alreadyExtractedDescendantSerializers,
|
|
126
|
+
serializersAppearingInHandWrittenOpenapi,
|
|
127
|
+
});
|
|
128
|
+
finalOutput.components.schemas = {
|
|
129
|
+
...finalOutput.components.schemas,
|
|
130
|
+
...renderedSchemasOpenapi,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
if (err instanceof MissingControllerActionPairingInRoutes && bypassMissingRoutes) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
throw err;
|
|
112
138
|
}
|
|
113
|
-
const finalPathObject = finalOutput.paths[path];
|
|
114
|
-
finalPathObject[method] = endpointPayloadPath[method];
|
|
115
|
-
finalPathObject.parameters = this.combineParameters([
|
|
116
|
-
...finalPathObject.parameters,
|
|
117
|
-
...endpointPayloadPath.parameters,
|
|
118
|
-
]);
|
|
119
|
-
renderer.toSchemaObject({
|
|
120
|
-
openapiName,
|
|
121
|
-
renderOpts,
|
|
122
|
-
renderedSchemasOpenapi,
|
|
123
|
-
alreadyExtractedDescendantSerializers,
|
|
124
|
-
serializersAppearingInHandWrittenOpenapi,
|
|
125
|
-
});
|
|
126
|
-
finalOutput.components.schemas = {
|
|
127
|
-
...finalOutput.components.schemas,
|
|
128
|
-
...renderedSchemasOpenapi,
|
|
129
|
-
};
|
|
130
139
|
}
|
|
131
140
|
}
|
|
132
141
|
const components = finalOutput.components;
|
|
@@ -28,7 +28,7 @@ export function getCachedOpenapiDocOrFail(openapiName) {
|
|
|
28
28
|
export function cacheOpenapiDoc(openapiName, routes) {
|
|
29
29
|
if (_openapiData[openapiName])
|
|
30
30
|
return;
|
|
31
|
-
const openapiDoc = OpenapiAppRenderer._toObject(routes, openapiName);
|
|
31
|
+
const openapiDoc = OpenapiAppRenderer._toObject(routes, openapiName, { bypassMissingRoutes: true });
|
|
32
32
|
_openapiData[openapiName] = openapiDoc?.components
|
|
33
33
|
? { components: openapiDoc.components }
|
|
34
34
|
: FILE_DOES_NOT_EXIST;
|
|
@@ -45,5 +45,8 @@ export function cacheOpenapiDoc(openapiName, routes) {
|
|
|
45
45
|
export function ignoreOpenapiDoc(openapiName) {
|
|
46
46
|
_openapiData[openapiName] = FILE_WAS_IGNORED;
|
|
47
47
|
}
|
|
48
|
+
export function _testOnlyClearOpenapiCache(openapiName) {
|
|
49
|
+
_openapiData[openapiName] = undefined;
|
|
50
|
+
}
|
|
48
51
|
const FILE_DOES_NOT_EXIST = 'FILE_DOES_NOT_EXIST';
|
|
49
52
|
const FILE_WAS_IGNORED = 'FILE_WAS_IGNORED';
|
|
@@ -16,6 +16,8 @@ export default class OpenapiAppRenderer {
|
|
|
16
16
|
* the controller layer.
|
|
17
17
|
*/
|
|
18
18
|
static toObject(): Record<string, OpenapiSchema>;
|
|
19
|
-
static _toObject(routes: RouteConfig[], openapiName: string
|
|
19
|
+
static _toObject(routes: RouteConfig[], openapiName: string, { bypassMissingRoutes }?: {
|
|
20
|
+
bypassMissingRoutes?: boolean;
|
|
21
|
+
}): OpenapiSchema;
|
|
20
22
|
private static combineParameters;
|
|
21
23
|
}
|
|
@@ -37,3 +37,4 @@ export declare function cacheOpenapiDoc(openapiName: string, routes: RouteConfig
|
|
|
37
37
|
* @param openapiName - the openapiName you wish to look up
|
|
38
38
|
*/
|
|
39
39
|
export declare function ignoreOpenapiDoc(openapiName: string): void;
|
|
40
|
+
export declare function _testOnlyClearOpenapiCache(openapiName: string): void;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@rvoh/psychic",
|
|
4
4
|
"description": "Typescript web framework",
|
|
5
|
-
"version": "1.8.
|
|
5
|
+
"version": "1.8.5",
|
|
6
6
|
"author": "RVOHealth",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -96,4 +96,4 @@
|
|
|
96
96
|
"winston": "^3.14.2"
|
|
97
97
|
},
|
|
98
98
|
"packageManager": "yarn@4.7.0"
|
|
99
|
-
}
|
|
99
|
+
}
|