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.
-
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') );
-
Generate models
List<JavaFile> sources = generator.generateSources(client);
-
Write the sources to the output directory
generator.writeSources(sources);
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);
}
}