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

Validate schemas using ex_json_schema #47

Open
fenollp opened this issue Sep 7, 2018 · 5 comments
Open

Validate schemas using ex_json_schema #47

fenollp opened this issue Sep 7, 2018 · 5 comments

Comments

@fenollp
Copy link
Contributor

fenollp commented Sep 7, 2018

Following on #23 (and my attempt at solving it: #42), I have been instead using the really good ex_json_schema.

Here is the code I am using:

    case %{
           "components" => components,
           "additionalProperties" => false,
           "type" => "object",
           "required" => [schema_name],
           "properties" => %{
             schema_name => %{"$ref" => "#/components/schemas/#{schema_name}"}
           }
         }
         |> ExJsonSchema.Schema.resolve()
         |> ExJsonSchema.Validator.validate(resp)

There needs to be a translation step first though, to rewrite nullable: true and such incompatibilities of OpenAPIV3 schemas with JSON Schema Draft-04.

Would you be open to use ex_json_schema validators instead of the current ones in this lib?
Where do you think this translation step should be: within this lib or within ex_json_schema?

Thanks

@mbuhot
Copy link
Collaborator

mbuhot commented Sep 9, 2018

I'd be OK with using ex_json_schema for validations. As you say, it just needs to be possible to map swagger schemas to json schema.

It would be great if there was a mode: swagger option in ex_json_schema, but if you want to get something working immediately we'd need to map it in open_api_spex.

@fenollp
Copy link
Contributor Author

fenollp commented Sep 9, 2018

The people over at OpenAPI and at JSON Schema want to converge their schema specs eventually. To me it makes more sense to do a conversion to (and from?) JSON Schema before validation.

In which module do you think this conversion step should go?

@fenollp fenollp changed the title Validate schemas using Validate schemas using ex_json_schema Oct 17, 2018
@fenollp
Copy link
Contributor Author

fenollp commented May 21, 2019

@moxley why is this labeled as wontfix? Thanks.

@moxley
Copy link
Contributor

moxley commented May 21, 2019

@fenollp: The Won't Fix label is only tentative, but requires further discussion to be sure. From what I understand, JSON Schema isn't compatible with Open API. Open API borrows much from JSON Schema, but it extends and modifies it. Here are some of the details of the differences: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schema-object. I don't think it's feasible to swap in a JSON Schema library.

By the way, we set up a private channel in the Elixir Slack for discussions. Would you be willing to join us there? You've already been added.

@mbuhot
Copy link
Collaborator

mbuhot commented Apr 10, 2020

Looks like this can be achieved when OpenApi 3.1 is released.
OpenAPI schemas will be a proper superset of the latest json schema draft 🎉

OAI/OpenAPI-Specification#1977

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

No branches or pull requests

3 participants