Home

Awesome

Java JSON Schema Generation – Module Addon

Build Status Maven Central

Module for the victools/jsonschema-generator – deriving JSON Schema attributes from annotations

Features

Usage

Dependency (Maven)

<dependency>
    <groupId>com.github.imifou</groupId>
    <artifactId>jsonschema-module-addon</artifactId>
    <version>1.2.1</version>
</dependency>

Code

Passing into SchemaGeneratorConfigBuilder.with(Module)

import com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder;
import com.github.imifou.jsonschema.module.addon.AddonModule;
AddonModule module = new AddonModule();
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(objectMapper).with(module);

Complete Example

import com.github.imifou.jsonschema.module.addon.AddonModule;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.victools.jsonschema.generator.OptionPreset;
import com.github.victools.jsonschema.generator.SchemaGenerator;
import com.github.victools.jsonschema.generator.SchemaGeneratorConfig;
import com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder;
ObjectMapper objectMapper = new ObjectMapper();
AddonModule module = new AddonModule();
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(objectMapper,OptionPreset.PLAIN_JSON)
  .with(module);
SchemaGeneratorConfig config = configBuilder.build();
SchemaGenerator generator = new SchemaGenerator(config);
JsonNode jsonSchema = generator.generateSchema(getEntityClass());
        
System.out.println(jsonSchema.toString());