Skip to content

Commit

Permalink
0.1.8rc13 - fixing resource loader
Browse files Browse the repository at this point in the history
  • Loading branch information
mehillid committed Jun 27, 2024
1 parent 4338018 commit bc0c428
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 28 deletions.
18 changes: 9 additions & 9 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Make sure you include the <a href="https://jitpack.io/">repository</a> as well.
<dependency>
<groupId>com.github.qlsolutions.JavalinFly</groupId>
<artifactId>javalinfly-core</artifactId>
<version>0.1.8rc12</version>
<version>0.1.8rc13</version>
</dependency>
```

Expand All @@ -37,7 +37,7 @@ Make sure you include the <a href="https://jitpack.io/">repository</a> as well.
<annotationProcessorPath>
<groupId>com.github.qlsolutions.JavalinFly</groupId>
<artifactId>javalinfly-core</artifactId>
<version>0.1.8rc12</version>
<version>0.1.8rc13</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
Expand All @@ -51,7 +51,7 @@ Make sure you include the <a href="https://jitpack.io/">repository</a> as well.
<dependency>
<groupId>com.github.qlsolutions.JavalinFly</groupId>
<artifactId>javalinfly-kotlin</artifactId>
<version>0.1.8rc12</version>
<version>0.1.8rc13</version>
</dependency>
```

Expand All @@ -69,20 +69,20 @@ Make sure you include the <a href="https://jitpack.io/">repository</a> 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'
```

- <details>
<summary>Optionally also the kotlin module</summary>

```groovy
implementation 'com.github.qlsolutions.JavalinFly:javalinfly-kotlin:0.1.8rc12'
implementation 'com.github.qlsolutions.JavalinFly:javalinfly-kotlin:0.1.8rc13'
```

</details>
Expand All @@ -93,19 +93,19 @@ Make sure you include the <a href="https://jitpack.io/">repository</a> 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")
```

- <details>
<summary>Optionally also the kotlin module</summary>

```groovy
implementation("com.github.qlsolutions.JavalinFly:javalinfly-kotlin:0.1.8rc12")
implementation("com.github.qlsolutions.JavalinFly:javalinfly-kotlin:0.1.8rc13")
```

</details>
Expand Down
2 changes: 1 addition & 1 deletion javalinfly-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.github.unldenis</groupId>
<artifactId>JavalinFly</artifactId>
<version>0.1.8rc12</version>
<version>0.1.8rc13</version>
</parent>

<artifactId>javalinfly-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,22 @@
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;
import java.nio.file.Files;

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("<!DOCTYPE html>\n")
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
2 changes: 1 addition & 1 deletion javalinfly-example-kotlin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.github.unldenis</groupId>
<artifactId>JavalinFly</artifactId>
<version>0.1.8rc12</version>
<version>0.1.8rc13</version>
</parent>

<artifactId>javalinfly-example-kotlin</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion javalinfly-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.github.unldenis</groupId>
<artifactId>JavalinFly</artifactId>
<version>0.1.8rc12</version>
<version>0.1.8rc13</version>
</parent>

<artifactId>javalinfly-example</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion javalinfly-kotlin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.github.unldenis</groupId>
<artifactId>JavalinFly</artifactId>
<version>0.1.8rc12</version>
<version>0.1.8rc13</version>
</parent>

<artifactId>javalinfly-kotlin</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.unldenis</groupId>
<artifactId>JavalinFly</artifactId>
<version>0.1.8rc12</version>
<version>0.1.8rc13</version>
<packaging>pom</packaging>

<modules>
Expand Down

0 comments on commit bc0c428

Please sign in to comment.