fastify-txstate 3.2.12 → 3.2.13

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.
Files changed (2) hide show
  1. package/lib/index.js +30 -6
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -131,13 +131,13 @@ class Server {
131
131
  * convert all nulls to undefined before fastify validates.
132
132
  */
133
133
  this.app.addHook('preSerialization', async (req, res, payload) => {
134
- return req.routeSchema?.response ? (0, txstate_utils_1.destroyNulls)(payload) : payload;
134
+ return req.routeOptions.schema?.response ? (0, txstate_utils_1.destroyNulls)(payload) : payload;
135
135
  });
136
136
  if (!config.skipOriginCheck && !process.env.SKIP_ORIGIN_CHECK) {
137
137
  this.setValidOrigins([...(config.validOrigins ?? []), ...(process.env.VALID_ORIGINS?.split(',') ?? [])]);
138
138
  this.setValidOriginHosts([...(config.validOriginHosts ?? []), ...(process.env.VALID_ORIGIN_HOSTS?.split(',') ?? [])]);
139
139
  this.setValidOriginSuffixes([...(config.validOriginSuffixes ?? []), ...(process.env.VALID_ORIGIN_SUFFIXES?.split(',') ?? [])]);
140
- this.app.addHook('preHandler', async (req, res) => {
140
+ this.app.addHook('onRequest', async (req, res) => {
141
141
  res.extraLogInfo = {};
142
142
  if (!req.headers.origin)
143
143
  return;
@@ -186,7 +186,7 @@ class Server {
186
186
  PATCH: true,
187
187
  DELETE: true
188
188
  };
189
- this.app.addHook('preHandler', async (req, res) => {
189
+ this.app.addHook('onRequest', async (req, res) => {
190
190
  if (!authenticatedMethods[req.method])
191
191
  return;
192
192
  try {
@@ -230,14 +230,14 @@ class Server {
230
230
  for (const v of err.validation ?? []) {
231
231
  if (v.keyword === 'errorMessage') {
232
232
  for (const ov of v.params.errors) {
233
- if (['type', 'additionalProperties'].includes(ov.keyword))
233
+ if (['type', 'additionalProperties', 'minProperties'].includes(ov.keyword))
234
234
  developerErrors.push({ ...ov, message: v.message });
235
235
  else
236
236
  userErrors.push({ ...ov, message: v.message });
237
237
  }
238
238
  }
239
239
  else {
240
- if (['type', 'additionalProperties'].includes(v.keyword))
240
+ if (['type', 'additionalProperties', 'minProperties'].includes(v.keyword))
241
241
  developerErrors.push(v);
242
242
  else
243
243
  userErrors.push(v);
@@ -340,7 +340,31 @@ this is log into this application and use dev tools to pull your token from the
340
340
  // Apply the security globally to all operations
341
341
  openapi.security = [{ unifiedAuth: [] }];
342
342
  }
343
- await this.app.register(swagger_1.default, { openapi });
343
+ function findRefs(obj, id) {
344
+ if (obj == null)
345
+ return undefined;
346
+ if (obj.$id?.length)
347
+ id = obj.$id;
348
+ if (obj.$ref === '#' && id?.length) {
349
+ obj.type = 'string';
350
+ obj.enum = [id];
351
+ delete obj.$ref;
352
+ }
353
+ else {
354
+ for (const val of Object.values(obj)) {
355
+ if (typeof val === 'object' && !(val instanceof Date))
356
+ findRefs(val, id);
357
+ }
358
+ }
359
+ return obj;
360
+ }
361
+ await this.app.register(swagger_1.default, {
362
+ openapi,
363
+ transform({ schema, url, route, swaggerObject, openapiObject }) {
364
+ const newSchema = findRefs((0, txstate_utils_1.clone)(schema));
365
+ return { schema: newSchema, url, route, swaggerObject, openapiObject };
366
+ }
367
+ });
344
368
  await this.app.register(swagger_ui_1.default, { ...opts?.ui, routePrefix: opts?.path ?? opts?.ui?.routePrefix ?? '/docs' });
345
369
  }
346
370
  async close(softSeconds) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastify-txstate",
3
- "version": "3.2.12",
3
+ "version": "3.2.13",
4
4
  "description": "A small wrapper for fastify providing a set of common conventions & utility functions we use.",
5
5
  "exports": {
6
6
  ".": {