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

[POC, WIP] Reverse ajv errors #370

Closed
wants to merge 3 commits into from
Closed

[POC, WIP] Reverse ajv errors #370

wants to merge 3 commits into from

Conversation

Magnus-Kuhn
Copy link
Contributor

@Magnus-Kuhn Magnus-Kuhn commented Dec 16, 2024

Readiness checklist

  • I added/updated tests.
  • I ensured that the PR title is good enough for the changelog.
  • I labeled the PR.
  • I self-reviewed the PR.

Description

In case the JSON schema contains anyOf and every option throws an error, ajv returns an array of all the errors thrown by each case followed by an overall error must match a schema in anyOf. Currently the first error is returned, this investigates changing it to the last error.

anyOf is used in

  • distinguishing request item types and groups (both when creating and deciding a request)
  • distinguishing response item types
  • distinguishing attribute types (also in queries)
  • attribute owners in a third party relationship attribute query
  • request response source is message or relationship/ request source is message or template
  • get requests (string | string[])
  • truncated reference is from token / file / template
  • challenge is for relationship / identity / device

It could also come up if messages or templates were validated with ajv with their individual ContentDerivations, currently they (and requests) are validated using serval.

Especially for requests, messages and similar with a high property depth, the error message must match a schema could be thrown too early to be helpful, e. g. if a contained attribute is wrong. A possible approach would be to use @type annotations to then figure out what the correct content should be and then run another validation against that schema.
TestRequestItems and TestNotificationItems would also potentially need to be changed.

@Magnus-Kuhn Magnus-Kuhn added wip Work in Progress (blocks mergify from auto update the branch) enhancement New feature or request labels Dec 16, 2024
Copy link

codecov bot commented Dec 16, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../src/useCases/common/validation/SchemaValidator.ts 0.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
packages/runtime/src/useCases/common/Schemas.ts 100.00% <ø> (ø)
.../src/useCases/common/validation/SchemaValidator.ts 87.87% <0.00%> (ø)

... and 11 files with indirect coverage changes

@jkoenig134
Copy link
Member

@Magnus-Kuhn this can be closed & deleted now, right?

@Magnus-Kuhn
Copy link
Contributor Author

@Magnus-Kuhn this can be closed & deleted now, right?

I think so, it would still be an improvement but it's not one that's asked for by the customer. We can revisit it later if it's needed. I'm closing it.

@Magnus-Kuhn Magnus-Kuhn deleted the reverse-ajv-errors branch January 14, 2025 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wip Work in Progress (blocks mergify from auto update the branch)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants