use of com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper in project graylog2-server by Graylog2.
the class RetentionStrategyResource method getRetentionStrategyDescription.
private RetentionStrategyDescription getRetentionStrategyDescription(@ApiParam(name = "strategy", value = "The name of the retention strategy", required = true) @PathParam("strategy") @NotEmpty String strategyName) {
final Provider<RetentionStrategy> provider = retentionStrategies.get(strategyName);
if (provider == null) {
throw new NotFoundException("Couldn't find retention strategy for given type " + strategyName);
}
final RetentionStrategy retentionStrategy = provider.get();
final RetentionStrategyConfig defaultConfig = retentionStrategy.defaultConfiguration();
final SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
try {
objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(retentionStrategy.configurationClass()), visitor);
} catch (JsonMappingException e) {
throw new InternalServerErrorException("Couldn't generate JSON schema for retention strategy " + strategyName, e);
}
return RetentionStrategyDescription.create(strategyName, defaultConfig, visitor.finalSchema());
}
use of com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper in project graylog2-server by Graylog2.
the class RotationStrategyResource method getRotationStrategyDescription.
private RotationStrategyDescription getRotationStrategyDescription(String strategyName) {
final Provider<RotationStrategy> provider = rotationStrategies.get(strategyName);
if (provider == null) {
throw new NotFoundException("Couldn't find rotation strategy for given type " + strategyName);
}
final RotationStrategy rotationStrategy = provider.get();
final RotationStrategyConfig defaultConfig = rotationStrategy.defaultConfiguration();
final SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
try {
objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(rotationStrategy.configurationClass()), visitor);
} catch (JsonMappingException e) {
throw new InternalServerErrorException("Couldn't generate JSON schema for rotation strategy " + strategyName, e);
}
return RotationStrategyDescription.create(strategyName, defaultConfig, visitor.finalSchema());
}
use of com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper in project graylog2-server by Graylog2.
the class Generator method schemaForType.
private Map<String, Object> schemaForType(Type valueType) {
final SchemaFactoryWrapper schemaFactoryWrapper = new SchemaFactoryWrapper() {
@Override
public JsonAnyFormatVisitor expectAnyFormat(JavaType convertedType) {
/*final ObjectSchema s = schemaProvider.objectSchema();
s.putProperty("anyType", schemaProvider.stringSchema());
this.schema = s;
return visitorFactory.anyFormatVisitor(new AnySchema());*/
return super.expectAnyFormat(convertedType);
}
};
final JsonSchemaGenerator schemaGenerator = new JsonSchemaGenerator(mapper, schemaFactoryWrapper);
try {
final JsonSchema schema = schemaGenerator.generateSchema(mapper.getTypeFactory().constructType(valueType));
final Map<String, Object> schemaMap = mapper.readValue(mapper.writeValueAsBytes(schema), Map.class);
if (schemaMap.containsKey("additional_properties") && !schemaMap.containsKey("properties")) {
schemaMap.put("properties", Collections.emptyMap());
}
if (schemaMap.equals(Collections.singletonMap("type", "any"))) {
return ImmutableMap.of("type", "object", "properties", Collections.emptyMap());
}
return schemaMap;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper in project tutorials by eugenp.
the class ExtraAnnotationUnitTest method whenUsingJsonPropertyDescriptionAnnotation_thenCorrect.
@Test
public void whenUsingJsonPropertyDescriptionAnnotation_thenCorrect() throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
SchemaFactoryWrapper wrapper = new SchemaFactoryWrapper();
mapper.acceptJsonFormatVisitor(PropertyDescriptionBean.class, wrapper);
JsonSchema jsonSchema = wrapper.finalSchema();
String jsonString = mapper.writeValueAsString(jsonSchema);
System.out.println(jsonString);
assertThat(jsonString, containsString("This is a description of the name property"));
}
use of com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper in project graylog2-server by Graylog2.
the class ClusterConfigResource method schema.
@GET
@Path("{configClass}")
@Produces(MoreMediaTypes.APPLICATION_SCHEMA_JSON)
@ApiOperation(value = "Get JSON schema of configuration class")
@Timed
@RequiresPermissions(RestPermissions.CLUSTER_CONFIG_ENTRY_READ)
public JsonSchema schema(@ApiParam(name = "configClass", value = "The name of the cluster configuration class", required = true) @PathParam("configClass") @NotBlank String configClass) {
final Class<?> cls = classFromName(configClass);
if (cls == null) {
throw new NotFoundException(createNoClassMsg(configClass));
}
final SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
try {
objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(cls), visitor);
} catch (JsonMappingException e) {
throw new InternalServerErrorException("Couldn't generate JSON schema for configuration class " + configClass, e);
}
return visitor.finalSchema();
}
Aggregations