Skip to content

Commit

Permalink
Skip Validation (#109)
Browse files Browse the repository at this point in the history
Co-authored-by: Gabriel Massadas <5445926+G4brym@users.noreply.github.com>
  • Loading branch information
rmzaoo and G4brym committed Mar 2, 2024
1 parent 89255c1 commit 978c412
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/pages/user-guide/router-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
| `redoc_url` | `string` or `null` or `undefined` | Path for redoc docs, `null`: disabled, `undefined`: `/redocs` | `/redocs` |
| `openapi_url` | `string` or `null` or `undefined` | Path for openapi schema, `null`: disabled, `undefined`: `/openapi.json` | `/openapi.json` |
| `raiseUnknownParameters` | `boolean` | This will raise validation errors when an endpoint received an unknown query parameter | true |
| `skipValidation` | `boolean` | This will skip request data validation | false |
| `generateOperationIds` | `boolean` | This will generate operation ids from class names for your endpoints when nothing is provided | true |
| `openapiVersion` | `string` | Use this property to switch between the 3 and 3.1 OpenAPI specification, by default this will be `3.1` | `3.1` |
| `aiPlugin` | `object` or `undefined` | Object that will be used to generate the `ai-plugin.json` schema | [see schema bellow](#aiplugin) |
Expand Down
5 changes: 3 additions & 2 deletions src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export function OpenAPIRouter<
RequestType = IRequest,
Args extends any[] = any[],
RouteType = Equal<RequestType, IRequest> extends true
? Route
: UniversalRoute<RequestType, Args>
? Route
: UniversalRoute<RequestType, Args>
>(options?: RouterOptions): OpenAPIRouterType<RouteType, Args> {
const registry: OpenAPIRegistryMerger = new OpenAPIRegistryMerger()

Expand Down Expand Up @@ -193,6 +193,7 @@ export function OpenAPIRouter<
return (...params: any[]) =>
new handler({
// raiseUnknownParameters: openapiConfig.raiseUnknownParameters, TODO
skipValidation: options?.skipValidation,
}).execute(...params)
}

Expand Down
7 changes: 7 additions & 0 deletions src/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ export class OpenAPIRoute<I = IRequest, A extends any[] = any[]> {
}
}

if (this.params?.skipValidation === true) {
return {
data: unvalidatedData,
errors: undefined,
}
}

let validationSchema: any = z.object(rawSchema)

if (
Expand Down
4 changes: 3 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface RouterOptions {
raiseUnknownParameters?: boolean
generateOperationIds?: boolean
openapiVersion?: '3' | '3.1'
skipValidation?: boolean
baseRouter?: any
}

Expand Down Expand Up @@ -43,6 +44,7 @@ export declare type OpenAPIRouteSchema = Omit<

export interface RouteOptions {
raiseUnknownParameters: boolean
skipValidation: boolean
}

export interface ParameterType {
Expand Down Expand Up @@ -81,7 +83,7 @@ export interface ParameterLocation extends StringParameterType {

export interface RouteValidated {
data: any
errors: Record<string, any>
errors?: Record<string, any>
}

export enum SchemaVersion {
Expand Down

0 comments on commit 978c412

Please sign in to comment.