E521 docs: mention `ContextBuilder` returned from `#check()` by fedeci · Pull Request #972 · express-validator/express-validator · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@fedeci
Copy link
Member
@fedeci fedeci commented Jan 2, 2021

Description

We mention in the docs that ContextBuilder is exposed in the result of #check() middleware.

This allows to get the properties of the builder.
It can be used to create a library based on the context that will be built.
(e.g. swagger docs generation)

I don't know if it is better to expose the properties in this way or to build a "local" context, @gustavohenke what do you think?

To-do list

  • I have added tests for what I changed.
  • This pull request is ready to merge.

@coveralls
Copy link
coveralls commented Jan 2, 2021

Coverage Status

Coverage remained the same at 100.0% when pulling 939bae6 on fedeci:get-builder-properties into 690cd63 on express-validator:master.

@fedeci fedeci requested a review from gustavohenke January 2, 2021 23:08
Copy link
Member
@gustavohenke gustavohenke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it is better to expose the properties in this way or to build a "local" context

Hmm I don't mind either way at the moment. The Context interface is quite small, so this looks reasonable for now.

I don't recall if the .builder property is exposed/documented anywhere... do you think it would make more sense to put it in

export interface ContextHandler<Chain> {
bail(): Chain;
if(condition: CustomValidator | ValidationChain): Chain;
optional(options?: Partial<Optional> | true): Chain;
}
instead?

@fedeci
Copy link
Member Author
fedeci commented Jan 13, 2021

Yes, for example in check it is exposed here.
Maybe we should just document this so that the end user could create his own context with all his methods and not only access properties through the builder.

return Object.assign(
middleware,
bindAll(runner),
bindAll(new SanitizersImpl(builder, middleware as any)),
bindAll(new ValidatorsImpl(builder, middleware as any)),
bindAll(new ContextHandlerImpl(builder, middleware as any)),
{ builder },
);
}

@fedeci fedeci force-pushed the get-builder-properties branch from 741b357 to d4250a2 Compare February 23, 2021 20:12
@fedeci fedeci added the docs label Feb 23, 2021
@fedeci fedeci changed the title feat(context-builder): add 'getProperties' method docs: mention ContextBuilder returned from #check() Feb 23, 2021
@fedeci fedeci requested a review from gustavohenke February 23, 2021 20:15
Copy link
Member
@gustavohenke gustavohenke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will LGTM if we can add more docs than just this 😬

  • API entry
  • Possibly an entry under "Features", if it's necessary to showcase more of it

@fedeci fedeci requested a review from gustavohenke July 27, 2021 20:27
@fedeci fedeci force-pushed the get-builder-properties branch from d4250a2 to 939bae6 Compare July 29, 2021 09:56
Copy link
Member
@gustavohenke gustavohenke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...did you want to address the previous review?

@fedeci
Copy link
Member Author
fedeci commented Aug 8, 2021

Oops nope, asked review for the wrong PR😄

@gustavohenke gustavohenke force-pushed the master branch 2 times, most recently from 3177f64 to 6e160b1 Compare April 7, 2023 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0