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

Provide builder in SwaggerValidator that takes JsonNode as schema #15

Closed
dmak opened this issue Aug 25, 2020 · 0 comments
Closed

Provide builder in SwaggerValidator that takes JsonNode as schema #15

dmak opened this issue Aug 25, 2020 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@dmak
Copy link

dmak commented Aug 25, 2020

In case when Swagger YAML contains both schema and examples, it is necessary to keep the reference to a whole document. Currently the only way out is to parse Swagger YAML twice:

JsonNode swaggerSpec;
SwaggerValidator validator;

try (InputStream in = getClass().getResourceAsStream("/htdoc/annotations.yaml")) {
    swaggerSpec = Yaml.mapper().readTree(in);
}

try (InputStream in = getClass().getResourceAsStream("/htdoc/annotations.yaml")) {
    validator = SwaggerValidator.forYamlSchema(new InputStreamReader(in, StandardCharsets.UTF_8));
}

ProcessingReport report = validator.validate(swaggerSpec.at("/components/examples/createRequest"), "/components/schemas/createRequest");

if (!report.isSuccess()) {
  ...
}

Suggestion:

JsonNode swaggerSpec;
SwaggerValidator validator;

try (InputStream in = getClass().getResourceAsStream("/htdoc/annotations.yaml")) {
    swaggerSpec = Yaml.mapper().readTree(in);
    validator = SwaggerValidator.forJsonSchema(swaggerSpec);
}

...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants