snap-on-openapi 1.0.10 → 1.0.12
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/OpenApi.js +4 -4
- package/dist/services/ExpressWrapper/ExpressWrapper.js +6 -1
- package/dist/services/ExpressWrapper/types/ExpressResponse.d.ts +1 -1
- package/dist/services/TanstackStartWrapper/TanstackStartWrapper.js +2 -1
- package/dist/services/ValidationUtils/transformers/stringDateTransformer.js +1 -1
- package/dist/types/errors/ValidationError.d.ts +5 -3
- package/dist/types/errors/ValidationError.js +6 -1
- package/package.json +1 -1
package/dist/OpenApi.js
CHANGED
|
@@ -185,19 +185,19 @@ export class OpenApi {
|
|
|
185
185
|
const queryValidator = route.validators.query?.strict() ?? z.object({});
|
|
186
186
|
const query = queryValidator.safeParse(req.query);
|
|
187
187
|
if (!query.success) {
|
|
188
|
-
throw new ValidationError(query.error, ValidationLocation.Query);
|
|
188
|
+
throw new ValidationError(query.error, ValidationLocation.Query, req.query);
|
|
189
189
|
}
|
|
190
190
|
const pathvalidator = route.validators.path?.strict() ?? z.object({});
|
|
191
191
|
const path = pathvalidator.safeParse(req.params);
|
|
192
192
|
if (!path.success) {
|
|
193
|
-
throw new ValidationError(path.error, ValidationLocation.Path);
|
|
193
|
+
throw new ValidationError(path.error, ValidationLocation.Path, req.params);
|
|
194
194
|
}
|
|
195
195
|
let response;
|
|
196
196
|
const containsBody = route.method !== Method.GET;
|
|
197
197
|
if (containsBody && route.validators.body) {
|
|
198
198
|
const body = route.validators.body.safeParse(req.body);
|
|
199
199
|
if (!body.success) {
|
|
200
|
-
throw new ValidationError(body.error, ValidationLocation.Body);
|
|
200
|
+
throw new ValidationError(body.error, ValidationLocation.Body, req.body);
|
|
201
201
|
}
|
|
202
202
|
const context = await this.config.routes[route.type].contextFactory({
|
|
203
203
|
route: route,
|
|
@@ -247,7 +247,7 @@ export class OpenApi {
|
|
|
247
247
|
}
|
|
248
248
|
const validated = finalResponseValidator.safeParse(finalResponse);
|
|
249
249
|
if (!validated.success) {
|
|
250
|
-
throw new ValidationError(validated.error, ValidationLocation.Response);
|
|
250
|
+
throw new ValidationError(validated.error, ValidationLocation.Response, finalResponse);
|
|
251
251
|
}
|
|
252
252
|
this.logger.info('Response: 200', validated.data);
|
|
253
253
|
return { status: 200, body: validated.data.body, headers: validated.data.headers };
|
|
@@ -41,7 +41,12 @@ export class ExpressWrapper {
|
|
|
41
41
|
for (const header of Object.entries(result.headers)) {
|
|
42
42
|
res.header(header[0], header[1]);
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
if (result.body instanceof Buffer) {
|
|
45
|
+
res.send(result.body);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
res.json(result.body);
|
|
49
|
+
}
|
|
45
50
|
};
|
|
46
51
|
const regex = new RegExp(`${route}.*`);
|
|
47
52
|
expressApp.get(regex, handler);
|
|
@@ -2,5 +2,5 @@ export interface ExpressResponse {
|
|
|
2
2
|
header: (name: string, value: string) => ExpressResponse;
|
|
3
3
|
status: (code: number) => ExpressResponse;
|
|
4
4
|
json: (data: unknown) => ExpressResponse;
|
|
5
|
-
send: (body: string) => ExpressResponse;
|
|
5
|
+
send: (body: string | Buffer) => ExpressResponse;
|
|
6
6
|
}
|
|
@@ -51,7 +51,8 @@ export class TanstackStartWrapper {
|
|
|
51
51
|
getOpenApiRootMethods() {
|
|
52
52
|
const processor = async (ctx) => {
|
|
53
53
|
const response = await this.service.processRootRoute(ctx.request);
|
|
54
|
-
const
|
|
54
|
+
const body = response.body instanceof Buffer ? response.body : JSON.stringify(response.body);
|
|
55
|
+
const res = new Response(body, {
|
|
55
56
|
status: response.status,
|
|
56
57
|
headers: response.headers,
|
|
57
58
|
});
|
|
@@ -2,9 +2,11 @@ import { ZodError } from 'zod';
|
|
|
2
2
|
import { ValidationLocation } from '../../enums/ValidationLocations.js';
|
|
3
3
|
import { BuiltInError } from './BuiltInError.js';
|
|
4
4
|
export declare class ValidationError extends BuiltInError {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
protected error: ZodError<unknown>;
|
|
6
|
+
protected location: ValidationLocation;
|
|
7
|
+
protected data?: unknown;
|
|
8
|
+
constructor(error: ZodError<unknown>, location: ValidationLocation, data: unknown);
|
|
8
9
|
getZodError(): ZodError<unknown>;
|
|
9
10
|
getLocation(): ValidationLocation;
|
|
11
|
+
getData(): unknown;
|
|
10
12
|
}
|
|
@@ -3,10 +3,12 @@ import { BuiltInError } from './BuiltInError.js';
|
|
|
3
3
|
export class ValidationError extends BuiltInError {
|
|
4
4
|
error;
|
|
5
5
|
location;
|
|
6
|
-
|
|
6
|
+
data;
|
|
7
|
+
constructor(error, location, data) {
|
|
7
8
|
super(ErrorCode.ValidationFailed);
|
|
8
9
|
this.error = error;
|
|
9
10
|
this.location = location;
|
|
11
|
+
this.data = data;
|
|
10
12
|
}
|
|
11
13
|
getZodError() {
|
|
12
14
|
return this.error;
|
|
@@ -14,4 +16,7 @@ export class ValidationError extends BuiltInError {
|
|
|
14
16
|
getLocation() {
|
|
15
17
|
return this.location;
|
|
16
18
|
}
|
|
19
|
+
getData() {
|
|
20
|
+
return this.data;
|
|
21
|
+
}
|
|
17
22
|
}
|
package/package.json
CHANGED