spiceflow 1.11.0 → 1.11.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.
- package/README.md +2 -1
- package/dist/openapi.js +1 -1
- package/dist/spiceflow.js +1 -1
- package/dist/spiceflow.test.js +1 -1
- package/package.json +1 -1
- package/src/openapi.ts +1 -1
- package/src/spiceflow.test.ts +1 -1
- package/src/spiceflow.ts +1 -1
package/README.md
CHANGED
|
@@ -66,7 +66,7 @@ import { Spiceflow } from 'spiceflow'
|
|
|
66
66
|
// DO NOT declare the app separately and add routes later
|
|
67
67
|
const app = new Spiceflow()
|
|
68
68
|
|
|
69
|
-
// Do NOT do this!
|
|
69
|
+
// Do NOT do this! Defining routes separately will lose type safety
|
|
70
70
|
app.route({
|
|
71
71
|
method: 'GET',
|
|
72
72
|
path: '/hello',
|
|
@@ -74,6 +74,7 @@ app.route({
|
|
|
74
74
|
return 'Hello, World!'
|
|
75
75
|
},
|
|
76
76
|
})
|
|
77
|
+
// Do NOT do this! Adding routes separately like this will lose type safety
|
|
77
78
|
app.route({
|
|
78
79
|
method: 'POST',
|
|
79
80
|
path: '/echo',
|
package/dist/openapi.js
CHANGED
|
@@ -87,7 +87,7 @@ const registerSchemaPath = ({ schema, route, models, }) => {
|
|
|
87
87
|
contentTypes = Array.isArray(hooks.type) ? hooks.type : [hooks.type];
|
|
88
88
|
}
|
|
89
89
|
const path = toOpenAPIPath(route.path);
|
|
90
|
-
const bodySchema = getJsonSchema(hooks?.body);
|
|
90
|
+
const bodySchema = getJsonSchema(hooks?.request || hooks?.body);
|
|
91
91
|
let paramsSchema = hooks?.params;
|
|
92
92
|
if (route.path.includes(':') && !paramsSchema) {
|
|
93
93
|
const paramNames = extractParamNames(route.path);
|
package/dist/spiceflow.js
CHANGED
|
@@ -43,7 +43,7 @@ export class Spiceflow {
|
|
|
43
43
|
return allRoutes;
|
|
44
44
|
}
|
|
45
45
|
add({ method, path, hooks, handler, ...rest }) {
|
|
46
|
-
let bodySchema = hooks?.body;
|
|
46
|
+
let bodySchema = hooks?.request || hooks?.body;
|
|
47
47
|
let validateBody = getValidateFunction(bodySchema);
|
|
48
48
|
let validateQuery = getValidateFunction(hooks?.query);
|
|
49
49
|
let validateParams = getValidateFunction(hooks?.params);
|
package/dist/spiceflow.test.js
CHANGED
|
@@ -387,7 +387,7 @@ test('validate body works, request fails', async () => {
|
|
|
387
387
|
let body = await request.json();
|
|
388
388
|
expect(body).toEqual({ name: 'John' });
|
|
389
389
|
}, {
|
|
390
|
-
|
|
390
|
+
request: z.object({
|
|
391
391
|
name: z.string(),
|
|
392
392
|
requiredField: z.string(),
|
|
393
393
|
}),
|
package/package.json
CHANGED
package/src/openapi.ts
CHANGED
|
@@ -138,7 +138,7 @@ const registerSchemaPath = ({
|
|
|
138
138
|
|
|
139
139
|
const path = toOpenAPIPath(route.path)
|
|
140
140
|
|
|
141
|
-
const bodySchema = getJsonSchema(hooks?.body)
|
|
141
|
+
const bodySchema = getJsonSchema(hooks?.request || hooks?.body)
|
|
142
142
|
let paramsSchema = hooks?.params
|
|
143
143
|
if (route.path.includes(':') && !paramsSchema) {
|
|
144
144
|
const paramNames = extractParamNames(route.path)
|
package/src/spiceflow.test.ts
CHANGED
package/src/spiceflow.ts
CHANGED
|
@@ -143,7 +143,7 @@ export class Spiceflow<
|
|
|
143
143
|
handler,
|
|
144
144
|
...rest
|
|
145
145
|
}: Partial<InternalRoute>) {
|
|
146
|
-
let bodySchema: TypeSchema = hooks?.body
|
|
146
|
+
let bodySchema: TypeSchema = hooks?.request || hooks?.body
|
|
147
147
|
let validateBody = getValidateFunction(bodySchema)
|
|
148
148
|
let validateQuery = getValidateFunction(hooks?.query)
|
|
149
149
|
let validateParams = getValidateFunction(hooks?.params)
|