-
Notifications
You must be signed in to change notification settings - Fork 1
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
Handle Swagger Schema Objects #17
Comments
Hi !
Definitively yes! Swagger is close to be mainstream. I guess we should keep decoupled stuff but we can make effort to make swagger validation compatible. I guess we could enforce the usage of Something like <?php
namespace Rezzza\SymfonyRestApiJson;
class PayloadValidator
{
private $jsonSchemaTools;
private $schemaloader;
public function __construct(JsonSchemaTools $jsonSchemaTools, SchemaLoader $schemaloader)
{
$this->jsonSchemaTools = $jsonSchemaTools;
$this->schemaloader = $schemaloader;
}
public function validate($payload, $validationPath)
{
$validationSchema = $this->schemaloader->schemaOfPath($validationPath);
$delegateValidator = $this->jsonSchemaTools->createValidator();
$refResolver = $this->jsonSchemaTools->createRefResolver();
$delegateValidator->check(
json_decode($payload),
$refResolver->resolve($validationSchema->asString())
);
if (!$delegateValidator->isValid()) {
throw InvalidPayload::withErrors($payload, $jsonSchemaFilename, $delegateValidator->getErrors());
}
}
} where schema loader would accept an array of So for your example:
and in routing.yml
It would fix all issues, does not it ? |
Hi @tyx Sorry for the late response. Basically, I really like what you purpose, especially the |
Ok yes may be we should have extra work around the refResolver but I'm sure it is not a big deal :p |
Hi,
I'm using Swagger to define Schema Objects which are based on the JSON Schema Specification Draft 4.
I have a standalone example that you can find here:
https://gist.github.com/jeremyb/a0419ad9d5501fb602f052169112166f
I'm curious to know if you might be interested to make
symfony-json-rest-api
works with Swagger (not only with separate JSON Schema files).Currently, I see some issues with the
PayloadValidator
class (especially with$jsonSchemaFilename
:file_exists
andrealpath
calls).Also, we probably need to update
JsonSchemaTools
to allow the creation from aSchemaStorage
?Do you have some ideas about how to handle that? I'm available to contribute in the next days/weeks :)
The text was updated successfully, but these errors were encountered: