json-kotlin-schema-codegen icon indicating copy to clipboard operation
json-kotlin-schema-codegen copied to clipboard

Custom template

Open chforsb opened this issue 4 years ago • 1 comments

Great work with both code generator and gradle plugin!

Just wanted to check if you have any plans for supplying a custom (mustache) templates, e.g. for class generation, and preferably also support in the gradle plugin?

Thanks!

chforsb avatar Aug 21 '21 09:08 chforsb

Thanks for the compliments :smile:

The ability to supply custom templates is already there:

    val directory = File("path/to/directory")
    val codeGenerator = CodeGenerator()
    codeGenerator.setTemplateDirectory(directory) // optional second parameter - extension (default ".mustache")

Generation of a class starts with a template named class. This is also customisable:

    codeGenerator.templateName = "custom_class"

I suspect you won't find it easy to create your own templates without a knowledge of the structures from which they derive their data - your best approach is probably to start by looking at the existing templates (at https://github.com/pwall567/json-kotlin-schema-codegen/tree/main/src/main/resources).

And I hadn't planned to add the specification of the template directory to the Gradle plugin - you're actually the first person to have asked about custom templates!

Good luck!

pwall567 avatar Aug 22 '21 13:08 pwall567