@sleekify/sleekify-fastify 1.0.0 → 1.0.1

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.
@@ -40,4 +40,5 @@ export declare class Sleekify {
40
40
  private addServiceHandlers;
41
41
  private getSuccessStatusCodes;
42
42
  private sortObject;
43
+ private sortOperationObjects;
43
44
  }
package/dist/src/index.js CHANGED
@@ -109,6 +109,13 @@ class Sleekify {
109
109
  for (const key of components) {
110
110
  this.sortObject(result, `components.${key}`);
111
111
  }
112
+ this.sortOperationObjects(result);
113
+ if (result.servers !== undefined) {
114
+ result.servers.sort((a, b) => a.url.localeCompare(b.url));
115
+ }
116
+ if (result.tags !== undefined) {
117
+ result.tags.sort((a, b) => a.name.localeCompare(b.name));
118
+ }
112
119
  }
113
120
  return result;
114
121
  }
@@ -137,7 +144,6 @@ class Sleekify {
137
144
  this.addServiceHandlers(clazz, classInstance, pathItemObject);
138
145
  }
139
146
  }
140
- // TODO - sort specification?
141
147
  }
142
148
  addComponents(clazz, componentsObject) {
143
149
  if (this.specification.components === undefined) {
@@ -254,7 +260,13 @@ class Sleekify {
254
260
  addServiceHandlers(clazz, classInstance, pathItemObject) {
255
261
  const path = pathItemObject.path;
256
262
  const operationMap = {};
257
- for (const propertyName of Object.getOwnPropertyNames(Object.getPrototypeOf(classInstance))) {
263
+ const propertyNameMap = {};
264
+ for (let prototype = Object.getPrototypeOf(classInstance); prototype !== Object.prototype; prototype = Object.getPrototypeOf(prototype)) {
265
+ for (const propertyName of Object.getOwnPropertyNames(prototype)) {
266
+ propertyNameMap[propertyName] = null;
267
+ }
268
+ }
269
+ for (const propertyName in propertyNameMap) {
258
270
  const propertyValue = classInstance[propertyName];
259
271
  if (['constructor', 'function'].includes(propertyName) || !lodash_1.default.isFunction(propertyValue)) {
260
272
  continue;
@@ -314,5 +326,22 @@ class Sleekify {
314
326
  }
315
327
  lodash_1.default.set(root, path, result);
316
328
  }
329
+ sortOperationObjects(result) {
330
+ if (result.paths !== undefined) {
331
+ for (const path in result.paths) {
332
+ const pathItemObject = result.paths[path];
333
+ for (const methodMap of methodMapArray) {
334
+ const operationObject = pathItemObject[methodMap.key];
335
+ if (operationObject !== undefined) {
336
+ this.sortObject(operationObject, 'callbacks');
337
+ this.sortObject(operationObject, 'responses');
338
+ if (operationObject.tags !== undefined) {
339
+ operationObject.tags.sort();
340
+ }
341
+ }
342
+ }
343
+ }
344
+ }
345
+ }
317
346
  }
318
347
  exports.Sleekify = Sleekify;
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@sleekify/sleekify-fastify",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A TypeScript decorator driven approach for developing Fastify web applications.",
5
5
  "scripts": {
6
6
  "build": "tsc",
7
7
  "lint": "eslint --ext .ts .",
8
- "test": "node --experimental-vm-modules ./node_modules/.bin/jest",
8
+ "test": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js",
9
9
  "validate": "npm run build && npm run lint -- --fix && npm test"
10
10
  },
11
11
  "repository": {
@@ -41,7 +41,7 @@
41
41
  "typescript": "^5.1.6"
42
42
  },
43
43
  "dependencies": {
44
- "@sleekify/sleekify": "^1.0.0",
44
+ "@sleekify/sleekify": "^1.0.3",
45
45
  "@types/node": "^20.4.5",
46
46
  "fastify": "^5.0.0",
47
47
  "fastify-openapi-glue": "^4.7.1",