diff --git a/README.MD b/README.MD index aaadbe5..f6b25e8 100644 --- a/README.MD +++ b/README.MD @@ -22,7 +22,7 @@ Make sure you include the repository as well. com.github.qlsolutions.JavalinFly javalinfly-core - 0.1.8rc12 + 0.1.8rc13 ``` @@ -37,7 +37,7 @@ Make sure you include the repository as well. com.github.qlsolutions.JavalinFly javalinfly-core - 0.1.8rc12 + 0.1.8rc13 @@ -51,7 +51,7 @@ Make sure you include the repository as well. com.github.qlsolutions.JavalinFly javalinfly-kotlin - 0.1.8rc12 + 0.1.8rc13 ``` @@ -69,20 +69,20 @@ Make sure you include the repository as well. - Dependency ```groovy - implementation 'com.github.qlsolutions.JavalinFly:javalinfly-core:0.1.8rc12' + implementation 'com.github.qlsolutions.JavalinFly:javalinfly-core:0.1.8rc13' ``` - Annotation processor ```groovy - annotationProcessor 'com.github.qlsolutions.JavalinFly:javalinfly-core:0.1.8rc12' + annotationProcessor 'com.github.qlsolutions.JavalinFly:javalinfly-core:0.1.8rc13' ``` -
Optionally also the kotlin module ```groovy - implementation 'com.github.qlsolutions.JavalinFly:javalinfly-kotlin:0.1.8rc12' + implementation 'com.github.qlsolutions.JavalinFly:javalinfly-kotlin:0.1.8rc13' ```
@@ -93,19 +93,19 @@ Make sure you include the repository as well. - Dependency ```groovy - implementation("com.github.qlsolutions.JavalinFly:javalinfly-core:0.1.8rc12") + implementation("com.github.qlsolutions.JavalinFly:javalinfly-core:0.1.8rc13") ``` - Annotation processor ```groovy - annotationProcessor("com.github.qlsolutions.JavalinFly:javalinfly-core:0.1.8rc12") + annotationProcessor("com.github.qlsolutions.JavalinFly:javalinfly-core:0.1.8rc13") ``` -
Optionally also the kotlin module ```groovy - implementation("com.github.qlsolutions.JavalinFly:javalinfly-kotlin:0.1.8rc12") + implementation("com.github.qlsolutions.JavalinFly:javalinfly-kotlin:0.1.8rc13") ```
diff --git a/javalinfly-core/pom.xml b/javalinfly-core/pom.xml index 2f09ee9..8d25f46 100644 --- a/javalinfly-core/pom.xml +++ b/javalinfly-core/pom.xml @@ -6,7 +6,7 @@ com.github.unldenis JavalinFly - 0.1.8rc12 + 0.1.8rc13 javalinfly-core diff --git a/javalinfly-core/src/main/java/com/quicklink/javalinfly/Vars.java b/javalinfly-core/src/main/java/com/quicklink/javalinfly/Vars.java index 5035a61..e2ee2a7 100644 --- a/javalinfly-core/src/main/java/com/quicklink/javalinfly/Vars.java +++ b/javalinfly-core/src/main/java/com/quicklink/javalinfly/Vars.java @@ -1,13 +1,15 @@ package com.quicklink.javalinfly; import com.quicklink.javalinfly.openapi.SwaggerUIHtmlGenerator; +import com.quicklink.javalinfly.processor.utils.ResourceUtil; + public class Vars { public static final String RESOURCE_FILE_SPEC = "openapiSpec.json"; public static String openApiSpec() { - return SwaggerUIHtmlGenerator.readResourceFile(RESOURCE_FILE_SPEC); + return ResourceUtil.readResourceFile(RESOURCE_FILE_SPEC); } private static String SWAGGER_UI = null; diff --git a/javalinfly-core/src/main/java/com/quicklink/javalinfly/openapi/SwaggerUIHtmlGenerator.java b/javalinfly-core/src/main/java/com/quicklink/javalinfly/openapi/SwaggerUIHtmlGenerator.java index eed52ee..ece5879 100644 --- a/javalinfly-core/src/main/java/com/quicklink/javalinfly/openapi/SwaggerUIHtmlGenerator.java +++ b/javalinfly-core/src/main/java/com/quicklink/javalinfly/openapi/SwaggerUIHtmlGenerator.java @@ -4,6 +4,7 @@ import com.goterl.resourceloader.FileLoader; import com.quicklink.javalinfly.JavalinFly; +import com.quicklink.javalinfly.processor.utils.ResourceUtil; import java.io.IOException; import java.io.UncheckedIOException; import java.net.URISyntaxException; @@ -11,21 +12,14 @@ public class SwaggerUIHtmlGenerator { - public static String readResourceFile(String fileName) { - try { - var file = FileLoader.get().load(fileName, JavalinFly.class); - return Files.readString(file.toPath()); - } catch (IOException e) { - throw new UncheckedIOException(e); - } catch (URISyntaxException e) { - throw new RuntimeException(e); - } - } + public static String generateSwaggerUIHtml(String openApiJson) { - String swaggerUiCss = readResourceFile("swagger-ui.css"); - String swaggerUiBundleJs = readResourceFile("swagger-ui-bundle.js"); - String swaggerUiStandalonePresetJs = readResourceFile("swagger-ui-standalone-preset.js"); + String swaggerUiCss = ResourceUtil.readResourceFile("swagger-ui.css"); + String swaggerUiBundleJs = ResourceUtil.readResourceFile( + "swagger-ui-bundle.js"); + String swaggerUiStandalonePresetJs = ResourceUtil.readResourceFile( + "swagger-ui-standalone-preset.js"); StringBuilder swaggerUiTemplate = new StringBuilder() .append("\n") diff --git a/javalinfly-core/src/main/java/com/quicklink/javalinfly/processor/utils/ResourceUtil.java b/javalinfly-core/src/main/java/com/quicklink/javalinfly/processor/utils/ResourceUtil.java new file mode 100644 index 0000000..242a31b --- /dev/null +++ b/javalinfly-core/src/main/java/com/quicklink/javalinfly/processor/utils/ResourceUtil.java @@ -0,0 +1,28 @@ +package com.quicklink.javalinfly.processor.utils; + + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UncheckedIOException; +import java.util.stream.Collectors; + +public class ResourceUtil { + + public static String readResourceFile(String fileName) { + try (InputStream inputStream = ResourceUtil.class.getResourceAsStream( + "/" + fileName)) { + if(inputStream == null) { + throw new FileNotFoundException("Resource '%s' not found!".formatted(fileName)); + } + try (BufferedReader reader = new BufferedReader( + new InputStreamReader(inputStream))) { + return reader.lines().collect(Collectors.joining(System.lineSeparator())); + } + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } +} diff --git a/javalinfly-example-kotlin/pom.xml b/javalinfly-example-kotlin/pom.xml index 357d28b..0bed558 100644 --- a/javalinfly-example-kotlin/pom.xml +++ b/javalinfly-example-kotlin/pom.xml @@ -6,7 +6,7 @@ com.github.unldenis JavalinFly - 0.1.8rc12 + 0.1.8rc13 javalinfly-example-kotlin diff --git a/javalinfly-example/pom.xml b/javalinfly-example/pom.xml index 989e908..fae70b2 100644 --- a/javalinfly-example/pom.xml +++ b/javalinfly-example/pom.xml @@ -6,7 +6,7 @@ com.github.unldenis JavalinFly - 0.1.8rc12 + 0.1.8rc13 javalinfly-example diff --git a/javalinfly-kotlin/pom.xml b/javalinfly-kotlin/pom.xml index 304a68e..61ea944 100644 --- a/javalinfly-kotlin/pom.xml +++ b/javalinfly-kotlin/pom.xml @@ -6,7 +6,7 @@ com.github.unldenis JavalinFly - 0.1.8rc12 + 0.1.8rc13 javalinfly-kotlin diff --git a/pom.xml b/pom.xml index 78ff9d1..dc4be49 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.unldenis JavalinFly - 0.1.8rc12 + 0.1.8rc13 pom