diff --git a/buildSrc/src/main/groovy/io.micronaut.build.internal.test-suite-generator.gradle b/buildSrc/src/main/groovy/io.micronaut.build.internal.test-suite-generator.gradle index d00a269..d51c94f 100644 --- a/buildSrc/src/main/groovy/io.micronaut.build.internal.test-suite-generator.gradle +++ b/buildSrc/src/main/groovy/io.micronaut.build.internal.test-suite-generator.gradle @@ -55,6 +55,8 @@ sourceSets { main { java.srcDir(beanGenerator.map(BeanGeneratorTask::getGeneratedSourcesDirectory)) java.srcDir(foodGenerator.map(BeanGeneratorTask::getGeneratedSourcesDirectory)) + java.srcDir(githubGenerator.map(BeanGeneratorTask::getGeneratedSourcesDirectory)) + java.srcDir(fhirGenerator.map(BeanGeneratorTask::getGeneratedSourcesDirectory)) } } diff --git a/json-schema-generator/src/main/java/io/micronaut/jsonschema/generator/CodeGenerator.java b/json-schema-generator/src/main/java/io/micronaut/jsonschema/generator/CodeGenerator.java index 9d4b7d7..52f1a0f 100644 --- a/json-schema-generator/src/main/java/io/micronaut/jsonschema/generator/CodeGenerator.java +++ b/json-schema-generator/src/main/java/io/micronaut/jsonschema/generator/CodeGenerator.java @@ -274,9 +274,7 @@ private int generateDefinitions(Schema jsonSchema, Path outputPath, String packa private File generateFromSchemaMap(Schema jsonSchema, Path outputPath, String packageName, String fileName) throws IOException { try { String decidedFileName = getFileName(jsonSchema, Optional.ofNullable(fileName), language); - File outputFile = getOutputFile(outputPath, packageName, decidedFileName); - String simpleName = outputFile.getName().substring(0, outputFile.getName().lastIndexOf('.')); - String builderClassName = packageName + "." + simpleName; + String simpleName = decidedFileName.substring(0, decidedFileName.lastIndexOf('.')); // decide type of generated object boolean hasOverLimitParameters = jsonSchema.hasProperties() && jsonSchema.getProperties().size() > 255; @@ -298,12 +296,15 @@ private File generateFromSchemaMap(Schema jsonSchema, Path outputPath, String pa return null; } + File outputFile = getOutputFile(outputPath, packageName, decidedFileName); + String builderClassName = packageName + "." + simpleName; try (FileWriter writer = new FileWriter(outputFile)) { ObjectDef objectDef = switch (type) { case ENUM -> buildEnum(jsonSchema, builderClassName); case CLASS -> buildClass(jsonSchema, builderClassName); case INTERFACE -> buildInterface(jsonSchema, builderClassName); - default -> buildRecord(jsonSchema, builderClassName); + case RECORD -> buildRecord(jsonSchema, builderClassName); + default -> null; }; sourceGenerator.write(objectDef, writer); } diff --git a/json-schema-generator/src/test/groovy/io/micronaut/jsonschema/generator/SimpleGeneratorSpec.groovy b/json-schema-generator/src/test/groovy/io/micronaut/jsonschema/generator/SimpleGeneratorSpec.groovy index 38dec3e..9e68abd 100644 --- a/json-schema-generator/src/test/groovy/io/micronaut/jsonschema/generator/SimpleGeneratorSpec.groovy +++ b/json-schema-generator/src/test/groovy/io/micronaut/jsonschema/generator/SimpleGeneratorSpec.groovy @@ -12,7 +12,7 @@ class SimpleGeneratorSpec extends AbstractGeneratorSpec { { "$schema":"https://json-schema.org/draft/2020-12/schema", "$id":"https://example.com/schemas/status.schema.json", - "title":"Status", + "description":"Status für mich", "type": "string", "enum": [ "active", diff --git a/test-suite-generator/src/test/java/io/micronaut/jsonschema/generator/animals/GenerationTest.java b/test-suite-generator/src/test/java/io/micronaut/jsonschema/generator/animals/GenerationTest.java index f699aa3..184fc9b 100644 --- a/test-suite-generator/src/test/java/io/micronaut/jsonschema/generator/animals/GenerationTest.java +++ b/test-suite-generator/src/test/java/io/micronaut/jsonschema/generator/animals/GenerationTest.java @@ -3,6 +3,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -12,7 +13,7 @@ public class GenerationTest { @Test void githubGenerator() throws IOException { Path outputPath = Paths.get("build/generated/jsonSchema/java/main"); - String packageName = "io.micronaut.jsonschema.generator.github".replace(".", "/"); + String packageName = "io.micronaut.jsonschema.generator.github".replace('.', File.separatorChar); Path expectedFolderPath = outputPath.resolve(packageName); Assertions.assertTrue(Files.exists(outputPath), "Output folder path does not exist."); @@ -26,13 +27,13 @@ void githubGenerator() throws IOException { } catch (IOException e) { Assertions.fail("Failed to list files in the folder: " + e.getMessage()); } - Assertions.assertEquals(12, generatedFiles); + Assertions.assertEquals(8, generatedFiles); } @Test void fhirGenerator() throws IOException { Path outputPath = Paths.get("build/generated/jsonSchema/java/main"); - String packageName = "io.micronaut.jsonschema.generator.fhir".replace(".", "/"); + String packageName = "io.micronaut.jsonschema.generator.fhir".replace('.', File.separatorChar); Path expectedFolderPath = outputPath.resolve(packageName); Assertions.assertTrue(Files.exists(expectedFolderPath), "Expected folder path does not exist.");