Open ragboyjr opened 6 years ago
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?
For the record I'm, 👍 for this!
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.
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.
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.
@ragboyjr Are you making progress on this subject, because it's very interesting?
@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.
See also https://github.com/api-platform/core/issues/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).
Any updates?
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.