use of org.jsonschema2pojo.GenerationConfig in project jsonschema2pojo by joelittlejohn.
the class LanguageFeaturesTest method mockConfig.
public static GenerationConfig mockConfig(String version) {
GenerationConfig config = mock(GenerationConfig.class);
when(config.getTargetVersion()).thenReturn(version);
return config;
}
use of org.jsonschema2pojo.GenerationConfig 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 = new URL("file:///path/to/my/schema.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(new File("output"));
// END EXAMPLE
}
use of org.jsonschema2pojo.GenerationConfig 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, schema);
assertThat(result, is(sameInstance(previouslyGeneratedType)));
}
use of org.jsonschema2pojo.GenerationConfig in project jsonschema2pojo by joelittlejohn.
the class RequiredArrayRuleTest method setupRuleFactoryToIncludeJsr303.
private void setupRuleFactoryToIncludeJsr303() {
GenerationConfig config = mock(GenerationConfig.class);
when(config.getPropertyWordDelimiters()).thenReturn(new char[] { '-', ' ', '_' });
RuleFactory ruleFactory = new RuleFactory();
ruleFactory.setGenerationConfig(config);
rule = new RequiredArrayRule(ruleFactory);
when(config.isIncludeJsr303Annotations()).thenReturn(true);
}
use of org.jsonschema2pojo.GenerationConfig in project jsonschema2pojo by joelittlejohn.
the class RuleFactoryImplTest method generationConfigIsReturned.
@Test
public void generationConfigIsReturned() {
GenerationConfig mockGenerationConfig = mock(GenerationConfig.class);
RuleFactory ruleFactory = new RuleFactory(mockGenerationConfig, new NoopAnnotator(), new SchemaStore());
assertThat(ruleFactory.getGenerationConfig(), is(sameInstance(mockGenerationConfig)));
}
Aggregations