-
Notifications
You must be signed in to change notification settings - Fork 0
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
JsonValidation #2
Comments
Maybe worth to consider:
|
I think we're talking about different things. I meant a middleware for json schema validation (using for example https://github.com/justinrainbow/json-schema), and you're talking about validate the body content to parse to json. Maybe the name is confusing, and Anyway, this libraries are interesting to include in middlewares/payload or do you prefer a new specific package for json that could include the utilities for parsing and schema validation?. |
I was aware of that, middlewares/payload is another project where these points could be considered. In my opinion we should consider to validate the raw body against the json schema and should replace the parsed body: $parsedBody = $this->parse($request->getBody());
$this->validate($parsedBody);
$request = $request->withParsedBody($parsedBody); This could provide some benefits:
Sorry, I can't follow you on this. |
Ok, my english is a bit 💩
$middleware = [
new Middlewares\JsonPayload(), //parse the json
new modifyParsedBody(), //modify the parsed body in somehow
new Middlewares\JsonSchemaValidation(), //validate the json schema
]; To me, is a bad idea to have some middlewares using the raw string body and others the parsed body because we remove the interoperation between. This is something I commented here: oscarotero/psr7-middlewares#50 (comment)
|
You are right, implementing these responsibilities within one single project is a bad idea. But we can also create a meta-middleware project which encapsulates the cumbersome setup above. For example: $middleware = [
…,
new Middlewares\JsonValidation('path/to/json-schemas', $modifyParsedBody),
…,
]; class JsonValidation extends MiddlewarePipe
{
public function __construct($path, MiddlewareInterface $modifyParsedBody = null)
{
$this->append(new Middlewares\JsonPayload()); //parse the json
if ($modifyParsedBody !== null) {
$this->append(new modifyParsedBody()); //modify the parsed body in somehow
}
$this->append(new Middlewares\JsonSchemaValidation($path)); //validate the json schema
}
} |
This could be a port (or improvement) of jsonvalidator: existing currently in psr7-middlewares: https://github.com/oscarotero/psr7-middlewares#jsonvalidator
Here's other similar package: https://github.com/moffe42/json-schema-middleware
The text was updated successfully, but these errors were encountered: