Search in sources :

Example 1 with GenerationConfig

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;
}
Also used : GenerationConfig(org.jsonschema2pojo.GenerationConfig)

Example 2 with GenerationConfig

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
}
Also used : DefaultGenerationConfig(org.jsonschema2pojo.DefaultGenerationConfig) RuleFactory(org.jsonschema2pojo.rules.RuleFactory) SchemaStore(org.jsonschema2pojo.SchemaStore) Jackson2Annotator(org.jsonschema2pojo.Jackson2Annotator) SchemaGenerator(org.jsonschema2pojo.SchemaGenerator) JCodeModel(com.sun.codemodel.JCodeModel) File(java.io.File) URL(java.net.URL) GenerationConfig(org.jsonschema2pojo.GenerationConfig) DefaultGenerationConfig(org.jsonschema2pojo.DefaultGenerationConfig) SchemaMapper(org.jsonschema2pojo.SchemaMapper)

Example 3 with GenerationConfig

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)));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SchemaStore(org.jsonschema2pojo.SchemaStore) Schema(org.jsonschema2pojo.Schema) URI(java.net.URI) JType(com.sun.codemodel.JType) GenerationConfig(org.jsonschema2pojo.GenerationConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 4 with GenerationConfig

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);
}
Also used : GenerationConfig(org.jsonschema2pojo.GenerationConfig)

Example 5 with GenerationConfig

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)));
}
Also used : SchemaStore(org.jsonschema2pojo.SchemaStore) NoopAnnotator(org.jsonschema2pojo.NoopAnnotator) GenerationConfig(org.jsonschema2pojo.GenerationConfig) DefaultGenerationConfig(org.jsonschema2pojo.DefaultGenerationConfig) Test(org.junit.Test)

Aggregations

GenerationConfig (org.jsonschema2pojo.GenerationConfig)6 SchemaStore (org.jsonschema2pojo.SchemaStore)4 Test (org.junit.Test)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 JCodeModel (com.sun.codemodel.JCodeModel)2 URI (java.net.URI)2 DefaultGenerationConfig (org.jsonschema2pojo.DefaultGenerationConfig)2 Schema (org.jsonschema2pojo.Schema)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 JDefinedClass (com.sun.codemodel.JDefinedClass)1 JType (com.sun.codemodel.JType)1 File (java.io.File)1 URL (java.net.URL)1 Jackson2Annotator (org.jsonschema2pojo.Jackson2Annotator)1 NoopAnnotator (org.jsonschema2pojo.NoopAnnotator)1 SchemaGenerator (org.jsonschema2pojo.SchemaGenerator)1 SchemaMapper (org.jsonschema2pojo.SchemaMapper)1 RuleFactory (org.jsonschema2pojo.rules.RuleFactory)1