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

Support @required and $data annotations. #1788

Closed
georeith opened this issue Oct 5, 2023 · 5 comments
Closed

Support @required and $data annotations. #1788

georeith opened this issue Oct 5, 2023 · 5 comments

Comments

@georeith
Copy link
Contributor

georeith commented Oct 5, 2023

I want to validate that my normalized data structure is correct and that every value in steps exists as a key in stepDefinitions:

export type UserTest {
   steps: string[];
  /**
   * @required { $data: "#/steps" }
   */
   stepDefinitions: Record<string, StepDefinition>;
}

However the @required tag is ignored although it is a base keyword in AJV for objects. If I enable it via extraTags I then get this error:

Error: schema is invalid: data/definitions/UserTest/properties/stepDefinitions/required must be array

Is what I'm trying to do possible with this library currently?

@domoritz
Copy link
Member

domoritz commented Oct 5, 2023

Sorry, I don't have cycles to look into answering questions. If you want an enhancement to this library, can you send a pull request?

@georeith
Copy link
Contributor Author

georeith commented Oct 5, 2023

Sorry, I don't have cycles to look into answering questions. If you want an enhancement to this library, can you send a pull request?

I'm trying to gauge whether it is an existing feature or not first as I couldn't find documentation on the tags and what syntax is supported.

Maybe I could have framed the question better but there is no need to be snarky. I framed the question as a yes or no answer I'm not asking you to do my homework.

By your response I presume it's no.

@georeith
Copy link
Contributor Author

georeith commented Oct 6, 2023

My bad this is working as I wanted as long as "required" is passed to extraTags the error above is an AJV validation issue, this is creating the Schema as I wanted. 👍

@georeith georeith closed this as completed Oct 6, 2023
@domoritz
Copy link
Member

domoritz commented Oct 6, 2023

Awesome. Your issue and question were totally valid btw. I wanted to give you a realistic expectation what I'll be able to do right now as I'll travel after next week.

Is required a valid json schema tag? If yes, it might be correct to support it by default.

@georeith
Copy link
Contributor Author

georeith commented Oct 6, 2023

Thanks, sorry if I read too much into that it had been a long day and my question was confusing because I had conflated the AJV error as coming from this library which then confused me about what was/wasn't supported.

Yeah its a valid tag for object: https://json-schema.org/understanding-json-schema/reference/object#required

The usage of it with { $data: jsonPointer } is an AJV specific thing as $data never made it into the official spec: json-schema-org/json-schema-spec#51

I've made a PR to add it here: #1789 with some test cases for the above.

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

No branches or pull requests

2 participants