Search in sources :

Example 11 with SchemaGeneratorConfigBuilder

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  ")));
    }
}
Also used : SchemaGeneratorConfig(com.github.victools.jsonschema.generator.SchemaGeneratorConfig) ValidationMessage(com.networknt.schema.ValidationMessage) SchemaGeneratorConfigBuilder(com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder) JsonSchema(com.networknt.schema.JsonSchema) SchemaGenerator(com.github.victools.jsonschema.generator.SchemaGenerator) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 12 with SchemaGeneratorConfigBuilder

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);
}
Also used : SchemaGeneratorConfig(com.github.victools.jsonschema.generator.SchemaGeneratorConfig) SchemaGeneratorConfigBuilder(com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder) SchemaGenerator(com.github.victools.jsonschema.generator.SchemaGenerator) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 13 with SchemaGeneratorConfigBuilder

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);
}
Also used : SchemaGeneratorConfigBuilder(com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder) SchemaGenerator(com.github.victools.jsonschema.generator.SchemaGenerator) JsonNode(com.fasterxml.jackson.databind.JsonNode) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 14 with SchemaGeneratorConfigBuilder

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));
    }
}
Also used : SchemaGeneratorConfig(com.github.victools.jsonschema.generator.SchemaGeneratorConfig) SchemaGeneratorConfigBuilder(com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder) SchemaGenerator(com.github.victools.jsonschema.generator.SchemaGenerator) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 15 with SchemaGeneratorConfigBuilder

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);
}
Also used : SchemaGeneratorConfig(com.github.victools.jsonschema.generator.SchemaGeneratorConfig) SchemaGeneratorConfigBuilder(com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder) SchemaGenerator(com.github.victools.jsonschema.generator.SchemaGenerator)

Aggregations

SchemaGeneratorConfigBuilder (com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder)16 SchemaGenerator (com.github.victools.jsonschema.generator.SchemaGenerator)15 SchemaGeneratorConfig (com.github.victools.jsonschema.generator.SchemaGeneratorConfig)12 JsonNode (com.fasterxml.jackson.databind.JsonNode)11 Test (org.junit.Test)9 OptionPreset (com.github.victools.jsonschema.generator.OptionPreset)4 Map (java.util.Map)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 SchemaVersion (com.github.victools.jsonschema.generator.SchemaVersion)3 List (java.util.List)3 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)2 Option (com.github.victools.jsonschema.generator.Option)2 JacksonModule (com.github.victools.jsonschema.module.jackson.JacksonModule)2 JsonSchema (com.networknt.schema.JsonSchema)2 ValidationMessage (com.networknt.schema.ValidationMessage)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ResolvedType (com.fasterxml.classmate.ResolvedType)1 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1