Search in sources :

Example 11 with SchemaGenerator

use of com.github.victools.jsonschema.generator.SchemaGenerator 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 12 with SchemaGenerator

use of com.github.victools.jsonschema.generator.SchemaGenerator 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 13 with SchemaGenerator

use of com.github.victools.jsonschema.generator.SchemaGenerator 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 14 with SchemaGenerator

use of com.github.victools.jsonschema.generator.SchemaGenerator 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

SchemaGenerator (com.github.victools.jsonschema.generator.SchemaGenerator)14 SchemaGeneratorConfigBuilder (com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder)14 SchemaGeneratorConfig (com.github.victools.jsonschema.generator.SchemaGeneratorConfig)11 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 Test (org.junit.Test)8 Map (java.util.Map)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)2 Option (com.github.victools.jsonschema.generator.Option)2 OptionPreset (com.github.victools.jsonschema.generator.OptionPreset)2 SchemaVersion (com.github.victools.jsonschema.generator.SchemaVersion)2 JsonSchema (com.networknt.schema.JsonSchema)2 ValidationMessage (com.networknt.schema.ValidationMessage)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)2 ResolvedType (com.fasterxml.classmate.ResolvedType)1 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 CustomPropertyDefinition (com.github.victools.jsonschema.generator.CustomPropertyDefinition)1