use of com.github.fge.jsonschema.main.JsonSchema in project records-management by Alfresco.
the class BaseYamlUnitTest method getSwaggerSchema.
/**
* Helper method to read in the Swagger JSON schema file
*/
private JsonSchema getSwaggerSchema(final String schemaLocation) throws IOException, ProcessingException {
JsonSchema swaggerSchema = null;
final InputStream in = this.getClass().getResourceAsStream(schemaLocation);
if (in != null) {
final String swaggerSchemaAsString = IOUtils.toString(in);
final JsonNode schemaNode = JsonLoader.fromString(swaggerSchemaAsString);
final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
swaggerSchema = factory.getJsonSchema(schemaNode);
}
return swaggerSchema;
}
use of com.github.fge.jsonschema.main.JsonSchema in project records-management by Alfresco.
the class BaseYamlUnitTest method validateYamlFiles.
/**
* Helper method to validate that all given yaml files are valid readable Swagger format
*/
protected void validateYamlFiles(final Set<String> yamlFileNames) throws ProcessingException, IOException {
assertFalse("Expected at least 1 yaml file to validate", yamlFileNames.isEmpty());
final JsonSchema swaggerSchema = getSwaggerSchema(SWAGGER_2_SCHEMA_LOCATION);
assertNotNull("Failed to obtain the Swagger schema", swaggerSchema);
for (String yamlFilePath : yamlFileNames) {
try {
// check the yaml file is valid against Swagger JSON schema
assertTrue("Yaml file is not valid Swagger " + OPEN_API_SPECIFICATION + ": " + yamlFilePath, validateYamlFile(yamlFilePath, swaggerSchema));
// check can read the swagger object to obtain the swagger version
Swagger swagger = new SwaggerParser().read(yamlFilePath);
assertEquals("Failed to obtain Swagger version from yaml file " + yamlFilePath, swagger.getSwagger(), OPEN_API_SPECIFICATION);
} catch (ParserException ex) {
// ensure the yaml filename is included in the message
String context = String.format(yamlFilePath + ": %n" + ex.getContext());
throw new ParserException(context, ex.getContextMark(), ex.getProblem(), ex.getProblemMark());
}
}
}
use of com.github.fge.jsonschema.main.JsonSchema in project syndesis by syndesisio.
the class ExtensionSchemaValidationTest method validateStepExtensionTest.
@Test
public void validateStepExtensionTest() throws ProcessingException, IOException {
String syndesisExtensionSchema = "/syndesis/syndesis-extension-definition-schema.json";
JsonSchema schema = JsonSchemaFactory.byDefault().getJsonSchema("resource:" + syndesisExtensionSchema);
ExtensionConverter converter = new DefaultExtensionConverter();
Extension extension = new Extension.Builder().extensionId("my-extension").name("Name").description("Description").uses(OptionalInt.empty()).version("1.0.0").schemaVersion(ExtensionConverter.getCurrentSchemaVersion()).addAction(new StepAction.Builder().id("action-1").name("action-1-name").description("Action 1 Description").pattern(Action.Pattern.From).descriptor(new StepDescriptor.Builder().entrypoint("direct:hello").kind(StepAction.Kind.ENDPOINT).build()).build()).build();
JsonNode tree = converter.toPublicExtension(extension);
ProcessingReport report = schema.validate(tree);
assertFalse(report.toString(), report.iterator().hasNext());
Extension extensionClone = converter.toInternalExtension(tree);
assertEquals(extensionClone, extension);
}
Aggregations