Class SourceGenerator
- Since:
- 1.3
- Author:
- Elif Kurtay
-
Constructor Summary
ConstructorsConstructorDescriptionSourceGenerator(io.micronaut.inject.visitor.VisitorContext.Language language, GeneratorContext context) Constructs a newSourceGeneratorinstance based on the provided programming language and the generation context.SourceGenerator(String lang) Constructs a newSourceGeneratorinstance based on the provided programming language. -
Method Summary
Modifier and TypeMethodDescriptionio.micronaut.sourcegen.model.EnumDefgenerate(SourceGeneratorConfig config) Generates source code from JSON schema files based on the provided configuration.static Stringstatic io.micronaut.inject.visitor.VisitorContext.Languagestatic Stringstatic Pathstatic voidsetInputFileName(String inputFileName)
-
Constructor Details
-
SourceGenerator
Constructs a newSourceGeneratorinstance based on the provided programming language.This constructor attempts to find a corresponding
SourceGeneratorimplementation for the given programming language. If no such implementation is found, aRuntimeExceptionis thrown.- Parameters:
lang- The String representing the target programming language for which the source generator is to be created. This argument cannot benull.- Throws:
RuntimeException- if no matching source generator is found for the provided language. The exception message will indicate the language for which no generator was found.
-
SourceGenerator
public SourceGenerator(io.micronaut.inject.visitor.VisitorContext.Language language, GeneratorContext context) Constructs a newSourceGeneratorinstance based on the provided programming language and the generation context.This constructor attempts to find a corresponding
SourceGeneratorimplementation for the given programming language. If no such implementation is found, aRuntimeExceptionis thrown.- Parameters:
language- TheVisitorContext.Languagerepresenting the target programming language for which the source generator is to be created. This argument cannot benull.context- TheGeneratorContextrepresenting the already existing context of generation.- Throws:
RuntimeException- if no matching source generator is found for the provided language. The exception message will indicate the language for which no generator was found.
-
-
Method Details
-
generate
Generates source code from JSON schema files based on the provided configuration.This method first checks if an
inputFolderis specified in the configuration. If theinputFolderis provided, it processes all JSON Schema in the folder to generate source code. IfinputFolderisnull, it attempts to retrieve the JSON schema from the specifiedinputStream,jsonUrl, orjsonFilein the configuration and generates code from the schema.If the
outputFileNameexists, the method generates a single source file from the schema with that file name. Otherwise, the method generates all objects defined in the schema inside the specifiedoutputPath(andoutputPackageNameif available).- Parameters:
config- TheSourceGeneratorConfigobject that contains the configuration for source code generation, including input folder, JSON schema URL, output path, output package name, and output file name.- Returns:
- The top level schema's generated File when a single input is given, null otherwise.
- Throws:
IOException- If an I/O error occurs during file or directory creation, or if an error occurs while reading or writing files.
-
buildEnum
-
getInputFileName
-
setInputFileName
-
getOutputPath
-
getOutputPackageName
-
getLanguage
public static io.micronaut.inject.visitor.VisitorContext.Language getLanguage()
-