-
public final class CodeGeneratorJSON Schema Code Generator. The class may be parameterised either by constructor parameters or by setting the appropriate variables after construction.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enumCodeGenerator.NestedClassNameOptionpublic final classCodeGenerator.TargetIndexpublic final classCodeGenerator.NameGeneratorpublic final classCodeGenerator.EnumDefaultThis class is intended to look like a StringValue, for when the default value of a string is an enum value.
public abstract classCodeGenerator.CustomClasspublic final classCodeGenerator.CustomClassByURIpublic final classCodeGenerator.CustomClassByFormatpublic final classCodeGenerator.CustomClassByExtensionpublic final classCodeGenerator.AppendableFilterpublic classCodeGenerator.Companion
-
Field Summary
Fields Modifier and Type Field Description private CodeGenerator.NestedClassNameOptionnestedClassNameOptionprivate TemplatecommentTemplateprivate ParserschemaParserprivate ParsertemplateParserprivate Templatetemplateprivate StringinterfaceTemplateNameprivate TemplateinterfaceTemplateprivate TemplateenumTemplateFieldprivate TemplateenumTemplateprivate TargetFileNameindexFileNameprivate StringindexTemplateNameprivate TemplateindexTemplateFieldprivate TemplateindexTemplateprivate Function1<TargetFileName, Writer>outputResolverFieldprivate Function1<TargetFileName, Writer>outputResolverprivate final IntegernumTargetsprivate TargetLanguagetargetLanguageprivate StringtemplateNameprivate StringenumTemplateNameprivate StringbasePackageNameprivate StringbaseDirectoryNameprivate BooleanderivePackageFromStructureprivate StringgeneratorCommentprivate ClassIdmarkerInterfaceprivate final Loggerlog
-
Constructor Summary
Constructors Constructor Description CodeGenerator(TargetLanguage targetLanguage, String templateName, String enumTemplateName, String basePackageName, String baseDirectoryName, Boolean derivePackageFromStructure, String generatorComment, ClassId markerInterface, Logger log)
-
Method Summary
Modifier and Type Method Description final CodeGenerator.NestedClassNameOptiongetNestedClassNameOption()final UnitsetNestedClassNameOption(CodeGenerator.NestedClassNameOption nestedClassNameOption)final TemplategetCommentTemplate()final UnitsetCommentTemplate(Template commentTemplate)final ParsergetSchemaParser()final UnitsetSchemaParser(Parser schemaParser)final ParsergetTemplateParser()final UnitsetTemplateParser(Parser templateParser)final TemplategetTemplate()final UnitsetTemplate(Template template)final StringgetInterfaceTemplateName()final UnitsetInterfaceTemplateName(String interfaceTemplateName)final TemplategetInterfaceTemplate()final UnitsetInterfaceTemplate(Template interfaceTemplate)final TemplategetEnumTemplateField()final UnitsetEnumTemplateField(Template enumTemplateField)final TemplategetEnumTemplate()final UnitsetEnumTemplate(Template enumTemplate)final TargetFileNamegetIndexFileName()final UnitsetIndexFileName(TargetFileName indexFileName)final StringgetIndexTemplateName()final UnitsetIndexTemplateName(String indexTemplateName)final TemplategetIndexTemplateField()final UnitsetIndexTemplateField(Template indexTemplateField)final TemplategetIndexTemplate()final UnitsetIndexTemplate(Template indexTemplate)final Function1<TargetFileName, Writer>getOutputResolverField()final UnitsetOutputResolverField(Function1<TargetFileName, Writer> outputResolverField)final Function1<TargetFileName, Writer>getOutputResolver()final UnitsetOutputResolver(Function1<TargetFileName, Writer> outputResolver)final IntegergetNumTargets()final TargetLanguagegetTargetLanguage()Target language final UnitsetTargetLanguage(TargetLanguage targetLanguage)Target language final StringgetTemplateName()The primary template to use for the generation of a class final UnitsetTemplateName(String templateName)The primary template to use for the generation of a class final StringgetEnumTemplateName()The primary template to use for the generation of an enum final UnitsetEnumTemplateName(String enumTemplateName)The primary template to use for the generation of an enum final StringgetBasePackageName()The base package name for the generated classes final UnitsetBasePackageName(String basePackageName)The base package name for the generated classes final StringgetBaseDirectoryName()The base output directory for generated files final UnitsetBaseDirectoryName(String baseDirectoryName)The base output directory for generated files final BooleangetDerivePackageFromStructure()A boolean flag to indicate the schema files in subdirectories are to be output to sub-packages final UnitsetDerivePackageFromStructure(Boolean derivePackageFromStructure)A boolean flag to indicate the schema files in subdirectories are to be output to sub-packages final StringgetGeneratorComment()A comment to add to the header of generated files final UnitsetGeneratorComment(String generatorComment)A comment to add to the header of generated files final ClassIdgetMarkerInterface()An optional marker interface to add to each generated class final UnitsetMarkerInterface(ClassId markerInterface)An optional marker interface to add to each generated class final LoggergetLog()A Logger object for the output of logging messages final UnitaddClassNameMapping(URI uri, String name)final UnitsetTemplateDirectory(File directory, String suffix)final Unitconfigure(File file, URI uri)Configure the CodeGeneratorusing a config file, specified by a File.final Unitconfigure(Path path, URI uri)Configure the CodeGeneratorusing a config file, specified by a Path.final Unitconfigure(JSONValue json, URI uri)Configure the CodeGeneratorusing a config file (in the form af a parsed JSON object).final UnitclearTargets()Clear the target list. final UnitaddTarget(JSONSchema schema, String className, List<String> subDirectories, String source, JSONValue json)Add a target using the supplied details. final UnitaddTarget(URI uri)Add a target by URI. final Unitgenerate(URI inputs)Generate classes for a set of schema files specified by URI. final Unitgenerate(File inputFiles)Generate classes for a set of schema files (specified as a varargarray).final Unitgenerate(List<File> inputFiles)Generate classes for a set of files (specified as a List). final UnitaddTargets(List<File> inputFiles)Add targets for a set of files (specified as a List). final UnitgenerateFromPaths(Path inputPaths)Generate classes for a set of schema files (specified as a varargarray of Path).final UnitgenerateFromPaths(List<Path> inputPaths)Generate classes for a set of files (specified as a List of Path). final UnitaddTargetsByPath(List<Path> inputPaths)Add targets for a set of files (specified as a List of Path). final UnitgenerateAllTargets()Generate all targets added to the target list. final UnitgenerateClass(JSONSchema schema, String className, List<String> subDirectories, JSONValue json)Generate a single class. final UnitgenerateClasses(List<Pair<JSONSchema, String>> schemaList, List<String> subDirectories, JSONValue json, Function1<String, String> logCommentFunction)Generate classes as specified by a list of pairs - Schema and class name. final UnitgenerateAll(JSONValue base, JSONPointer pointer, List<String> subDirectories, URI uri, Function1<String, Boolean> filter)Generate classes for all definitions in a composite file (e.g. final UnitaddCompositeTargets(URI uri, JSONPointer pointer, Function1<String, Boolean> filter)Add targets for all definitions in a composite file (e.g. final UnitaddCompositeTargets(JSONValue base, JSONPointer pointer, List<String> subDirectories, URI uri, Function1<String, Boolean> filter)Add targets for all definitions in a composite file (e.g. final UnitaddCustomClassByURI(URI uri, String qualifiedClassName)final UnitaddCustomClassByURI(URI uri, String className, String packageName)final UnitaddCustomClassByURI(URI uri, ClassId classId)final UnitaddCustomClassByFormat(String name, String qualifiedClassName)final UnitaddCustomClassByFormat(String name, String className, String packageName)final UnitaddCustomClassByFormat(String name, ClassId classId)final UnitaddCustomClassByExtension(String extensionId, Object extensionValue, String qualifiedClassName)final UnitaddCustomClassByExtension(String extensionId, Object extensionValue, String className, String packageName)final UnitaddCustomClassByExtension(String extensionId, Object extensionValue, ClassId classId)-
-
Method Detail
-
getNestedClassNameOption
final CodeGenerator.NestedClassNameOption getNestedClassNameOption()
-
setNestedClassNameOption
final Unit setNestedClassNameOption(CodeGenerator.NestedClassNameOption nestedClassNameOption)
-
getCommentTemplate
final Template getCommentTemplate()
-
setCommentTemplate
final Unit setCommentTemplate(Template commentTemplate)
-
getSchemaParser
final Parser getSchemaParser()
-
setSchemaParser
final Unit setSchemaParser(Parser schemaParser)
-
getTemplateParser
final Parser getTemplateParser()
-
setTemplateParser
final Unit setTemplateParser(Parser templateParser)
-
getTemplate
final Template getTemplate()
-
setTemplate
final Unit setTemplate(Template template)
-
getInterfaceTemplateName
final String getInterfaceTemplateName()
-
setInterfaceTemplateName
final Unit setInterfaceTemplateName(String interfaceTemplateName)
-
getInterfaceTemplate
final Template getInterfaceTemplate()
-
setInterfaceTemplate
final Unit setInterfaceTemplate(Template interfaceTemplate)
-
getEnumTemplateField
final Template getEnumTemplateField()
-
setEnumTemplateField
final Unit setEnumTemplateField(Template enumTemplateField)
-
getEnumTemplate
final Template getEnumTemplate()
-
setEnumTemplate
final Unit setEnumTemplate(Template enumTemplate)
-
getIndexFileName
final TargetFileName getIndexFileName()
-
setIndexFileName
final Unit setIndexFileName(TargetFileName indexFileName)
-
getIndexTemplateName
final String getIndexTemplateName()
-
setIndexTemplateName
final Unit setIndexTemplateName(String indexTemplateName)
-
getIndexTemplateField
final Template getIndexTemplateField()
-
setIndexTemplateField
final Unit setIndexTemplateField(Template indexTemplateField)
-
getIndexTemplate
final Template getIndexTemplate()
-
setIndexTemplate
final Unit setIndexTemplate(Template indexTemplate)
-
getOutputResolverField
final Function1<TargetFileName, Writer> getOutputResolverField()
-
setOutputResolverField
final Unit setOutputResolverField(Function1<TargetFileName, Writer> outputResolverField)
-
getOutputResolver
final Function1<TargetFileName, Writer> getOutputResolver()
-
setOutputResolver
final Unit setOutputResolver(Function1<TargetFileName, Writer> outputResolver)
-
getNumTargets
final Integer getNumTargets()
-
getTargetLanguage
final TargetLanguage getTargetLanguage()
Target language
-
setTargetLanguage
final Unit setTargetLanguage(TargetLanguage targetLanguage)
Target language
-
getTemplateName
final String getTemplateName()
The primary template to use for the generation of a class
-
setTemplateName
final Unit setTemplateName(String templateName)
The primary template to use for the generation of a class
-
getEnumTemplateName
final String getEnumTemplateName()
The primary template to use for the generation of an enum
-
setEnumTemplateName
final Unit setEnumTemplateName(String enumTemplateName)
The primary template to use for the generation of an enum
-
getBasePackageName
final String getBasePackageName()
The base package name for the generated classes
-
setBasePackageName
final Unit setBasePackageName(String basePackageName)
The base package name for the generated classes
-
getBaseDirectoryName
final String getBaseDirectoryName()
The base output directory for generated files
-
setBaseDirectoryName
final Unit setBaseDirectoryName(String baseDirectoryName)
The base output directory for generated files
-
getDerivePackageFromStructure
final Boolean getDerivePackageFromStructure()
A boolean flag to indicate the schema files in subdirectories are to be output to sub-packages
-
setDerivePackageFromStructure
final Unit setDerivePackageFromStructure(Boolean derivePackageFromStructure)
A boolean flag to indicate the schema files in subdirectories are to be output to sub-packages
-
getGeneratorComment
final String getGeneratorComment()
A comment to add to the header of generated files
-
setGeneratorComment
final Unit setGeneratorComment(String generatorComment)
A comment to add to the header of generated files
-
getMarkerInterface
final ClassId getMarkerInterface()
An optional marker interface to add to each generated class
-
setMarkerInterface
final Unit setMarkerInterface(ClassId markerInterface)
An optional marker interface to add to each generated class
-
getLog
final Logger getLog()
A Logger object for the output of logging messages
-
addClassNameMapping
final Unit addClassNameMapping(URI uri, String name)
-
setTemplateDirectory
final Unit setTemplateDirectory(File directory, String suffix)
-
configure
final Unit configure(File file, URI uri)
Configure the
CodeGeneratorusing a config file, specified by a File.- Parameters:
file- a File pointing to the JSON or YAML config fileuri- an optional URI (for error reporting)
-
configure
final Unit configure(Path path, URI uri)
Configure the
CodeGeneratorusing a config file, specified by a Path.- Parameters:
path- the Path to the JSON or YAML config fileuri- an optional URI (for error reporting)
-
configure
final Unit configure(JSONValue json, URI uri)
Configure the
CodeGeneratorusing a config file (in the form af a parsed JSON object).- Parameters:
json- the JSON objecturi- an optional URI (for error reporting)
-
clearTargets
final Unit clearTargets()
Clear the target list.
-
addTarget
final Unit addTarget(JSONSchema schema, String className, List<String> subDirectories, String source, JSONValue json)
Add a target using the supplied details.
- Parameters:
schema- the JSON schemaclassName- the class name to use for the generated classsubDirectories- the subdirectory names to use for package name determinationsource- an optional source comment stringjson- original JSON (for template expansion)
-
generate
final Unit generate(URI inputs)
Generate classes for a set of schema files specified by URI.
-
generate
final Unit generate(File inputFiles)
Generate classes for a set of schema files (specified as a
varargarray). Directories will be traversed recursively.- Parameters:
inputFiles- the files
-
generate
final Unit generate(List<File> inputFiles)
Generate classes for a set of files (specified as a List). Directories will be traversed recursively.
- Parameters:
inputFiles- the list of files
-
addTargets
final Unit addTargets(List<File> inputFiles)
Add targets for a set of files (specified as a List). Directories will be traversed recursively.
- Parameters:
inputFiles- the list of files
-
generateFromPaths
final Unit generateFromPaths(Path inputPaths)
Generate classes for a set of schema files (specified as a
varargarray of Path). Directories will be traversed recursively.- Parameters:
inputPaths- the files
-
generateFromPaths
final Unit generateFromPaths(List<Path> inputPaths)
Generate classes for a set of files (specified as a List of Path). Directories will be traversed recursively.
- Parameters:
inputPaths- the list of files
-
addTargetsByPath
final Unit addTargetsByPath(List<Path> inputPaths)
Add targets for a set of files (specified as a List of Path). Directories will be traversed recursively.
- Parameters:
inputPaths- the list of files
-
generateAllTargets
final Unit generateAllTargets()
Generate all targets added to the target list.
-
generateClass
final Unit generateClass(JSONSchema schema, String className, List<String> subDirectories, JSONValue json)
Generate a single class.
- Parameters:
schema- the JSONSchemaclassName- the class namesubDirectories- list of subdirectory names to use for the output filejson- original JSON (for template expansion)
-
generateClasses
final Unit generateClasses(List<Pair<JSONSchema, String>> schemaList, List<String> subDirectories, JSONValue json, Function1<String, String> logCommentFunction)
Generate classes as specified by a list of pairs - Schema and class name.
-
generateAll
final Unit generateAll(JSONValue base, JSONPointer pointer, List<String> subDirectories, URI uri, Function1<String, Boolean> filter)
Generate classes for all definitions in a composite file (e.g. schema definitions embedded in an OpenAPI or Swagger document).
- Parameters:
base- the base of the composite objectpointer- pointer to the structure containing the schema definitions (e.g.subDirectories- list of subdirectory names to use for the output filesuri- the default URI of the documentfilter- optional filter to select which classes to include (by name)
-
addCompositeTargets
final Unit addCompositeTargets(URI uri, JSONPointer pointer, Function1<String, Boolean> filter)
Add targets for all definitions in a composite file (e.g. schema definitions embedded in an OpenAPI or Swagger document) for a file located by URI.
- Parameters:
uri- the URI of the documentpointer- pointer to the structure containing the schema definitions (e.g.filter- optional filter to select which classes to include (by name)
-
addCompositeTargets
final Unit addCompositeTargets(JSONValue base, JSONPointer pointer, List<String> subDirectories, URI uri, Function1<String, Boolean> filter)
Add targets for all definitions in a composite file (e.g. schema definitions embedded in an OpenAPI or Swagger document).
- Parameters:
base- the base of the composite objectpointer- pointer to the structure containing the schema definitions (e.g.subDirectories- list of subdirectory names to use for the output filesuri- the default URI of the documentfilter- optional filter to select which classes to include (by name)
-
addCustomClassByURI
final Unit addCustomClassByURI(URI uri, String qualifiedClassName)
-
addCustomClassByURI
final Unit addCustomClassByURI(URI uri, String className, String packageName)
-
addCustomClassByURI
final Unit addCustomClassByURI(URI uri, ClassId classId)
-
addCustomClassByFormat
final Unit addCustomClassByFormat(String name, String qualifiedClassName)
-
addCustomClassByFormat
final Unit addCustomClassByFormat(String name, String className, String packageName)
-
addCustomClassByFormat
final Unit addCustomClassByFormat(String name, ClassId classId)
-
addCustomClassByExtension
final Unit addCustomClassByExtension(String extensionId, Object extensionValue, String qualifiedClassName)
-
addCustomClassByExtension
final Unit addCustomClassByExtension(String extensionId, Object extensionValue, String className, String packageName)
-
addCustomClassByExtension
final Unit addCustomClassByExtension(String extensionId, Object extensionValue, ClassId classId)
-
-
-
-