use of org.jsonschema2pojo.SchemaStore in project jsonschema2pojo by joelittlejohn.
the class Example method main.
public static void main(String[] args) throws IOException {
// BEGIN EXAMPLE
JCodeModel codeModel = new JCodeModel();
URL source = Example.class.getResource("/schema/required.json");
GenerationConfig config = new DefaultGenerationConfig() {
@Override
public boolean isGenerateBuilders() {
// set config option by overriding method
return true;
}
};
SchemaMapper mapper = new SchemaMapper(new RuleFactory(config, new Jackson2Annotator(config), new SchemaStore()), new SchemaGenerator());
mapper.generate(codeModel, "ClassName", "com.example", source);
codeModel.build(Files.createTempDirectory("required").toFile());
// END EXAMPLE
}
use of org.jsonschema2pojo.SchemaStore in project jsonschema2pojo by joelittlejohn.
the class MinLengthMaxLengthRuleTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
rule = new MinLengthMaxLengthRule(new RuleFactory(config, new NoopAnnotator(), new SchemaStore()));
when(config.isUseJakartaValidation()).thenReturn(useJakartaValidation);
}
use of org.jsonschema2pojo.SchemaStore in project jsonschema2pojo by joelittlejohn.
the class PatternRuleTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
rule = new PatternRule(new RuleFactory(config, new NoopAnnotator(), new SchemaStore()));
when(config.isUseJakartaValidation()).thenReturn(useJakartaValidation);
}
use of org.jsonschema2pojo.SchemaStore in project jsonschema2pojo by joelittlejohn.
the class SchemaRuleTest method existingTypeIsUsedWhenTypeIsAlreadyGenerated.
@Test
public void existingTypeIsUsedWhenTypeIsAlreadyGenerated() throws URISyntaxException {
JType previouslyGeneratedType = mock(JType.class);
URI schemaUri = getClass().getResource("/schema/address.json").toURI();
SchemaStore schemaStore = new SchemaStore();
Schema schema = schemaStore.create(schemaUri, "#/.");
schema.setJavaType(previouslyGeneratedType);
final GenerationConfig mockGenerationConfig = mock(GenerationConfig.class);
when(mockGenerationConfig.getRefFragmentPathDelimiters()).thenReturn("#/.");
when(mockRuleFactory.getSchemaStore()).thenReturn(schemaStore);
when(mockRuleFactory.getGenerationConfig()).thenReturn(mockGenerationConfig);
ObjectNode schemaNode = new ObjectMapper().createObjectNode();
schemaNode.put("$ref", schemaUri.toString());
JType result = rule.apply(NODE_NAME, schemaNode, null, null, schema);
assertThat(result, is(sameInstance(previouslyGeneratedType)));
}
use of org.jsonschema2pojo.SchemaStore in project jsonschema2pojo by joelittlejohn.
the class SchemaRuleTest method refsToOtherSchemasAreLoaded.
@Test
public void refsToOtherSchemasAreLoaded() throws URISyntaxException, JClassAlreadyExistsException {
URI schemaUri = getClass().getResource("/schema/address.json").toURI();
ObjectNode schemaWithRef = new ObjectMapper().createObjectNode();
schemaWithRef.put("$ref", schemaUri.toString());
JDefinedClass jclass = new JCodeModel()._class(TARGET_CLASS_NAME);
final GenerationConfig mockGenerationConfig = mock(GenerationConfig.class);
when(mockGenerationConfig.getRefFragmentPathDelimiters()).thenReturn("#/.");
TypeRule mockTypeRule = mock(TypeRule.class);
when(mockRuleFactory.getTypeRule()).thenReturn(mockTypeRule);
when(mockRuleFactory.getSchemaStore()).thenReturn(new SchemaStore());
when(mockRuleFactory.getGenerationConfig()).thenReturn(mockGenerationConfig);
ArgumentCaptor<JsonNode> captureJsonNode = ArgumentCaptor.forClass(JsonNode.class);
ArgumentCaptor<Schema> captureSchema = ArgumentCaptor.forClass(Schema.class);
rule.apply(NODE_NAME, schemaWithRef, null, jclass, null);
verify(mockTypeRule).apply(eq("address"), captureJsonNode.capture(), any(), eq(jclass.getPackage()), captureSchema.capture());
assertThat(captureSchema.getValue().getId(), is(equalTo(schemaUri)));
assertThat(captureSchema.getValue().getContent(), is(equalTo(captureJsonNode.getValue())));
assertThat(captureJsonNode.getValue().get("description").asText(), is(equalTo("An Address following the convention of http://microformats.org/wiki/hcard")));
}
Aggregations