pwall567 / json-kotlin-schema-codegen

Code generation for JSON Schema (Draft 07)
MIT License
75 stars 11 forks source link

Custom template #5

Open chforsb opened 2 years ago

chforsb commented 2 years ago

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!

pwall567 commented 2 years ago

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!