@ahmttyydn/java-integration 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/CHANGELOG.md +762 -0
  2. package/README.md +37 -0
  3. package/package.json +46 -0
  4. package/pom.xml +242 -0
  5. package/scalar-core/pom.xml +92 -0
  6. package/scalar-core/src/main/java/com/scalar/maven/core/ScalarConstants.java +26 -0
  7. package/scalar-core/src/main/java/com/scalar/maven/core/ScalarHtmlRenderer.java +135 -0
  8. package/scalar-core/src/main/java/com/scalar/maven/core/ScalarProperties.java +596 -0
  9. package/scalar-core/src/main/java/com/scalar/maven/core/authentication/ScalarAuthenticationOptions.java +235 -0
  10. package/scalar-core/src/main/java/com/scalar/maven/core/authentication/flows/AuthorizationCodeFlow.java +160 -0
  11. package/scalar-core/src/main/java/com/scalar/maven/core/authentication/flows/ClientCredentialsFlow.java +88 -0
  12. package/scalar-core/src/main/java/com/scalar/maven/core/authentication/flows/ImplicitFlow.java +64 -0
  13. package/scalar-core/src/main/java/com/scalar/maven/core/authentication/flows/OAuthFlow.java +185 -0
  14. package/scalar-core/src/main/java/com/scalar/maven/core/authentication/flows/PasswordFlow.java +134 -0
  15. package/scalar-core/src/main/java/com/scalar/maven/core/authentication/flows/ScalarFlows.java +113 -0
  16. package/scalar-core/src/main/java/com/scalar/maven/core/authentication/schemes/ScalarApiKeySecurityScheme.java +77 -0
  17. package/scalar-core/src/main/java/com/scalar/maven/core/authentication/schemes/ScalarHttpSecurityScheme.java +115 -0
  18. package/scalar-core/src/main/java/com/scalar/maven/core/authentication/schemes/ScalarOAuth2SecurityScheme.java +75 -0
  19. package/scalar-core/src/main/java/com/scalar/maven/core/authentication/schemes/ScalarSecurityScheme.java +45 -0
  20. package/scalar-core/src/main/java/com/scalar/maven/core/config/DefaultHttpClient.java +77 -0
  21. package/scalar-core/src/main/java/com/scalar/maven/core/config/ScalarAgentOptions.java +68 -0
  22. package/scalar-core/src/main/java/com/scalar/maven/core/config/ScalarServer.java +197 -0
  23. package/scalar-core/src/main/java/com/scalar/maven/core/config/ScalarSource.java +151 -0
  24. package/scalar-core/src/main/java/com/scalar/maven/core/enums/CredentialsLocation.java +52 -0
  25. package/scalar-core/src/main/java/com/scalar/maven/core/enums/DeveloperToolsVisibility.java +58 -0
  26. package/scalar-core/src/main/java/com/scalar/maven/core/enums/DocumentDownloadType.java +67 -0
  27. package/scalar-core/src/main/java/com/scalar/maven/core/enums/OperationSorter.java +52 -0
  28. package/scalar-core/src/main/java/com/scalar/maven/core/enums/OperationTitleSource.java +52 -0
  29. package/scalar-core/src/main/java/com/scalar/maven/core/enums/Pkce.java +57 -0
  30. package/scalar-core/src/main/java/com/scalar/maven/core/enums/PropertyOrder.java +53 -0
  31. package/scalar-core/src/main/java/com/scalar/maven/core/enums/ScalarClient.java +208 -0
  32. package/scalar-core/src/main/java/com/scalar/maven/core/enums/ScalarLayout.java +52 -0
  33. package/scalar-core/src/main/java/com/scalar/maven/core/enums/ScalarTarget.java +158 -0
  34. package/scalar-core/src/main/java/com/scalar/maven/core/enums/ScalarTheme.java +102 -0
  35. package/scalar-core/src/main/java/com/scalar/maven/core/enums/TagSorter.java +47 -0
  36. package/scalar-core/src/main/java/com/scalar/maven/core/enums/ThemeMode.java +52 -0
  37. package/scalar-core/src/main/java/com/scalar/maven/core/internal/ScalarConfiguration.java +425 -0
  38. package/scalar-core/src/main/java/com/scalar/maven/core/internal/ScalarConfigurationMapper.java +69 -0
  39. package/scalar-core/src/main/resources/META-INF/resources/webjars/scalar/index.html +22 -0
  40. package/scalar-core/src/test/java/com/scalar/maven/core/ScalarConfigurationTest.java +144 -0
  41. package/scalar-core/src/test/java/com/scalar/maven/core/ScalarHtmlRendererTest.java +104 -0
  42. package/scalar-core/src/test/java/com/scalar/maven/core/ScalarPropertiesTest.java +525 -0
  43. package/scalar-core/src/test/java/com/scalar/maven/core/config/DefaultHttpClientTest.java +61 -0
  44. package/scalar-core/src/test/java/com/scalar/maven/core/config/ScalarAgentOptionsTest.java +80 -0
  45. package/scalar-core/src/test/java/com/scalar/maven/core/config/ScalarServerTest.java +118 -0
  46. package/scalar-core/src/test/java/com/scalar/maven/core/config/ScalarSourceTest.java +105 -0
  47. package/scalar-playground-webflux/pom.xml +52 -0
  48. package/scalar-playground-webflux/src/main/java/com/scalar/maven/playground/CustomScalarWebFluxController.java +34 -0
  49. package/scalar-playground-webflux/src/main/java/com/scalar/maven/playground/PlaygroundApplication.java +27 -0
  50. package/scalar-playground-webflux/src/main/resources/application.properties +7 -0
  51. package/scalar-playground-webmvc/pom.xml +52 -0
  52. package/scalar-playground-webmvc/src/main/java/com/scalar/maven/playground/CustomScalarWebMvcController.java +34 -0
  53. package/scalar-playground-webmvc/src/main/java/com/scalar/maven/playground/PlaygroundApplication.java +27 -0
  54. package/scalar-playground-webmvc/src/main/resources/application.properties +7 -0
  55. package/scalar-webflux/pom.xml +110 -0
  56. package/scalar-webflux/src/main/java/com/scalar/maven/webflux/ScalarWebFluxActuatorEndpoint.java +103 -0
  57. package/scalar-webflux/src/main/java/com/scalar/maven/webflux/ScalarWebFluxAutoConfiguration.java +63 -0
  58. package/scalar-webflux/src/main/java/com/scalar/maven/webflux/ScalarWebFluxController.java +109 -0
  59. package/scalar-webflux/src/main/java/com/scalar/maven/webflux/SpringBootScalarProperties.java +43 -0
  60. package/scalar-webflux/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +2 -0
  61. package/scalar-webflux/src/test/java/com/scalar/maven/webflux/ScalarWebFluxActuatorEndpointTest.java +136 -0
  62. package/scalar-webflux/src/test/java/com/scalar/maven/webflux/ScalarWebFluxControllerTest.java +162 -0
  63. package/scalar-webmvc/pom.xml +103 -0
  64. package/scalar-webmvc/src/main/java/com/scalar/maven/webmvc/ScalarWebMvcActuatorEndpoint.java +97 -0
  65. package/scalar-webmvc/src/main/java/com/scalar/maven/webmvc/ScalarWebMvcAutoConfiguration.java +63 -0
  66. package/scalar-webmvc/src/main/java/com/scalar/maven/webmvc/ScalarWebMvcController.java +103 -0
  67. package/scalar-webmvc/src/main/java/com/scalar/maven/webmvc/SpringBootScalarProperties.java +43 -0
  68. package/scalar-webmvc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +2 -0
  69. package/scalar-webmvc/src/test/java/com/scalar/maven/webmvc/ScalarWebMvcActuatorEndpointTest.java +128 -0
  70. package/scalar-webmvc/src/test/java/com/scalar/maven/webmvc/ScalarWebMvcControllerTest.java +154 -0
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ <!--
2
+ This file is auto-generated by the Scalar README generator.
3
+ Command: pnpm --filter @scalar-internal/build-scripts start generate-readme
4
+
5
+ Do not edit this file manually. Changes will be lost when the file is regenerated.
6
+ -->
7
+
8
+ # Scalar API Reference for Java
9
+
10
+ [![Version](https://img.shields.io/maven-central/v/com.scalar.maven/scalar-core.svg)](https://central.sonatype.com/artifact/com.scalar.maven/scalar-core)
11
+ [![Discord](https://img.shields.io/discord/1135330207960678410?style=flat&color=5865F2)](https://discord.gg/scalar)
12
+
13
+ Scalar API Reference Java integrations for Spring Boot
14
+
15
+ ## Documentation
16
+
17
+ [Read the documentation here](https://scalar.com/products/api-references/integrations/java)
18
+
19
+ ### Available Packages
20
+
21
+ This integration provides three Maven packages:
22
+
23
+ - `com.scalar.maven:scalar-core` - Core framework-agnostic module for Scalar API Reference
24
+ - `com.scalar.maven:scalar-webmvc` - Spring Boot WebMVC integration for Scalar API Reference
25
+ - `com.scalar.maven:scalar-webflux` - Spring Boot WebFlux integration for Scalar API Reference
26
+
27
+ ## Changelog
28
+
29
+ See [CHANGELOG.md](https://github.com/scalar/scalar/blob/main/integrations/java/CHANGELOG.md) for a list of changes.
30
+
31
+ ## Community
32
+
33
+ We are API nerds. You too? Let’s chat on Discord: <https://discord.gg/scalar>
34
+
35
+ ## License
36
+
37
+ The source code in this repository is licensed under [MIT](https://github.com/scalar/scalar/blob/main/LICENSE).
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@ahmttyydn/java-integration",
3
+ "description": "Scalar API Reference Java integrations for Spring Boot",
4
+ "license": "MIT",
5
+ "author": "Scalar (https://github.com/scalar)",
6
+ "homepage": "https://github.com/scalar/scalar",
7
+ "bugs": "https://github.com/scalar/scalar/issues/new/choose",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/scalar/scalar.git",
11
+ "directory": "integrations/java"
12
+ },
13
+ "version": "1.0.1",
14
+ "private": false,
15
+ "engines": {
16
+ "node": ">=22"
17
+ },
18
+ "scripts": {
19
+ "build": "command -v mvn >/dev/null 2>&1 && pnpm copy:standalone && mvn clean package -Dgpg.skip=true || echo '⚠️ Maven is not available or the build failed, ignoring it.'",
20
+ "copy:standalone": "shx cp ../../packages/api-reference/dist/browser/standalone.js ./scalar-core/src/main/resources/META-INF/resources/webjars/scalar/scalar.js",
21
+ "mvn:install": "command -v mvn >/dev/null 2>&1 && pnpm copy:standalone && mvn clean install -Dgpg.skip=true || echo '⚠️ Maven is not available or the build failed, ignoring it.'",
22
+ "mvn:run:webflux": "cd scalar-playground-webflux && mvn spring-boot:run",
23
+ "mvn:run:webmvc": "cd scalar-playground-webmvc && mvn spring-boot:run",
24
+ "update:version": "mvn versions:set -DnewVersion=$npm_package_version -DgenerateBackupPoms=false"
25
+ },
26
+ "readme": {
27
+ "title": "Scalar API Reference for Java",
28
+ "badges": [
29
+ {
30
+ "type": "maven-central-version",
31
+ "package": "com.scalar.maven/scalar-core"
32
+ }
33
+ ],
34
+ "documentation": "https://scalar.com/products/api-references/integrations/java",
35
+ "extraContent": {
36
+ "headline": "Available Packages",
37
+ "content": "This integration provides three Maven packages:\n\n- `com.scalar.maven:scalar-core` - Core framework-agnostic module for Scalar API Reference\n- `com.scalar.maven:scalar-webmvc` - Spring Boot WebMVC integration for Scalar API Reference\n- `com.scalar.maven:scalar-webflux` - Spring Boot WebFlux integration for Scalar API Reference"
38
+ }
39
+ },
40
+ "dependencies": {
41
+ "@ahmttyydn/api-reference": "workspace:*"
42
+ },
43
+ "devDependencies": {
44
+ "@ahmttyydn/snippetz": "workspace:*"
45
+ }
46
+ }
package/pom.xml ADDED
@@ -0,0 +1,242 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
3
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5
+ http://maven.apache.org/xsd/maven-4.0.0.xsd">
6
+ <modelVersion>4.0.0</modelVersion>
7
+
8
+ <!-- Don't touch this, this is our verified namespace in the Maven Central Repository. -->
9
+ <groupId>com.scalar.maven</groupId>
10
+ <artifactId>scalar-parent</artifactId>
11
+ <!-- This will replaced with the version from the package.json right before release. -->
12
+ <!-- Just keep it 0.0.0, don't touch it. -->
13
+ <version>0.0.0</version>
14
+ <packaging>pom</packaging>
15
+
16
+ <name>Scalar API Reference Parent</name>
17
+ <description>Parent POM for Scalar API Reference Java integrations</description>
18
+ <url>https://github.com/scalar/scalar</url>
19
+
20
+ <licenses>
21
+ <license>
22
+ <name>MIT License</name>
23
+ <url>https://opensource.org/licenses/MIT</url>
24
+ <distribution>repo</distribution>
25
+ </license>
26
+ </licenses>
27
+
28
+ <developers>
29
+ <developer>
30
+ <id>scalar</id>
31
+ <!-- Don't touch this, it needs to match the GPG Key (Scalar <support@scalar.com>) -->
32
+ <name>Scalar</name>
33
+ <!-- Don't touch this, it needs to match the GPG Key (Scalar <support@scalar.com>) -->
34
+ <email>support@scalar.com</email>
35
+ </developer>
36
+ </developers>
37
+
38
+ <scm>
39
+ <url>https://github.com/scalar/scalar</url>
40
+ <connection>scm:git:https://github.com/scalar/scalar.git</connection>
41
+ <developerConnection>scm:git:git@github.com/scalar/scalar.git</developerConnection>
42
+ </scm>
43
+
44
+ <distributionManagement>
45
+ <repository>
46
+ <id>central</id>
47
+ <name>Maven Central Release Repository</name>
48
+ <url>https://central.sonatype.com/api/v1/publish</url>
49
+ </repository>
50
+ </distributionManagement>
51
+
52
+ <modules>
53
+ <module>scalar-core</module>
54
+ <module>scalar-webmvc</module>
55
+ <module>scalar-webflux</module>
56
+ <module>scalar-playground-webmvc</module>
57
+ <module>scalar-playground-webflux</module>
58
+ </modules>
59
+
60
+ <properties>
61
+ <java.version>17</java.version>
62
+ <maven.compiler.release>17</maven.compiler.release>
63
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
64
+ <gpg.skip>false</gpg.skip>
65
+ </properties>
66
+
67
+ <dependencyManagement>
68
+ <dependencies>
69
+ <!-- Spring Boot BOM -->
70
+ <dependency>
71
+ <groupId>org.springframework.boot</groupId>
72
+ <artifactId>spring-boot-dependencies</artifactId>
73
+ <version>3.5.7</version>
74
+ <type>pom</type>
75
+ <scope>import</scope>
76
+ </dependency>
77
+ </dependencies>
78
+ </dependencyManagement>
79
+
80
+ <build>
81
+ <pluginManagement>
82
+ <plugins>
83
+ <!-- Maven Compiler Plugin -->
84
+ <plugin>
85
+ <groupId>org.apache.maven.plugins</groupId>
86
+ <artifactId>maven-compiler-plugin</artifactId>
87
+ <version>3.15.0</version>
88
+ <configuration>
89
+ <release>17</release>
90
+ <encoding>UTF-8</encoding>
91
+ </configuration>
92
+ </plugin>
93
+
94
+ <!-- Surefire plugin for running tests -->
95
+ <plugin>
96
+ <groupId>org.apache.maven.plugins</groupId>
97
+ <artifactId>maven-surefire-plugin</artifactId>
98
+ <version>3.5.5</version>
99
+ <configuration>
100
+ <argLine>-XX:+EnableDynamicAgentLoading</argLine>
101
+ </configuration>
102
+ </plugin>
103
+
104
+ <!-- Source JAR -->
105
+ <plugin>
106
+ <groupId>org.apache.maven.plugins</groupId>
107
+ <artifactId>maven-source-plugin</artifactId>
108
+ <version>3.4.0</version>
109
+ <executions>
110
+ <execution>
111
+ <id>attach-sources</id>
112
+ <phase>verify</phase>
113
+ <goals>
114
+ <goal>jar</goal>
115
+ </goals>
116
+ </execution>
117
+ </executions>
118
+ </plugin>
119
+
120
+ <!-- Javadoc JAR -->
121
+ <plugin>
122
+ <groupId>org.apache.maven.plugins</groupId>
123
+ <artifactId>maven-javadoc-plugin</artifactId>
124
+ <version>3.12.0</version>
125
+ <executions>
126
+ <execution>
127
+ <id>generate-javadoc</id>
128
+ <phase>compile</phase>
129
+ <goals>
130
+ <goal>javadoc</goal>
131
+ </goals>
132
+ </execution>
133
+ <execution>
134
+ <id>attach-javadocs</id>
135
+ <phase>verify</phase>
136
+ <goals>
137
+ <goal>jar</goal>
138
+ </goals>
139
+ </execution>
140
+ </executions>
141
+ <configuration>
142
+ <release>17</release>
143
+ <encoding>UTF-8</encoding>
144
+ <doclint>none</doclint>
145
+ <failOnError>true</failOnError>
146
+ </configuration>
147
+ </plugin>
148
+
149
+ <!-- GPG Signing -->
150
+ <plugin>
151
+ <groupId>org.apache.maven.plugins</groupId>
152
+ <artifactId>maven-gpg-plugin</artifactId>
153
+ <version>3.2.8</version>
154
+ <executions>
155
+ <execution>
156
+ <id>sign-artifacts</id>
157
+ <phase>verify</phase>
158
+ <goals>
159
+ <goal>sign</goal>
160
+ </goals>
161
+ </execution>
162
+ </executions>
163
+ </plugin>
164
+
165
+ <!-- Required for Maven Central publishing -->
166
+ <plugin>
167
+ <groupId>org.sonatype.central</groupId>
168
+ <artifactId>central-publishing-maven-plugin</artifactId>
169
+ <version>0.10.0</version>
170
+ <extensions>true</extensions>
171
+ <configuration>
172
+ <publishingServerId>central</publishingServerId>
173
+ <autoPublish>true</autoPublish>
174
+ </configuration>
175
+ </plugin>
176
+
177
+ <!-- Maven Clean Plugin -->
178
+ <plugin>
179
+ <groupId>org.apache.maven.plugins</groupId>
180
+ <artifactId>maven-clean-plugin</artifactId>
181
+ <version>3.5.0</version>
182
+ <configuration>
183
+ <filesets>
184
+ <fileset>
185
+ <directory>${project.build.directory}</directory>
186
+ <includes>
187
+ <include>**/*</include>
188
+ </includes>
189
+ <followSymlinks>false</followSymlinks>
190
+ </fileset>
191
+ </filesets>
192
+ </configuration>
193
+ </plugin>
194
+
195
+ <!-- Skip deploying the parent POM to Maven Central -->
196
+ <plugin>
197
+ <groupId>org.apache.maven.plugins</groupId>
198
+ <artifactId>maven-deploy-plugin</artifactId>
199
+ <version>3.1.4</version>
200
+ <configuration>
201
+ <skip>true</skip>
202
+ </configuration>
203
+ </plugin>
204
+
205
+ <!-- Spring Boot Maven Plugin -->
206
+ <plugin>
207
+ <groupId>org.springframework.boot</groupId>
208
+ <artifactId>spring-boot-maven-plugin</artifactId>
209
+ <version>3.5.7</version>
210
+ </plugin>
211
+
212
+ <!-- Flatten to publish effective POMs without deploying the parent -->
213
+ <plugin>
214
+ <groupId>org.codehaus.mojo</groupId>
215
+ <artifactId>flatten-maven-plugin</artifactId>
216
+ <version>1.7.3</version>
217
+ <configuration>
218
+ <flattenMode>oss</flattenMode>
219
+ <updatePomFile>true</updatePomFile>
220
+ </configuration>
221
+ <executions>
222
+ <execution>
223
+ <id>flatten</id>
224
+ <phase>process-resources</phase>
225
+ <goals>
226
+ <goal>flatten</goal>
227
+ </goals>
228
+ </execution>
229
+ <execution>
230
+ <id>flatten-clean</id>
231
+ <phase>clean</phase>
232
+ <goals>
233
+ <goal>clean</goal>
234
+ </goals>
235
+ </execution>
236
+ </executions>
237
+ </plugin>
238
+ </plugins>
239
+ </pluginManagement>
240
+ </build>
241
+ </project>
242
+
@@ -0,0 +1,92 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
3
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5
+ http://maven.apache.org/xsd/maven-4.0.0.xsd">
6
+ <modelVersion>4.0.0</modelVersion>
7
+
8
+ <parent>
9
+ <groupId>com.scalar.maven</groupId>
10
+ <artifactId>scalar-parent</artifactId>
11
+ <version>0.0.0</version>
12
+ </parent>
13
+
14
+ <artifactId>scalar-core</artifactId>
15
+ <packaging>jar</packaging>
16
+
17
+ <name>Scalar API Reference Core</name>
18
+ <description>Core framework-agnostic module for Scalar API Reference</description>
19
+
20
+ <dependencies>
21
+ <!-- Jackson for JSON serialization -->
22
+ <dependency>
23
+ <groupId>com.fasterxml.jackson.core</groupId>
24
+ <artifactId>jackson-databind</artifactId>
25
+ </dependency>
26
+
27
+ <!-- Test Dependencies -->
28
+ <dependency>
29
+ <groupId>org.junit.jupiter</groupId>
30
+ <artifactId>junit-jupiter</artifactId>
31
+ <scope>test</scope>
32
+ </dependency>
33
+
34
+ <dependency>
35
+ <groupId>org.mockito</groupId>
36
+ <artifactId>mockito-core</artifactId>
37
+ <scope>test</scope>
38
+ </dependency>
39
+
40
+ <dependency>
41
+ <groupId>org.mockito</groupId>
42
+ <artifactId>mockito-junit-jupiter</artifactId>
43
+ <scope>test</scope>
44
+ </dependency>
45
+
46
+ <dependency>
47
+ <groupId>org.assertj</groupId>
48
+ <artifactId>assertj-core</artifactId>
49
+ <scope>test</scope>
50
+ </dependency>
51
+ </dependencies>
52
+
53
+ <build>
54
+ <plugins>
55
+ <plugin>
56
+ <groupId>org.codehaus.mojo</groupId>
57
+ <artifactId>flatten-maven-plugin</artifactId>
58
+ </plugin>
59
+
60
+ <plugin>
61
+ <groupId>org.apache.maven.plugins</groupId>
62
+ <artifactId>maven-compiler-plugin</artifactId>
63
+ </plugin>
64
+
65
+ <plugin>
66
+ <groupId>org.apache.maven.plugins</groupId>
67
+ <artifactId>maven-surefire-plugin</artifactId>
68
+ </plugin>
69
+
70
+ <plugin>
71
+ <groupId>org.apache.maven.plugins</groupId>
72
+ <artifactId>maven-source-plugin</artifactId>
73
+ </plugin>
74
+
75
+ <plugin>
76
+ <groupId>org.apache.maven.plugins</groupId>
77
+ <artifactId>maven-javadoc-plugin</artifactId>
78
+ </plugin>
79
+
80
+ <plugin>
81
+ <groupId>org.apache.maven.plugins</groupId>
82
+ <artifactId>maven-gpg-plugin</artifactId>
83
+ </plugin>
84
+
85
+ <plugin>
86
+ <groupId>org.sonatype.central</groupId>
87
+ <artifactId>central-publishing-maven-plugin</artifactId>
88
+ </plugin>
89
+ </plugins>
90
+ </build>
91
+ </project>
92
+
@@ -0,0 +1,26 @@
1
+ package com.scalar.maven.core;
2
+
3
+ /**
4
+ * Constants used across the Scalar Java integration.
5
+ * <p>
6
+ * This class provides shared constants to avoid duplication across different
7
+ * modules and classes.
8
+ * </p>
9
+ */
10
+ public final class ScalarConstants {
11
+
12
+ /**
13
+ * The default path where the Scalar API Reference interface is available.
14
+ */
15
+ public static final String DEFAULT_PATH = "/scalar";
16
+
17
+ /**
18
+ * The filename of the JavaScript bundle for the Scalar API Reference.
19
+ */
20
+ public static final String JS_FILENAME = "scalar.js";
21
+
22
+ private ScalarConstants() {
23
+ // Utility class - prevent instantiation
24
+ }
25
+ }
26
+
@@ -0,0 +1,135 @@
1
+ package com.scalar.maven.core;
2
+
3
+ import com.fasterxml.jackson.core.JsonProcessingException;
4
+ import com.fasterxml.jackson.databind.ObjectMapper;
5
+ import com.scalar.maven.core.internal.ScalarConfiguration;
6
+ import com.scalar.maven.core.internal.ScalarConfigurationMapper;
7
+
8
+ import java.io.IOException;
9
+ import java.io.InputStream;
10
+ import java.nio.charset.StandardCharsets;
11
+ import java.util.Objects;
12
+
13
+ /**
14
+ * Static utility class for rendering HTML content for the Scalar API Reference interface.
15
+ *
16
+ * <p>
17
+ * This class is framework-agnostic and provides the core HTML rendering
18
+ * functionality. It loads the HTML template, serializes the configuration to JSON,
19
+ * and replaces placeholders with actual values.
20
+ * </p>
21
+ */
22
+ public final class ScalarHtmlRenderer {
23
+
24
+ private static final String HTML_TEMPLATE_PATH = "/META-INF/resources/webjars/scalar/index.html";
25
+ private static final String JS_BUNDLE_PATH = "/META-INF/resources/webjars/scalar/" + ScalarConstants.JS_FILENAME;
26
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
27
+
28
+ private ScalarHtmlRenderer() {
29
+ // Utility class - prevent instantiation
30
+ }
31
+
32
+ /**
33
+ * Normalizes the base path by returning the default path if the provided
34
+ * base path is null or empty.
35
+ *
36
+ * @param basePath the base path to normalize
37
+ * @return the normalized base path, or {@link ScalarConstants#DEFAULT_PATH} if null or empty
38
+ */
39
+ private static String normalizeBasePath(String basePath) {
40
+ if (basePath == null || basePath.isEmpty()) {
41
+ return ScalarConstants.DEFAULT_PATH;
42
+ }
43
+ return basePath;
44
+ }
45
+
46
+ /**
47
+ * Renders the complete HTML content for the Scalar API Reference interface.
48
+ *
49
+ * @param properties the configuration properties for the Scalar integration
50
+ * @return the rendered HTML content
51
+ * @throws IOException if the HTML template cannot be loaded
52
+ */
53
+ public static String render(ScalarProperties properties) throws IOException {
54
+ Objects.requireNonNull(properties, "properties must not be null");
55
+
56
+ String basePath = normalizeBasePath(properties.getPath());
57
+
58
+ // Load the template HTML
59
+ InputStream templateStream = ScalarHtmlRenderer.class.getResourceAsStream(HTML_TEMPLATE_PATH);
60
+ if (templateStream == null) {
61
+ throw new IOException("HTML template not found at: " + HTML_TEMPLATE_PATH);
62
+ }
63
+
64
+ String html;
65
+ try (InputStream inputStream = templateStream) {
66
+ html = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
67
+ }
68
+
69
+ // Build the JS bundle URL from the base path
70
+ String bundleUrl = buildJsBundleUrl(basePath);
71
+ String pageTitle = Objects.requireNonNullElse(properties.getPageTitle(), "Scalar API Reference");
72
+
73
+ // Serialize configuration to JSON
74
+ String configurationJson = buildConfigurationJson(properties);
75
+
76
+ // Replace placeholders
77
+ return html
78
+ .replace("__JS_BUNDLE_URL__", bundleUrl)
79
+ .replace("__PAGE_TITLE__", pageTitle)
80
+ .replace("__CONFIGURATION__", configurationJson);
81
+ }
82
+
83
+ /**
84
+ * Builds the URL for the Scalar JavaScript bundle based on the base path.
85
+ * Uses only the last path segment so the relative URL resolves correctly
86
+ * when the page is at basePath (avoids duplicate segments for multi-segment
87
+ * paths) and when deployed behind a reverse proxy with a context path.
88
+ *
89
+ * @param basePath the base path
90
+ * @return the relative path for the JavaScript bundle
91
+ */
92
+ private static String buildJsBundleUrl(String basePath) {
93
+ // Remove trailing slash to avoid double slashes when concatenating
94
+ String path = basePath;
95
+ if (path.endsWith("/")) {
96
+ path = path.substring(0, path.length() - 1);
97
+ }
98
+
99
+ int lastSlash = path.lastIndexOf('/');
100
+ String lastSegment = lastSlash >= 0 ? path.substring(lastSlash + 1) : path;
101
+ return lastSegment + "/" + ScalarConstants.JS_FILENAME;
102
+ }
103
+
104
+ /**
105
+ * Builds the configuration JSON for the Scalar API Reference.
106
+ *
107
+ * @param properties the properties to serialize
108
+ * @return the configuration JSON as a string
109
+ */
110
+ private static String buildConfigurationJson(ScalarProperties properties) {
111
+ try {
112
+ ScalarConfiguration config = ScalarConfigurationMapper.map(properties);
113
+ return OBJECT_MAPPER.writeValueAsString(config);
114
+ } catch (JsonProcessingException e) {
115
+ throw new RuntimeException("Failed to serialize Scalar configuration", e);
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Gets the JavaScript bundle content.
121
+ *
122
+ * @return the JavaScript bundle content as bytes
123
+ * @throws IOException if the JavaScript file cannot be loaded
124
+ */
125
+ public static byte[] getScalarJsContent() throws IOException {
126
+ InputStream jsStream = ScalarHtmlRenderer.class.getResourceAsStream(JS_BUNDLE_PATH);
127
+ if (jsStream == null) {
128
+ throw new IOException("JavaScript bundle not found at: " + JS_BUNDLE_PATH);
129
+ }
130
+
131
+ try (InputStream inputStream = jsStream) {
132
+ return inputStream.readAllBytes();
133
+ }
134
+ }
135
+ }