Skip to content

feat(exact): validate oneOf chains#1282

Draft
fedeci wants to merge 2 commits into
express-validator:masterfrom
fedeci:fedeci/feat/exact-and-oneof
Draft

feat(exact): validate oneOf chains#1282
fedeci wants to merge 2 commits into
express-validator:masterfrom
fedeci:fedeci/feat/exact-and-oneof

Conversation

@fedeci
Copy link
Copy Markdown
Member

@fedeci fedeci commented Feb 22, 2024

Description

Closes #1269

To-do list

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

@coveralls
Copy link
Copy Markdown

coveralls commented Feb 22, 2024

Coverage Status

coverage: 100.0%. remained the same
when pulling d371fc3 on fedeci:fedeci/feat/exact-and-oneof
into ffd7994 on express-validator:master.

Copy link
Copy Markdown
Member Author

@fedeci fedeci left a comment

Choose a reason for hiding this comment

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

This is a possible solution to close the linked issue. I would like to work a little bit more on this one to make the code cleaner.

Comment thread src/context-builder.ts
Comment on lines +45 to +49
pushSubcontext(...contexts: ReadonlyContext[]) {
this.subcontexts.push(...contexts);
return this;
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Before merging this I want experiment with inheritance of contexts to see if I can create separate contexts for each of the middlewares we provide. All of them would conform to a shared interface, so that some methods are easily callable without type casting.

Comment thread src/middlewares/exact.ts
return;
(internalReq[contextsKey] || [])
.flatMap(context => {
// TODO: This does not work for nested oneOf
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is something I feel that inherited contexts may help to achieve

Comment thread src/middlewares/one-of.ts
Comment on lines -13 to -18
import { ContextItem } from '../context-items';
import { runAllChains } from '../utils';

// A dummy context item that gets added to surrogate contexts just to make them run
const dummyItem: ContextItem = { async run() {} };

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Was this useful? Removing it did not make any test to fail.

@Hulahup01
Copy link
Copy Markdown

Will it be implemented?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using oneOf together with checkExact causes Unknown Field errors

3 participants