Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
G4brym committed Nov 14, 2024
1 parent f01fd5e commit 480ab6f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ nav:
- advanced-user-guide/hiding-routes-in-openapi-schema.md
- advanced-user-guide/openapi-schema-customizations.md
- advanced-user-guide/streaming-responses.md
- advanced-user-guide/utilities.md
markdown_extensions:
- toc:
permalink: true
Expand Down
22 changes: 22 additions & 0 deletions docs/pages/advanced-user-guide/utilities.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Accessing url parameters from the class schema

You can now get a list of url parameters inside the getSchema function.
This can be very helpful when auto generating schemas

```ts
import { OpenAPIRoute } from './route'

// Define route
router.get("/v1/:account_id/gateways/:gateway_id", GetGateway);

export class GetAccountStats extends OpenAPIRoute {
getSchema() {
console.log(this.params.urlParams)

// The line above will print this: ["account_id", "gateway_id"]
// You can use this to manipulate the schema, adding or removing fields

return this.schema
}
};
```
32 changes: 22 additions & 10 deletions src/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,29 @@ export class OpenAPIRoute<HandleArgs extends Array<object> = any> {
}

handleValidationError(errors: z.ZodIssue[]): Response {
return jsonResp(
{
errors: errors,
success: false,
result: {},
},
{
status: 400,
},
);

// In the future, errors will be handled as exceptions
// Errors caught here are always validation errors
const updatedError: Array<object> = errors.map((err) => {
// @ts-ignore
if ((err as ApiException).buildResponse) {
// Error is already an internal exception
return err;
}
return new InputValidationException(err.message, err.path);
});

throw new MultiException(updatedError as Array<ApiException>);
// const updatedError: Array<object> = errors.map((err) => {
// // @ts-ignore
// if ((err as ApiException).buildResponse) {
// // Error is already an internal exception
// return err;
// }
// return new InputValidationException(err.message, err.path);
// });
//
// throw new MultiException(updatedError as Array<ApiException>);
}

async execute(...args: HandleArgs) {
Expand Down

0 comments on commit 480ab6f

Please sign in to comment.