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

[RFC] Json Schema Validations #2131

Open
ragboyjr opened this issue Jul 26, 2018 · 9 comments
Open

[RFC] Json Schema Validations #2131

ragboyjr opened this issue Jul 26, 2018 · 9 comments

Comments

@ragboyjr
Copy link
Contributor

What would you think about allowing JSON Schema Validations for API Resources that we could then expose inside of the generated OpenAPI documentation file?

Most of the basic symfony validations like Assert\Blank, Assert\Length etc are values that could be defined via the json schema vocabulary and a library like https://github.com/justinrainbow/json-schema would be able to parse and validate those definitions.

I don't think this would obviate the need for symfony validations because you might still want to use a custom validation rule or maybe check the db for uniqueness, but a lot of the simple stuff could easily be written as json schema validations.

@ragboyjr
Copy link
Contributor Author

I'd be willing to put in the effort coding wise, but not sure if this idea would even be worth adding/maintaining for you guys?

@dunglas
Copy link
Member

dunglas commented Dec 22, 2018

For the record I'm, 👍 for this!

@ragboyjr
Copy link
Contributor Author

Implementation wise, what do you think about caching the normalized swagger documentation? We could keep cached instances for v2 and v3?

I'm thinking we create an interface for accessing the normalized docs

interface DocumentationRepository {
  public function getDocs(string $type): array;
}

where type is swagger or openapi_v3.

and then a caching decorator implementation of that, and another that generates the Documentation object and normalizes it accordingly.

We could then use that normalized data to grab the definition per entity and run the json schema validator on it.

We might even want to add a ChainValidator so we can always enforce json schema, and optionally run SF validations on top of it.

@ragboyjr
Copy link
Contributor Author

hmm, one thing to mention that the normal API Platform validations occur on kernel.view which is after the deserialization step. Part of me wonders if the json schema validations should run on the raw JSON data BEFORE deserialization.

This could (possibly) mess up the various deserialization formats API Platform supports. It's almost as if, we should decode the value, then run JSON schema validation, then deserialize into the DTO or Entity object accordingly.

@Tchinkatchuk
Copy link

I do validate the need.
If any JSON schema validation could be done as soon as possible, the performance & quality of the response will be improved.

@fherbin
Copy link

fherbin commented Nov 13, 2020

@ragboyjr Are you making progress on this subject, because it's very interesting?

@ragboyjr
Copy link
Contributor Author

@fherbin I haven't made much progress on it, I think I hit that road block mentioned on Dec 22, didn't receive any feedback and moved on.

@soyuka
Copy link
Member

soyuka commented Nov 19, 2020

See also #3828. For the documentation cache I'd suggest using a file that you previously dump as it should be sufficient. Note that on the master branch the OpenApi code has been improved (use the OpenApiFactory).

@er1z
Copy link
Contributor

er1z commented Aug 29, 2024

Any updates?

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

7 participants