@sleekify/sleekify-fastify 1.0.0 → 1.0.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.
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +49 -16
- package/package.json +3 -3
package/dist/src/index.d.ts
CHANGED
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) {
|
|
@@ -182,11 +188,6 @@ class Sleekify {
|
|
|
182
188
|
}
|
|
183
189
|
addRequestBody(operationObject, resolvedConsumes, resolvedSchema) {
|
|
184
190
|
if (operationObject.requestBody === undefined) {
|
|
185
|
-
operationObject.requestBody = {};
|
|
186
|
-
}
|
|
187
|
-
const referenceObject = operationObject.requestBody;
|
|
188
|
-
const requestBody = operationObject.requestBody;
|
|
189
|
-
if (referenceObject.$ref === undefined && requestBody.content === undefined) {
|
|
190
191
|
operationObject.requestBody = {
|
|
191
192
|
content: resolvedConsumes.reduce((content, mediaType) => {
|
|
192
193
|
content[mediaType] = {
|
|
@@ -196,6 +197,10 @@ class Sleekify {
|
|
|
196
197
|
}, {})
|
|
197
198
|
};
|
|
198
199
|
}
|
|
200
|
+
const requestBody = operationObject.requestBody;
|
|
201
|
+
if (lodash_1.default.isEmpty(requestBody) || (requestBody.content !== undefined && lodash_1.default.isEmpty(requestBody.content) && Object.keys(requestBody).length === 1)) {
|
|
202
|
+
delete operationObject.requestBody;
|
|
203
|
+
}
|
|
199
204
|
}
|
|
200
205
|
addResponses(operationObject, resolvedProduces, resolvedSchema, resolvedStatusCodes) {
|
|
201
206
|
if (resolvedStatusCodes.length === 0) {
|
|
@@ -219,15 +224,20 @@ class Sleekify {
|
|
|
219
224
|
}
|
|
220
225
|
else {
|
|
221
226
|
const referenceOrResponse = operationObject.responses[resolvedStatusCode];
|
|
222
|
-
if (referenceOrResponse.$ref === undefined
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
content
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
227
|
+
if (referenceOrResponse.$ref === undefined) {
|
|
228
|
+
if (referenceOrResponse.content === undefined) {
|
|
229
|
+
const responseObject = operationObject.responses[resolvedStatusCode];
|
|
230
|
+
/* add content to an existing response object */
|
|
231
|
+
responseObject.content = resolvedProduces.reduce((content, mediaType) => {
|
|
232
|
+
content[mediaType] = {
|
|
233
|
+
schema: resolvedSchema
|
|
234
|
+
};
|
|
235
|
+
return content;
|
|
236
|
+
}, {});
|
|
237
|
+
}
|
|
238
|
+
if (lodash_1.default.isEmpty(referenceOrResponse.content)) {
|
|
239
|
+
delete referenceOrResponse.content;
|
|
240
|
+
}
|
|
231
241
|
}
|
|
232
242
|
}
|
|
233
243
|
}
|
|
@@ -254,7 +264,13 @@ class Sleekify {
|
|
|
254
264
|
addServiceHandlers(clazz, classInstance, pathItemObject) {
|
|
255
265
|
const path = pathItemObject.path;
|
|
256
266
|
const operationMap = {};
|
|
257
|
-
|
|
267
|
+
const propertyNameMap = {};
|
|
268
|
+
for (let prototype = Object.getPrototypeOf(classInstance); prototype !== Object.prototype; prototype = Object.getPrototypeOf(prototype)) {
|
|
269
|
+
for (const propertyName of Object.getOwnPropertyNames(prototype)) {
|
|
270
|
+
propertyNameMap[propertyName] = null;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
for (const propertyName in propertyNameMap) {
|
|
258
274
|
const propertyValue = classInstance[propertyName];
|
|
259
275
|
if (['constructor', 'function'].includes(propertyName) || !lodash_1.default.isFunction(propertyValue)) {
|
|
260
276
|
continue;
|
|
@@ -314,5 +330,22 @@ class Sleekify {
|
|
|
314
330
|
}
|
|
315
331
|
lodash_1.default.set(root, path, result);
|
|
316
332
|
}
|
|
333
|
+
sortOperationObjects(result) {
|
|
334
|
+
if (result.paths !== undefined) {
|
|
335
|
+
for (const path in result.paths) {
|
|
336
|
+
const pathItemObject = result.paths[path];
|
|
337
|
+
for (const methodMap of methodMapArray) {
|
|
338
|
+
const operationObject = pathItemObject[methodMap.key];
|
|
339
|
+
if (operationObject !== undefined) {
|
|
340
|
+
this.sortObject(operationObject, 'callbacks');
|
|
341
|
+
this.sortObject(operationObject, 'responses');
|
|
342
|
+
if (operationObject.tags !== undefined) {
|
|
343
|
+
operationObject.tags.sort();
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
317
350
|
}
|
|
318
351
|
exports.Sleekify = Sleekify;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sleekify/sleekify-fastify",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
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
|
|
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.
|
|
44
|
+
"@sleekify/sleekify": "^1.0.4",
|
|
45
45
|
"@types/node": "^20.4.5",
|
|
46
46
|
"fastify": "^5.0.0",
|
|
47
47
|
"fastify-openapi-glue": "^4.7.1",
|