Skip to content

Conversation

@ConorCorp
Copy link

Issue

Closes #1269

Solution and steps

This exposes a custom request object and extends Foal's request object, thus allowing you to manually type your request params and body, to make typescript happy. Makes working with validation easier.

This works, but a better solution would just be to make ValidatePathParam and ValidateBody automatically type ctx.

Please let me know if this makes sense and I can add some docs.

Example Usage

  @Get()
  @ValidatePathParam('versionId', { type: 'string', format: 'uuid' })
  async getDocumentVersionApprovers(ctx: Context<UserContext, object, Request<undefined, {versionId: string}>>) {
    const {
      request: {
        params: { versionId },
      },
      user,
    } = ctx;

Checklist

  • Add/update/check docs (code comments and docs/ folder).
  • Add/update/check tests.
  • Update/check the cli generators.

@ConorCorp
Copy link
Author

Small side note:
npm run start-docker fails on the m1 macs due to the old versions of postgres and mysql not support arm processors. I had to run higher versions of each of those images.

@ConorCorp ConorCorp changed the title add: request type add: optional typed request Jul 4, 2024
@LoicPoullain
Copy link
Member

LoicPoullain commented May 27, 2025

As explained here, I'm closing this PR in favor of changes in version 5.

Sorry again it took so long and thank you for the well-written PR description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make A Controller's Request Typed

2 participants