Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
elifKurtay committed Nov 25, 2024
1 parent d98b70d commit cab9d34
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.");
Expand All @@ -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.");
Expand Down

0 comments on commit cab9d34

Please sign in to comment.