snap-on-openapi 1.0.9 → 1.0.10

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 CHANGED
@@ -241,6 +241,10 @@ export class OpenApi {
241
241
  body: route.validators.response ?? z.undefined(),
242
242
  headers: route.validators.responseHeaders?.strict() ?? z.object({}),
243
243
  });
244
+ if (this.config.disableResponseValidation) {
245
+ this.logger.info('Response: 200', finalResponse);
246
+ return { status: 200, body: finalResponse.body, headers: finalResponse.headers };
247
+ }
244
248
  const validated = finalResponseValidator.safeParse(finalResponse);
245
249
  if (!validated.success) {
246
250
  throw new ValidationError(validated.error, ValidationLocation.Response);
@@ -255,7 +259,7 @@ export class OpenApi {
255
259
  handleError(e, req) {
256
260
  this.logger.error('Error during request openAPI route handling', e);
257
261
  try {
258
- const response = this.config.handleError ? this.config.handleError(e, req) : this.config.defaultError;
262
+ const response = this.config.handleError ? this.config.handleError(e, { request: req, logger: this.logger }) : this.config.defaultError;
259
263
  const status = this.config.errors[response.code].status;
260
264
  const valid = this.config.errors[response.code].responseValidator.safeParse(response.body);
261
265
  if (!valid.success) {
@@ -10,6 +10,7 @@ import { RouteContextMap } from './RouteContextMap.js';
10
10
  import { RouteExtraPropsMap } from './RouteExtraPropsMap.js';
11
11
  import { Server } from './Server.js';
12
12
  export type Config<TRouteTypes extends string, TErrorCodes extends string, TErrorConfigMap extends ErrorConfigMap<TErrorCodes>, TRouteParamMap extends RouteExtraPropsMap<TRouteTypes>, TRouteContextMap extends RouteContextMap<TRouteTypes, TRouteParamMap>, TRouteConfigMap extends RouteConfigMap<TRouteTypes, TErrorCodes, TRouteParamMap, TRouteContextMap>> = {
13
+ disableResponseValidation?: boolean;
13
14
  logger?: Logger;
14
15
  basePath: RoutePath;
15
16
  routes: TRouteConfigMap;
@@ -27,7 +28,10 @@ export type Config<TRouteTypes extends string, TErrorCodes extends string, TErro
27
28
  apiVersion?: string;
28
29
  servers?: Server[];
29
30
  logLevel?: LogLevel;
30
- handleError?: (e: unknown, req: Request) => ErrorResponse<TErrorCodes, TErrorConfigMap>;
31
+ handleError?: (e: unknown, context: {
32
+ request: Request;
33
+ logger: Logger;
34
+ }) => ErrorResponse<TErrorCodes, TErrorConfigMap>;
31
35
  middleware?: <T extends TRouteTypes>(route: AnyRoute<T>, ctx: Awaited<ReturnType<TRouteContextMap[T]>>) => Promise<{
32
36
  body?: unknown;
33
37
  status?: number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "snap-on-openapi",
3
3
  "author": "Alex Sarychev",
4
- "version": "1.0.9",
4
+ "version": "1.0.10",
5
5
  "description": "Swiftly build type-checked OpenAPI applications with Zod and TypeScript",
6
6
  "type": "module",
7
7
  "license": "ISC",