Skip to content

Latest commit

 

History

History

delivery-sdk-generators

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Kontent.ai model generator for Java

License: MIT

Javadocs Maven Central

Stack Overflow GitHub Discussions

This tool generates strongly-typed models based on Content Types in a Kontent.ai project. The models are supposed to be used together with the Kontent.ai Delivery SDK for Java. Please read the documentation to see all benefits of this approach.

Get started

  1. Create a new instance of Code generator

    CodeGenerator generator = new CodeGenerator(
    "975bf280-fd91-488c-994c-2f04416e5ee3",
    'ai.kontent.test.springapp.models',
    file('src/main/java')
    );
  2. Generate models

    List<JavaFile> sources = generator.generateSources(client);
  3. Write the sources to the output directory

    generator.writeSources(sources);

Run as a gradle task

Add to your build.gradle

import com.squareup.javapoet.JavaFile
import kontent.ai.delivery.DeliveryClient
import kontent.ai.delivery.DeliveryOptions
import kontent.ai.delivery.generators.CodeGenerator

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath('ai.kontent:delivery-sdk-generators:latest.release')
    }
}

// showcase task
task generateModels {
    doLast {

        // The most complex solution, you could configure the client as you want
        // i.e. set preview API key
        DeliveryOptions options = new DeliveryOptions();
        options.setProjectId("975bf280-fd91-488c-994c-2f04416e5ee3");
        DeliveryClient client = new DeliveryClient(options);

        CodeGenerator generator = new CodeGenerator(
            options.getProjectId(),
            'ai.kontent.test.springapp.models',
            file('src/main/java')
        );
        List<JavaFile> sources = generator.generateSources(client);
        generator.writeSources(sources);
    }
}