|
1 |
| -# jsonschema-module-javax-validation |
2 |
| -Module for the `jsonschema-generator` – deriving JSON Schema attributes from `javax.validation` annotations |
| 1 | +# Java JSON Schema Generator – Module javax.validation |
| 2 | +[](https://maven-badges.herokuapp.com/maven-central/com.github.victools/jsonschema-module-javax-validation) |
| 3 | + |
| 4 | +Module for the `jsonschema-generator` – deriving JSON Schema attributes from `javax.validation` annotations. |
| 5 | + |
| 6 | +## Usage |
| 7 | +### Dependency (Maven) |
| 8 | + |
| 9 | +```xml |
| 10 | +<dependency> |
| 11 | + <groupId>com.github.victools</groupId> |
| 12 | + <artifactId>jsonschema-module-javax-validation</artifactId> |
| 13 | + <version>1.0.0</version> |
| 14 | +</dependency> |
| 15 | +``` |
| 16 | + |
| 17 | +### Code |
| 18 | +#### Passing into SchemaGeneratorConfigBuilder.with(Module) |
| 19 | +```java |
| 20 | +import com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder; |
| 21 | +import com.github.victools.jsonschema.module.javax.validation.JavaxValidationModule; |
| 22 | +``` |
| 23 | +```java |
| 24 | +JavaxValidationModule module = new JavaxValidationModule(); |
| 25 | +SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(objectMapper) |
| 26 | + .with(module); |
| 27 | +``` |
| 28 | + |
| 29 | +#### Complete Example |
| 30 | +```java |
| 31 | +import com.fasterxml.jackson.databind.JsonNode; |
| 32 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 33 | +import com.github.victools.jsonschema.generator.OptionPreset; |
| 34 | +import com.github.victools.jsonschema.generator.SchemaGenerator; |
| 35 | +import com.github.victools.jsonschema.generator.SchemaGeneratorConfig; |
| 36 | +import com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder; |
| 37 | +import com.github.victools.jsonschema.module.javax.validation.JavaxValidationModule; |
| 38 | +``` |
| 39 | +```java |
| 40 | +ObjectMapper objectMapper = new ObjectMapper(); |
| 41 | +JavaxValidationModule module = new JavaxValidationModule(); |
| 42 | +SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(objectMapper, OptionPreset.PLAIN_JSON) |
| 43 | + .with(module); |
| 44 | +SchemaGeneratorConfig config = configBuilder.build(); |
| 45 | +SchemaGenerator generator = new SchemaGenerator(config); |
| 46 | +JsonNode jsonSchema = generator.generateSchema(YourClass.class); |
| 47 | + |
| 48 | +System.out.println(jsonSchema.toString()); |
| 49 | +``` |
0 commit comments