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

AnyOf not supported #49

Closed
JbIPS opened this issue Sep 27, 2017 · 14 comments
Closed

AnyOf not supported #49

JbIPS opened this issue Sep 27, 2017 · 14 comments

Comments

@JbIPS
Copy link
Contributor

JbIPS commented Sep 27, 2017

When trying to validate against a JSON schema containing anyOf type, the parser throw an error.

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "properties": {
    "key1": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "object"
        }
      ]
    }
  },
  "additionalProperties": false
}

throws undefined unsupported.

I'll make a PR with a failing test case so it can be clearer.

@JbIPS
Copy link
Contributor Author

JbIPS commented Sep 27, 2017

I looked a bit at the code and I'm thinking of adding a case "anyOf" that will call the function again for each key.

What do you think?

@mcollina
Copy link
Member

Can you add a reference to the part of the JSON Schema for this?

👍 for a PR anyway.

@JbIPS
Copy link
Contributor Author

JbIPS commented Sep 28, 2017

Can you add a reference to the part of the JSON Schema for this?

I'm sorry, do you mean the JSON Schema spec ?

@mcollina
Copy link
Member

Yes thanks!! a PR would be very welcome!

@JbIPS
Copy link
Contributor Author

JbIPS commented Sep 28, 2017

I created #50 (and started it with failing tests) but I'm not sure how to start the implementation. My first guess was to add a case "anyOf" that will call the function again for each key.

What do you think of that?

@mcollina
Copy link
Member

go for it!

@JbIPS
Copy link
Contributor Author

JbIPS commented Sep 29, 2017

Worked a bit on that yesterday and I'm a bit stuck. A achieve to catch anyOf properties and iterate over the children but I can't see how I could tell to 'try' each one until one pass. I though the method $as[...] would throw errors if the type doesn't match but they don't.

Any leads?

Thanks

@mcollina
Copy link
Member

I don’t know really. Trying multiple paths and throwing errors completely defeat the purpose of this library.

A possibility might be to use Ajv to validate all the various option, but it would be slower.

@JbIPS
Copy link
Contributor Author

JbIPS commented Sep 29, 2017

If it's noted clearly that using anyOf cannot lead to any optimization but is supported, it could worth it, don't you think?

@mcollina
Copy link
Member

Yes definitely.

@JbIPS
Copy link
Contributor Author

JbIPS commented Oct 9, 2017

I finally had some time to work on this but I'm hitting an issue: how can I use ajv to validate the data inside the generated code? I tried to require it but require is not defined :/

@mcollina
Copy link
Member

mcollina commented Oct 9, 2017

It should be done following this pattern: https://github.com/fastify/fast-json-stringify/blob/master/index.js#L90-L92

@JbIPS
Copy link
Contributor Author

JbIPS commented Oct 9, 2017

Thank you! First draft of my implementation ready here

@JbIPS
Copy link
Contributor Author

JbIPS commented Oct 11, 2017

Closed by #50

@JbIPS JbIPS closed this as completed Oct 11, 2017
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