Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip Validation #109

Merged
merged 2 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading