swagger-api / validator-badge

Validate your Swagger JSON/YAML today!
http://swagger.io
Apache License 2.0
210 stars 85 forks source link

Validator can cache the schema #8

Closed futurely closed 9 years ago

futurely commented 9 years ago

https://github.com/swagger-api/validator-badge/blob/master/src/main/java/com/wordnik/swagger/services/ValidatorService.java

        String schemaText = getSchema();
        JsonNode schemaObject = MAPPER.readTree(schemaText);
        JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
        JsonSchema schema = factory.getJsonSchema(schemaObject);

The schema can be cached to avoid being downloaded, parsed and built for every request.

private JsonSchema schema;

if (schema == null) {
        String schemaText = getSchema();
        JsonNode schemaObject = MAPPER.readTree(schemaText);
        JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
        schema = factory.getJsonSchema(schemaObject);
}
fehguy commented 9 years ago

can you please send a PR?

fehguy commented 9 years ago

well that's no fun. OK i've pushed it for you.