Class SourceGenerator
- Since:
- 1.3
- Author:
- Elif Kurtay
-
Constructor Summary
ConstructorsConstructorDescriptionSourceGenerator
(io.micronaut.inject.visitor.VisitorContext.Language language, GeneratorContext context) Constructs a newSourceGenerator
instance based on the provided programming language and the generation context.SourceGenerator
(String lang) Constructs a newSourceGenerator
instance based on the provided programming language. -
Method Summary
Modifier and TypeMethodDescriptionio.micronaut.sourcegen.model.EnumDef
generate
(SourceGeneratorConfig config) Generates source code from JSON schema files based on the provided configuration.static String
static io.micronaut.inject.visitor.VisitorContext.Language
static String
static Path
static void
setInputFileName
(String inputFileName)
-
Constructor Details
-
SourceGenerator
Constructs a newSourceGenerator
instance based on the provided programming language.This constructor attempts to find a corresponding
SourceGenerator
implementation for the given programming language. If no such implementation is found, aRuntimeException
is 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 newSourceGenerator
instance based on the provided programming language and the generation context.This constructor attempts to find a corresponding
SourceGenerator
implementation for the given programming language. If no such implementation is found, aRuntimeException
is thrown.- Parameters:
language
- TheVisitorContext.Language
representing the target programming language for which the source generator is to be created. This argument cannot benull
.context
- TheGeneratorContext
representing 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
inputFolder
is specified in the configuration. If theinputFolder
is provided, it processes all JSON Schema in the folder to generate source code. IfinputFolder
isnull
, it attempts to retrieve the JSON schema from the specifiedinputStream
,jsonUrl
, orjsonFile
in the configuration and generates code from the schema.If the
outputFileName
exists, 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
(andoutputPackageName
if available).- Parameters:
config
- TheSourceGeneratorConfig
object 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()
-