8000 [Question] Validation through json schemas · Issue #402 · api-platform/core · GitHub
[go: up one dir, main page]

Skip to content
[Question] Validation through json schemas #402
@soyuka

Description

@soyuka

I was thinking about validation constraints, and as we're playing a lot with json in this library I thought it would be nice to validate data through json schemas. I don't think that Annotations are good for entities validation in a system which may change, or be used in a different way. Yaml validations would be sufficient, but json-schema's are more portable and might be re-used for a different task.

I've started an implementation which:

  • takes a Class constraint annotation (specifying, or not, the json schema)
  • parse the schema through justinrainbow/json-schema
  • checks input data through the json-schema validator

Now, I hit a wall where json-schema does not accept Classes, but requires an object. Which leads to three solutions:

  • try to validate input data before the denormalization - as a side-effect, it'll not be possible to only send one property to update the whole object will be needed
  • serialize the Entity to valid it through the shema - this would be the cleaner solution, but the entity will be serialized twice (validation + response)
  • try to hack into the json-schema validator to accept Classes - this could definitly work but will require more work

What would be your choice if you had to implement this? Would you have a solution in mind that I haven't think about? Or is this maybe a bad idea?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0