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

Custom fields in schema (AJVs "custom keywords") #35

Open
antoniusostermann opened this issue May 26, 2020 · 4 comments
Open

Custom fields in schema (AJVs "custom keywords") #35

antoniusostermann opened this issue May 26, 2020 · 4 comments

Comments

@antoniusostermann
Copy link

antoniusostermann commented May 26, 2020

First of all: Thanks for this small library, it's exactly what I was looking for.

I'm trying to combine this library with AJV, struggling with the right way to use "custom keywords" (https://github.com/ajv-validator/ajv/blob/master/CUSTOM.md) with ts-json-validator. ts-json-validator does not allow any kind of keywords which aren't part of the official JSON Schema specification, so it throws an error for something like this:

  createSchema({
    type: "object",
    properties: {
      name: createSchema({ type: "string", forbiddenNames: ["Administrator"] }),
    },
  });

("Object literal may only specify known properties, and 'forbiddenNames' does not exist in type (...)")

One possible solution could be to allow additional typings via an optional generic and merge those toegether with the already existing ones, so I'd be able to use createSchema<{ forbiddenNames: string[] }> which would merge the parameter-type with the given one. As a further improvement, createSchema could even "inherit" the given type whenever sub-schemas are defined via properties etc.

What do you think about this?

Edit: Nevermind, had to switch to https://github.com/bcherny/json-schema-to-typescript due to some additional requirements. Keep up the great work! :-)

@ostrowr
Copy link
Owner

ostrowr commented May 26, 2020

This definitely seems possible but I have to think about the right design.

Besides the custom keywords issue, what other features were you looking for?

@nordluf
Copy link

nordluf commented Jul 9, 2020

Is there any chance for this ticket to be finished? Unfortunately, I'm not so familiar with TS and can't help you with PR.

@ostrowr
Copy link
Owner

ostrowr commented Jul 15, 2020

@nordluf planning on getting to this ASAP but unfortunately probably not this week.

@funkel1989
Copy link

The last update on this was quite a long time ago. Did you ever decide to move forward with this?

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

4 participants