-
I'm generating json schema from a pojo using the JakartaValidationModule. If i put This my code: var jakartaModule = new JakartaValidationModule(JakartaValidationOption.INCLUDE_PATTERN_EXPRESSIONS);
var configBuilder = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_7, OptionPreset.PLAIN_JSON).with(jakartaModule);
var config = configBuilder.build();
var generator = new SchemaGenerator(config);
var jsonSchema = generator.generateSchema(Example.class);
return jsonSchema.toPrettyString(); Example class: @lombok.Getter
@lombok.Setter
static class Example {
private String notRequiredField;
@jakarta.validation.constraints.NotNull
private String requiredField;
@jakarta.validation.constraints.NotEmpty
private List<String> notEmptyList;
private List<String> emptyList;
} This is the resulting json {
"$schema" : "http://json-schema.org/draft-07/schema#",
"type" : "object",
"properties" : {
"emptyList" : {
"type" : "array",
"items" : {
"type" : "string"
}
},
"notEmptyList" : {
"minItems" : 1,
"type" : "array",
"items" : {
"type" : "string"
}
},
"notRequiredField" : {
"type" : "string"
},
"requiredField" : {
"type" : "string"
}
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Ok, I just realized I missed the "JakartaValidationOption.NOT_NULLABLE_FIELD_IS_REQUIRED" option in the module. Now it works as expected. |
Beta Was this translation helpful? Give feedback.
Ok, I just realized I missed the "JakartaValidationOption.NOT_NULLABLE_FIELD_IS_REQUIRED" option in the module. Now it works as expected.