use of com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder in project jsonschema-generator by victools.
the class SubtypeResolutionFromInterfaceIntegrationTest method testIntegration.
@Test
public void testIntegration() throws Exception {
JacksonModule module = new JacksonModule(JacksonOption.FLATTENED_ENUMS_FROM_JSONVALUE);
SchemaGeneratorConfig config = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2019_09, OptionPreset.PLAIN_JSON).with(Option.DEFINITIONS_FOR_ALL_OBJECTS, Option.NULLABLE_FIELDS_BY_DEFAULT).with(module).build();
SchemaGenerator generator = new SchemaGenerator(config);
JsonNode result = generator.generateSchema(TestClassForSubtypeResolution.class);
String rawJsonSchema = result.toString();
JSONAssert.assertEquals('\n' + rawJsonSchema + '\n', loadResource("subtype-interface-integration-test-result.json"), rawJsonSchema, JSONCompareMode.STRICT);
JsonSchema schemaForValidation = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V201909).getSchema(result);
String jsonInstance = config.getObjectMapper().writeValueAsString(new TestClassForSubtypeResolution());
Set<ValidationMessage> validationResult = schemaForValidation.validate(config.getObjectMapper().readTree(jsonInstance));
if (!validationResult.isEmpty()) {
Assert.fail("\n" + jsonInstance + "\n " + validationResult.stream().map(ValidationMessage::getMessage).collect(Collectors.joining("\n ")));
}
}
use of com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder in project jsonschema-generator by victools.
the class IntegrationTest method testIntegration.
/**
* Test
*
* @throws Exception
*/
@Test
public void testIntegration() throws Exception {
// active all optional modules
SwaggerModule module = new SwaggerModule(SwaggerOption.ENABLE_PROPERTY_NAME_OVERRIDES, SwaggerOption.IGNORING_HIDDEN_PROPERTIES);
SchemaGeneratorConfig config = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2019_09, OptionPreset.FULL_DOCUMENTATION).with(Option.NULLABLE_ARRAY_ITEMS_ALLOWED).with(module).build();
SchemaGenerator generator = new SchemaGenerator(config);
JsonNode result = generator.generateSchema(TestClass.class);
String rawJsonSchema = result.toString();
JSONAssert.assertEquals('\n' + rawJsonSchema + '\n', loadResource("integration-test-result.json"), rawJsonSchema, JSONCompareMode.STRICT);
}
use of com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder in project jsonschema-generator by victools.
the class IntegrationTest method testIntegration.
@Test
@Parameters
public void testIntegration(Class<?> rawTargetType) throws Exception {
Swagger2Module module = new Swagger2Module();
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2019_09, OptionPreset.PLAIN_JSON).with(Option.DEFINITIONS_FOR_ALL_OBJECTS, Option.NULLABLE_ARRAY_ITEMS_ALLOWED).with(Option.NONSTATIC_NONVOID_NONGETTER_METHODS, Option.FIELDS_DERIVED_FROM_ARGUMENTFREE_METHODS).with(module);
SchemaGenerator generator = new SchemaGenerator(configBuilder.build());
JsonNode result = generator.generateSchema(rawTargetType);
String rawJsonSchema = result.toString();
JSONAssert.assertEquals('\n' + rawJsonSchema + '\n', loadResource("integration-test-result-" + rawTargetType.getSimpleName() + ".json"), rawJsonSchema, JSONCompareMode.STRICT);
}
use of com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder in project alfresco-java-sdk by Alfresco.
the class JsonSchemaGeneratorTest method jsonSchema.
@Test
public void jsonSchema() {
for (final EventEntry entry : EventEntry.values()) {
final SchemaGeneratorConfigBuilder configBuilder = getConfigBuilder(entry);
final SchemaGeneratorConfig config = configBuilder.build();
final SchemaGenerator generator = new SchemaGenerator(config);
final JsonNode jsonSchema = generator.generateSchema(RepoEvent.class);
entry.fileNames.forEach(file -> writeToFile(jsonSchema, file));
}
}
use of com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder in project tapestry-5 by apache.
the class RestJacksonModule method buildSchemaGenerator.
/**
* Provides the default {@link SchemaGenerator} instance with a default configuration.
*/
public static SchemaGenerator buildSchemaGenerator() {
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2019_09, OptionPreset.PLAIN_JSON);
SchemaGeneratorConfig config = configBuilder.build();
return new SchemaGenerator(config);
}
Aggregations