@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.
- package/CHANGELOG.md +762 -0
- package/README.md +37 -0
- package/package.json +46 -0
- package/pom.xml +242 -0
- package/scalar-core/pom.xml +92 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/ScalarConstants.java +26 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/ScalarHtmlRenderer.java +135 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/ScalarProperties.java +596 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/authentication/ScalarAuthenticationOptions.java +235 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/authentication/flows/AuthorizationCodeFlow.java +160 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/authentication/flows/ClientCredentialsFlow.java +88 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/authentication/flows/ImplicitFlow.java +64 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/authentication/flows/OAuthFlow.java +185 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/authentication/flows/PasswordFlow.java +134 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/authentication/flows/ScalarFlows.java +113 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/authentication/schemes/ScalarApiKeySecurityScheme.java +77 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/authentication/schemes/ScalarHttpSecurityScheme.java +115 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/authentication/schemes/ScalarOAuth2SecurityScheme.java +75 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/authentication/schemes/ScalarSecurityScheme.java +45 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/config/DefaultHttpClient.java +77 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/config/ScalarAgentOptions.java +68 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/config/ScalarServer.java +197 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/config/ScalarSource.java +151 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/enums/CredentialsLocation.java +52 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/enums/DeveloperToolsVisibility.java +58 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/enums/DocumentDownloadType.java +67 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/enums/OperationSorter.java +52 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/enums/OperationTitleSource.java +52 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/enums/Pkce.java +57 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/enums/PropertyOrder.java +53 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/enums/ScalarClient.java +208 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/enums/ScalarLayout.java +52 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/enums/ScalarTarget.java +158 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/enums/ScalarTheme.java +102 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/enums/TagSorter.java +47 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/enums/ThemeMode.java +52 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/internal/ScalarConfiguration.java +425 -0
- package/scalar-core/src/main/java/com/scalar/maven/core/internal/ScalarConfigurationMapper.java +69 -0
- package/scalar-core/src/main/resources/META-INF/resources/webjars/scalar/index.html +22 -0
- package/scalar-core/src/test/java/com/scalar/maven/core/ScalarConfigurationTest.java +144 -0
- package/scalar-core/src/test/java/com/scalar/maven/core/ScalarHtmlRendererTest.java +104 -0
- package/scalar-core/src/test/java/com/scalar/maven/core/ScalarPropertiesTest.java +525 -0
- package/scalar-core/src/test/java/com/scalar/maven/core/config/DefaultHttpClientTest.java +61 -0
- package/scalar-core/src/test/java/com/scalar/maven/core/config/ScalarAgentOptionsTest.java +80 -0
- package/scalar-core/src/test/java/com/scalar/maven/core/config/ScalarServerTest.java +118 -0
- package/scalar-core/src/test/java/com/scalar/maven/core/config/ScalarSourceTest.java +105 -0
- package/scalar-playground-webflux/pom.xml +52 -0
- package/scalar-playground-webflux/src/main/java/com/scalar/maven/playground/CustomScalarWebFluxController.java +34 -0
- package/scalar-playground-webflux/src/main/java/com/scalar/maven/playground/PlaygroundApplication.java +27 -0
- package/scalar-playground-webflux/src/main/resources/application.properties +7 -0
- package/scalar-playground-webmvc/pom.xml +52 -0
- package/scalar-playground-webmvc/src/main/java/com/scalar/maven/playground/CustomScalarWebMvcController.java +34 -0
- package/scalar-playground-webmvc/src/main/java/com/scalar/maven/playground/PlaygroundApplication.java +27 -0
- package/scalar-playground-webmvc/src/main/resources/application.properties +7 -0
- package/scalar-webflux/pom.xml +110 -0
- package/scalar-webflux/src/main/java/com/scalar/maven/webflux/ScalarWebFluxActuatorEndpoint.java +103 -0
- package/scalar-webflux/src/main/java/com/scalar/maven/webflux/ScalarWebFluxAutoConfiguration.java +63 -0
- package/scalar-webflux/src/main/java/com/scalar/maven/webflux/ScalarWebFluxController.java +109 -0
- package/scalar-webflux/src/main/java/com/scalar/maven/webflux/SpringBootScalarProperties.java +43 -0
- package/scalar-webflux/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +2 -0
- package/scalar-webflux/src/test/java/com/scalar/maven/webflux/ScalarWebFluxActuatorEndpointTest.java +136 -0
- package/scalar-webflux/src/test/java/com/scalar/maven/webflux/ScalarWebFluxControllerTest.java +162 -0
- package/scalar-webmvc/pom.xml +103 -0
- package/scalar-webmvc/src/main/java/com/scalar/maven/webmvc/ScalarWebMvcActuatorEndpoint.java +97 -0
- package/scalar-webmvc/src/main/java/com/scalar/maven/webmvc/ScalarWebMvcAutoConfiguration.java +63 -0
- package/scalar-webmvc/src/main/java/com/scalar/maven/webmvc/ScalarWebMvcController.java +103 -0
- package/scalar-webmvc/src/main/java/com/scalar/maven/webmvc/SpringBootScalarProperties.java +43 -0
- package/scalar-webmvc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +2 -0
- package/scalar-webmvc/src/test/java/com/scalar/maven/webmvc/ScalarWebMvcActuatorEndpointTest.java +128 -0
- package/scalar-webmvc/src/test/java/com/scalar/maven/webmvc/ScalarWebMvcControllerTest.java +154 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
package com.scalar.maven.core.config;
|
|
2
|
+
|
|
3
|
+
import org.junit.jupiter.api.DisplayName;
|
|
4
|
+
import org.junit.jupiter.api.Nested;
|
|
5
|
+
import org.junit.jupiter.api.Test;
|
|
6
|
+
|
|
7
|
+
import java.util.HashMap;
|
|
8
|
+
import java.util.Map;
|
|
9
|
+
|
|
10
|
+
import static org.assertj.core.api.Assertions.assertThat;
|
|
11
|
+
|
|
12
|
+
@DisplayName("ScalarServer")
|
|
13
|
+
class ScalarServerTest {
|
|
14
|
+
|
|
15
|
+
@Nested
|
|
16
|
+
@DisplayName("construction")
|
|
17
|
+
class Construction {
|
|
18
|
+
|
|
19
|
+
@Test
|
|
20
|
+
@DisplayName("should create server with default constructor")
|
|
21
|
+
void shouldCreateServerWithDefaultConstructor() {
|
|
22
|
+
ScalarServer server = new ScalarServer();
|
|
23
|
+
assertThat(server).isNotNull();
|
|
24
|
+
assertThat(server.getUrl()).isNull();
|
|
25
|
+
assertThat(server.getDescription()).isNull();
|
|
26
|
+
assertThat(server.getVariables()).isNull();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@Test
|
|
30
|
+
@DisplayName("should create server with URL")
|
|
31
|
+
void shouldCreateServerWithUrl() {
|
|
32
|
+
String url = "https://api.example.com";
|
|
33
|
+
ScalarServer server = new ScalarServer(url);
|
|
34
|
+
assertThat(server.getUrl()).isEqualTo(url);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Test
|
|
38
|
+
@DisplayName("should create server with URL and description")
|
|
39
|
+
void shouldCreateServerWithUrlAndDescription() {
|
|
40
|
+
String url = "https://api.example.com";
|
|
41
|
+
String description = "Production API";
|
|
42
|
+
ScalarServer server = new ScalarServer(url, description);
|
|
43
|
+
assertThat(server.getUrl()).isEqualTo(url);
|
|
44
|
+
assertThat(server.getDescription()).isEqualTo(description);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Nested
|
|
49
|
+
@DisplayName("properties")
|
|
50
|
+
class Properties {
|
|
51
|
+
|
|
52
|
+
@Test
|
|
53
|
+
@DisplayName("should set and get URL")
|
|
54
|
+
void shouldSetAndGetUrl() {
|
|
55
|
+
ScalarServer server = new ScalarServer();
|
|
56
|
+
String url = "https://api.example.com";
|
|
57
|
+
server.setUrl(url);
|
|
58
|
+
assertThat(server.getUrl()).isEqualTo(url);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@Test
|
|
62
|
+
@DisplayName("should set and get description")
|
|
63
|
+
void shouldSetAndGetDescription() {
|
|
64
|
+
ScalarServer server = new ScalarServer();
|
|
65
|
+
String description = "Production API";
|
|
66
|
+
server.setDescription(description);
|
|
67
|
+
assertThat(server.getDescription()).isEqualTo(description);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@Test
|
|
71
|
+
@DisplayName("should set and get variables")
|
|
72
|
+
void shouldSetAndGetVariables() {
|
|
73
|
+
ScalarServer server = new ScalarServer();
|
|
74
|
+
Map<String, ScalarServer.ServerVariable> variables = new HashMap<>();
|
|
75
|
+
ScalarServer.ServerVariable variable = new ScalarServer.ServerVariable("default");
|
|
76
|
+
variables.put("env", variable);
|
|
77
|
+
server.setVariables(variables);
|
|
78
|
+
assertThat(server.getVariables()).isEqualTo(variables);
|
|
79
|
+
assertThat(server.getVariables().get("env")).isEqualTo(variable);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@Nested
|
|
84
|
+
@DisplayName("ServerVariable")
|
|
85
|
+
class ServerVariableTests {
|
|
86
|
+
|
|
87
|
+
@Test
|
|
88
|
+
@DisplayName("should create variable with default constructor")
|
|
89
|
+
void shouldCreateVariableWithDefaultConstructor() {
|
|
90
|
+
ScalarServer.ServerVariable variable = new ScalarServer.ServerVariable();
|
|
91
|
+
assertThat(variable).isNotNull();
|
|
92
|
+
assertThat(variable.getDefaultValue()).isNull();
|
|
93
|
+
assertThat(variable.getDescription()).isNull();
|
|
94
|
+
assertThat(variable.getEnumValues()).isNull();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@Test
|
|
98
|
+
@DisplayName("should create variable with default value")
|
|
99
|
+
void shouldCreateVariableWithDefaultValue() {
|
|
100
|
+
String defaultValue = "production";
|
|
101
|
+
ScalarServer.ServerVariable variable = new ScalarServer.ServerVariable(defaultValue);
|
|
102
|
+
assertThat(variable.getDefaultValue()).isEqualTo(defaultValue);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@Test
|
|
106
|
+
@DisplayName("should set and get properties")
|
|
107
|
+
void shouldSetAndGetProperties() {
|
|
108
|
+
ScalarServer.ServerVariable variable = new ScalarServer.ServerVariable();
|
|
109
|
+
variable.setDefaultValue("production");
|
|
110
|
+
variable.setDescription("Environment");
|
|
111
|
+
variable.setEnumValues(new String[]{"production", "staging", "development"});
|
|
112
|
+
assertThat(variable.getDefaultValue()).isEqualTo("production");
|
|
113
|
+
assertThat(variable.getDescription()).isEqualTo("Environment");
|
|
114
|
+
assertThat(variable.getEnumValues()).containsExactly("production", "staging", "development");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
package com.scalar.maven.core.config;
|
|
2
|
+
|
|
3
|
+
import org.junit.jupiter.api.DisplayName;
|
|
4
|
+
import org.junit.jupiter.api.Nested;
|
|
5
|
+
import org.junit.jupiter.api.Test;
|
|
6
|
+
|
|
7
|
+
import static org.assertj.core.api.Assertions.assertThat;
|
|
8
|
+
|
|
9
|
+
@DisplayName("ScalarSource")
|
|
10
|
+
class ScalarSourceTest {
|
|
11
|
+
|
|
12
|
+
@Nested
|
|
13
|
+
@DisplayName("construction")
|
|
14
|
+
class Construction {
|
|
15
|
+
|
|
16
|
+
@Test
|
|
17
|
+
@DisplayName("should create source with default constructor")
|
|
18
|
+
void shouldCreateSourceWithDefaultConstructor() {
|
|
19
|
+
ScalarSource source = new ScalarSource();
|
|
20
|
+
assertThat(source).isNotNull();
|
|
21
|
+
assertThat(source.getUrl()).isNull();
|
|
22
|
+
assertThat(source.getTitle()).isNull();
|
|
23
|
+
assertThat(source.getSlug()).isNull();
|
|
24
|
+
assertThat(source.isDefault()).isNull();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Test
|
|
28
|
+
@DisplayName("should create source with all parameters")
|
|
29
|
+
void shouldCreateSourceWithAllParameters() {
|
|
30
|
+
String url = "https://api.example.com/openapi.json";
|
|
31
|
+
String title = "Example API";
|
|
32
|
+
String slug = "example-api";
|
|
33
|
+
Boolean isDefault = true;
|
|
34
|
+
ScalarSource source = new ScalarSource(url, title, slug, isDefault);
|
|
35
|
+
assertThat(source.getUrl()).isEqualTo(url);
|
|
36
|
+
assertThat(source.getTitle()).isEqualTo(title);
|
|
37
|
+
assertThat(source.getSlug()).isEqualTo(slug);
|
|
38
|
+
assertThat(source.isDefault()).isEqualTo(isDefault);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Nested
|
|
43
|
+
@DisplayName("properties")
|
|
44
|
+
class Properties {
|
|
45
|
+
|
|
46
|
+
@Test
|
|
47
|
+
@DisplayName("should set and get URL")
|
|
48
|
+
void shouldSetAndGetUrl() {
|
|
49
|
+
ScalarSource source = new ScalarSource();
|
|
50
|
+
String url = "https://api.example.com/openapi.json";
|
|
51
|
+
source.setUrl(url);
|
|
52
|
+
assertThat(source.getUrl()).isEqualTo(url);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@Test
|
|
56
|
+
@DisplayName("should set and get title")
|
|
57
|
+
void shouldSetAndGetTitle() {
|
|
58
|
+
ScalarSource source = new ScalarSource();
|
|
59
|
+
String title = "Example API";
|
|
60
|
+
source.setTitle(title);
|
|
61
|
+
assertThat(source.getTitle()).isEqualTo(title);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@Test
|
|
65
|
+
@DisplayName("should set and get slug")
|
|
66
|
+
void shouldSetAndGetSlug() {
|
|
67
|
+
ScalarSource source = new ScalarSource();
|
|
68
|
+
String slug = "example-api";
|
|
69
|
+
source.setSlug(slug);
|
|
70
|
+
assertThat(source.getSlug()).isEqualTo(slug);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@Test
|
|
74
|
+
@DisplayName("should set and get isDefault")
|
|
75
|
+
void shouldSetAndGetIsDefault() {
|
|
76
|
+
ScalarSource source = new ScalarSource();
|
|
77
|
+
source.setDefault(true);
|
|
78
|
+
assertThat(source.isDefault()).isTrue();
|
|
79
|
+
source.setDefault(false);
|
|
80
|
+
assertThat(source.isDefault()).isFalse();
|
|
81
|
+
source.setDefault(null);
|
|
82
|
+
assertThat(source.isDefault()).isNull();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@Test
|
|
86
|
+
@DisplayName("should set and get agent")
|
|
87
|
+
void shouldSetAndGetAgent() {
|
|
88
|
+
ScalarSource source = new ScalarSource();
|
|
89
|
+
assertThat(source.getAgent()).isNull();
|
|
90
|
+
|
|
91
|
+
ScalarAgentOptions agent = new ScalarAgentOptions();
|
|
92
|
+
agent.setKey("agent-key");
|
|
93
|
+
agent.setDisabled(true);
|
|
94
|
+
source.setAgent(agent);
|
|
95
|
+
|
|
96
|
+
assertThat(source.getAgent()).isSameAs(agent);
|
|
97
|
+
assertThat(source.getAgent().getKey()).isEqualTo("agent-key");
|
|
98
|
+
assertThat(source.getAgent().getDisabled()).isTrue();
|
|
99
|
+
|
|
100
|
+
source.setAgent(null);
|
|
101
|
+
assertThat(source.getAgent()).isNull();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
@@ -0,0 +1,52 @@
|
|
|
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-playground-webflux</artifactId>
|
|
15
|
+
<packaging>jar</packaging>
|
|
16
|
+
|
|
17
|
+
<name>Scalar API Reference Playground (WebFlux)</name>
|
|
18
|
+
<description>Example Spring Boot application demonstrating Scalar API Reference usage with WebFlux</description>
|
|
19
|
+
|
|
20
|
+
<dependencies>
|
|
21
|
+
<!-- Scalar WebFlux integration -->
|
|
22
|
+
<dependency>
|
|
23
|
+
<groupId>com.scalar.maven</groupId>
|
|
24
|
+
<artifactId>scalar-webflux</artifactId>
|
|
25
|
+
<version>${project.version}</version>
|
|
26
|
+
</dependency>
|
|
27
|
+
|
|
28
|
+
<!-- Spring Boot WebFlux -->
|
|
29
|
+
<dependency>
|
|
30
|
+
<groupId>org.springframework.boot</groupId>
|
|
31
|
+
<artifactId>spring-boot-starter-webflux</artifactId>
|
|
32
|
+
</dependency>
|
|
33
|
+
</dependencies>
|
|
34
|
+
|
|
35
|
+
<build>
|
|
36
|
+
<plugins>
|
|
37
|
+
<plugin>
|
|
38
|
+
<groupId>org.apache.maven.plugins</groupId>
|
|
39
|
+
<artifactId>maven-compiler-plugin</artifactId>
|
|
40
|
+
</plugin>
|
|
41
|
+
|
|
42
|
+
<plugin>
|
|
43
|
+
<groupId>org.springframework.boot</groupId>
|
|
44
|
+
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
45
|
+
<configuration>
|
|
46
|
+
<mainClass>com.scalar.maven.playground.PlaygroundApplication</mainClass>
|
|
47
|
+
</configuration>
|
|
48
|
+
</plugin>
|
|
49
|
+
</plugins>
|
|
50
|
+
</build>
|
|
51
|
+
</project>
|
|
52
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
package com.scalar.maven.playground;
|
|
2
|
+
|
|
3
|
+
import com.scalar.maven.core.ScalarProperties;
|
|
4
|
+
import com.scalar.maven.webflux.ScalarWebFluxController;
|
|
5
|
+
import org.springframework.http.server.reactive.ServerHttpRequest;
|
|
6
|
+
import org.springframework.web.bind.annotation.RestController;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Custom Scalar WebFlux controller for the playground application.
|
|
10
|
+
*
|
|
11
|
+
* <p>
|
|
12
|
+
* This controller extends {@link ScalarWebFluxController} and overrides the
|
|
13
|
+
* {@link #configureProperties(ScalarProperties, ServerHttpRequest)} method
|
|
14
|
+
* to set a custom page title.
|
|
15
|
+
* </p>
|
|
16
|
+
*/
|
|
17
|
+
@RestController
|
|
18
|
+
public class CustomScalarWebFluxController extends ScalarWebFluxController {
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Configures the Scalar properties before rendering.
|
|
22
|
+
* This implementation sets a custom page title.
|
|
23
|
+
*
|
|
24
|
+
* @param properties the properties to configure
|
|
25
|
+
* @param request the HTTP request
|
|
26
|
+
* @return the configured properties with custom page title
|
|
27
|
+
*/
|
|
28
|
+
@Override
|
|
29
|
+
protected ScalarProperties configureProperties(ScalarProperties properties, ServerHttpRequest request) {
|
|
30
|
+
properties.setPageTitle("Scalar API Reference - WebFlux");
|
|
31
|
+
return properties;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
package com.scalar.maven.playground;
|
|
2
|
+
|
|
3
|
+
import org.springframework.boot.SpringApplication;
|
|
4
|
+
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Example Spring Boot application demonstrating Scalar API Reference integration.
|
|
8
|
+
*
|
|
9
|
+
* <p>
|
|
10
|
+
* Run this application with:
|
|
11
|
+
* </p>
|
|
12
|
+
* <pre>
|
|
13
|
+
* mvn spring-boot:run
|
|
14
|
+
* </pre>
|
|
15
|
+
*
|
|
16
|
+
* <p>
|
|
17
|
+
* Then visit {@code http://localhost:8080/scalar} to see the API Reference.
|
|
18
|
+
* </p>
|
|
19
|
+
*/
|
|
20
|
+
@SpringBootApplication
|
|
21
|
+
public class PlaygroundApplication {
|
|
22
|
+
|
|
23
|
+
public static void main(String[] args) {
|
|
24
|
+
SpringApplication.run(PlaygroundApplication.class, args);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
@@ -0,0 +1,52 @@
|
|
|
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-playground-webmvc</artifactId>
|
|
15
|
+
<packaging>jar</packaging>
|
|
16
|
+
|
|
17
|
+
<name>Scalar API Reference Playground (WebMVC)</name>
|
|
18
|
+
<description>Example Spring Boot application demonstrating Scalar API Reference usage with WebMVC</description>
|
|
19
|
+
|
|
20
|
+
<dependencies>
|
|
21
|
+
<!-- Scalar WebMVC integration -->
|
|
22
|
+
<dependency>
|
|
23
|
+
<groupId>com.scalar.maven</groupId>
|
|
24
|
+
<artifactId>scalar-webmvc</artifactId>
|
|
25
|
+
<version>${project.version}</version>
|
|
26
|
+
</dependency>
|
|
27
|
+
|
|
28
|
+
<!-- Spring Boot Web -->
|
|
29
|
+
<dependency>
|
|
30
|
+
<groupId>org.springframework.boot</groupId>
|
|
31
|
+
<artifactId>spring-boot-starter-web</artifactId>
|
|
32
|
+
</dependency>
|
|
33
|
+
</dependencies>
|
|
34
|
+
|
|
35
|
+
<build>
|
|
36
|
+
<plugins>
|
|
37
|
+
<plugin>
|
|
38
|
+
<groupId>org.apache.maven.plugins</groupId>
|
|
39
|
+
<artifactId>maven-compiler-plugin</artifactId>
|
|
40
|
+
</plugin>
|
|
41
|
+
|
|
42
|
+
<plugin>
|
|
43
|
+
<groupId>org.springframework.boot</groupId>
|
|
44
|
+
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
45
|
+
<configuration>
|
|
46
|
+
<mainClass>com.scalar.maven.playground.PlaygroundApplication</mainClass>
|
|
47
|
+
</configuration>
|
|
48
|
+
</plugin>
|
|
49
|
+
</plugins>
|
|
50
|
+
</build>
|
|
51
|
+
</project>
|
|
52
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
package com.scalar.maven.playground;
|
|
2
|
+
|
|
3
|
+
import com.scalar.maven.core.ScalarProperties;
|
|
4
|
+
import com.scalar.maven.webmvc.ScalarWebMvcController;
|
|
5
|
+
import jakarta.servlet.http.HttpServletRequest;
|
|
6
|
+
import org.springframework.web.bind.annotation.RestController;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Custom Scalar WebMVC controller for the playground application.
|
|
10
|
+
*
|
|
11
|
+
* <p>
|
|
12
|
+
* This controller extends {@link ScalarWebMvcController} and overrides the
|
|
13
|
+
* {@link #configureProperties(ScalarProperties, HttpServletRequest)} method
|
|
14
|
+
* to set a custom page title.
|
|
15
|
+
* </p>
|
|
16
|
+
*/
|
|
17
|
+
@RestController
|
|
18
|
+
public class CustomScalarWebMvcController extends ScalarWebMvcController {
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Configures the Scalar properties before rendering.
|
|
22
|
+
* This implementation sets a custom page title.
|
|
23
|
+
*
|
|
24
|
+
* @param properties the properties to configure
|
|
25
|
+
* @param request the HTTP request
|
|
26
|
+
* @return the configured properties with custom page title
|
|
27
|
+
*/
|
|
28
|
+
@Override
|
|
29
|
+
protected ScalarProperties configureProperties(ScalarProperties properties, HttpServletRequest request) {
|
|
30
|
+
properties.setPageTitle("Scalar API Reference - WebMVC");
|
|
31
|
+
return properties;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
package com.scalar.maven.playground;
|
|
2
|
+
|
|
3
|
+
import org.springframework.boot.SpringApplication;
|
|
4
|
+
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Example Spring Boot application demonstrating Scalar API Reference integration.
|
|
8
|
+
*
|
|
9
|
+
* <p>
|
|
10
|
+
* Run this application with:
|
|
11
|
+
* </p>
|
|
12
|
+
* <pre>
|
|
13
|
+
* mvn spring-boot:run
|
|
14
|
+
* </pre>
|
|
15
|
+
*
|
|
16
|
+
* <p>
|
|
17
|
+
* Then visit {@code http://localhost:8080/scalar} to see the API Reference.
|
|
18
|
+
* </p>
|
|
19
|
+
*/
|
|
20
|
+
@SpringBootApplication
|
|
21
|
+
public class PlaygroundApplication {
|
|
22
|
+
|
|
23
|
+
public static void main(String[] args) {
|
|
24
|
+
SpringApplication.run(PlaygroundApplication.class, args);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
@@ -0,0 +1,110 @@
|
|
|
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-webflux</artifactId>
|
|
15
|
+
<packaging>jar</packaging>
|
|
16
|
+
|
|
17
|
+
<name>Scalar API Reference Spring Boot WebFlux</name>
|
|
18
|
+
<description>Spring Boot WebFlux integration for Scalar API Reference</description>
|
|
19
|
+
|
|
20
|
+
<dependencies>
|
|
21
|
+
<!-- Core module -->
|
|
22
|
+
<dependency>
|
|
23
|
+
<groupId>com.scalar.maven</groupId>
|
|
24
|
+
<artifactId>scalar-core</artifactId>
|
|
25
|
+
<version>${project.version}</version>
|
|
26
|
+
</dependency>
|
|
27
|
+
|
|
28
|
+
<!-- Spring Boot WebFlux -->
|
|
29
|
+
<dependency>
|
|
30
|
+
<groupId>org.springframework.boot</groupId>
|
|
31
|
+
<artifactId>spring-boot-starter-webflux</artifactId>
|
|
32
|
+
<scope>provided</scope>
|
|
33
|
+
</dependency>
|
|
34
|
+
|
|
35
|
+
<!-- Spring Boot Auto-Configuration -->
|
|
36
|
+
<dependency>
|
|
37
|
+
<groupId>org.springframework.boot</groupId>
|
|
38
|
+
<artifactId>spring-boot-autoconfigure</artifactId>
|
|
39
|
+
<scope>provided</scope>
|
|
40
|
+
</dependency>
|
|
41
|
+
|
|
42
|
+
<!-- Spring Boot Configuration Processor -->
|
|
43
|
+
<dependency>
|
|
44
|
+
<groupId>org.springframework.boot</groupId>
|
|
45
|
+
<artifactId>spring-boot-configuration-processor</artifactId>
|
|
46
|
+
<optional>true</optional>
|
|
47
|
+
</dependency>
|
|
48
|
+
|
|
49
|
+
<!-- Spring Boot Actuator -->
|
|
50
|
+
<dependency>
|
|
51
|
+
<groupId>org.springframework.boot</groupId>
|
|
52
|
+
<artifactId>spring-boot-starter-actuator</artifactId>
|
|
53
|
+
<scope>provided</scope>
|
|
54
|
+
</dependency>
|
|
55
|
+
|
|
56
|
+
<!-- Test Dependencies -->
|
|
57
|
+
<dependency>
|
|
58
|
+
<groupId>org.springframework.boot</groupId>
|
|
59
|
+
<artifactId>spring-boot-starter-test</artifactId>
|
|
60
|
+
<scope>test</scope>
|
|
61
|
+
</dependency>
|
|
62
|
+
|
|
63
|
+
<!-- Reactor Test -->
|
|
64
|
+
<dependency>
|
|
65
|
+
<groupId>io.projectreactor</groupId>
|
|
66
|
+
<artifactId>reactor-test</artifactId>
|
|
67
|
+
<scope>test</scope>
|
|
68
|
+
</dependency>
|
|
69
|
+
</dependencies>
|
|
70
|
+
|
|
71
|
+
<build>
|
|
72
|
+
<plugins>
|
|
73
|
+
<plugin>
|
|
74
|
+
<groupId>org.codehaus.mojo</groupId>
|
|
75
|
+
<artifactId>flatten-maven-plugin</artifactId>
|
|
76
|
+
</plugin>
|
|
77
|
+
|
|
78
|
+
<plugin>
|
|
79
|
+
<groupId>org.apache.maven.plugins</groupId>
|
|
80
|
+
<artifactId>maven-compiler-plugin</artifactId>
|
|
81
|
+
</plugin>
|
|
82
|
+
|
|
83
|
+
<plugin>
|
|
84
|
+
<groupId>org.apache.maven.plugins</groupId>
|
|
85
|
+
<artifactId>maven-surefire-plugin</artifactId>
|
|
86
|
+
</plugin>
|
|
87
|
+
|
|
88
|
+
<plugin>
|
|
89
|
+
<groupId>org.apache.maven.plugins</groupId>
|
|
90
|
+
<artifactId>maven-source-plugin</artifactId>
|
|
91
|
+
</plugin>
|
|
92
|
+
|
|
93
|
+
<plugin>
|
|
94
|
+
<groupId>org.apache.maven.plugins</groupId>
|
|
95
|
+
<artifactId>maven-javadoc-plugin</artifactId>
|
|
96
|
+
</plugin>
|
|
97
|
+
|
|
98
|
+
<plugin>
|
|
99
|
+
<groupId>org.apache.maven.plugins</groupId>
|
|
100
|
+
<artifactId>maven-gpg-plugin</artifactId>
|
|
101
|
+
</plugin>
|
|
102
|
+
|
|
103
|
+
<plugin>
|
|
104
|
+
<groupId>org.sonatype.central</groupId>
|
|
105
|
+
<artifactId>central-publishing-maven-plugin</artifactId>
|
|
106
|
+
</plugin>
|
|
107
|
+
</plugins>
|
|
108
|
+
</build>
|
|
109
|
+
</project>
|
|
110
|
+
|
package/scalar-webflux/src/main/java/com/scalar/maven/webflux/ScalarWebFluxActuatorEndpoint.java
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
package com.scalar.maven.webflux;
|
|
2
|
+
|
|
3
|
+
import com.scalar.maven.core.ScalarHtmlRenderer;
|
|
4
|
+
import com.scalar.maven.core.ScalarProperties;
|
|
5
|
+
import org.springframework.beans.factory.ObjectProvider;
|
|
6
|
+
import org.springframework.beans.factory.annotation.Autowired;
|
|
7
|
+
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
|
8
|
+
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
|
9
|
+
import org.springframework.boot.actuate.endpoint.web.annotation.WebEndpoint;
|
|
10
|
+
import org.springframework.core.io.ByteArrayResource;
|
|
11
|
+
import org.springframework.core.io.Resource;
|
|
12
|
+
import org.springframework.http.MediaType;
|
|
13
|
+
import org.springframework.http.server.reactive.ServerHttpRequest;
|
|
14
|
+
import reactor.core.publisher.Mono;
|
|
15
|
+
import reactor.core.scheduler.Schedulers;
|
|
16
|
+
|
|
17
|
+
import java.io.IOException;
|
|
18
|
+
import java.nio.charset.StandardCharsets;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Actuator endpoint for serving the Scalar API Reference interface in Spring WebFlux applications.
|
|
22
|
+
*
|
|
23
|
+
* <p>
|
|
24
|
+
* This endpoint provides access to the Scalar API Reference interface through
|
|
25
|
+
* Spring Boot Actuator endpoints. It serves the same HTML content as the
|
|
26
|
+
* regular ScalarWebFluxController but is accessible at the actuator path.
|
|
27
|
+
* </p>
|
|
28
|
+
*
|
|
29
|
+
* <p>
|
|
30
|
+
* The endpoint is only enabled when {@code scalar.actuatorEnabled=true} is set
|
|
31
|
+
* in the configuration properties.
|
|
32
|
+
* </p>
|
|
33
|
+
*
|
|
34
|
+
* <p>
|
|
35
|
+
* Access the endpoint at: {@code /actuator/scalar}
|
|
36
|
+
* </p>
|
|
37
|
+
*/
|
|
38
|
+
@Endpoint(id = "scalar")
|
|
39
|
+
@WebEndpoint(id = "scalar")
|
|
40
|
+
public class ScalarWebFluxActuatorEndpoint {
|
|
41
|
+
|
|
42
|
+
@Autowired
|
|
43
|
+
private ObjectProvider<SpringBootScalarProperties> propertiesProvider;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Serves the Scalar API Reference interface as an actuator endpoint.
|
|
47
|
+
*
|
|
48
|
+
* <p>
|
|
49
|
+
* This method returns the same HTML content as the regular ScalarWebFluxController
|
|
50
|
+
* but is accessible through the actuator endpoint system.
|
|
51
|
+
* </p>
|
|
52
|
+
*
|
|
53
|
+
* @param request the HTTP request
|
|
54
|
+
* @return a Mono containing a Resource with the HTML content for the API Reference
|
|
55
|
+
* interface
|
|
56
|
+
*/
|
|
57
|
+
@ReadOperation(produces = MediaType.TEXT_HTML_VALUE)
|
|
58
|
+
public final Mono<Resource> scalarUi(ServerHttpRequest request) {
|
|
59
|
+
return Mono.fromCallable(() -> {
|
|
60
|
+
ScalarProperties properties = propertiesProvider.getObject();
|
|
61
|
+
ScalarProperties configuredProperties = configureProperties(properties, request);
|
|
62
|
+
String html = ScalarHtmlRenderer.render(configuredProperties);
|
|
63
|
+
Resource resource = new ByteArrayResource(html.getBytes(StandardCharsets.UTF_8));
|
|
64
|
+
return resource;
|
|
65
|
+
})
|
|
66
|
+
.subscribeOn(Schedulers.boundedElastic())
|
|
67
|
+
.onErrorMap(IOException.class, e -> new RuntimeException("Failed to render HTML", e));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Serves the JavaScript bundle for the Scalar API Reference.
|
|
72
|
+
*
|
|
73
|
+
* <p>
|
|
74
|
+
* This endpoint returns the JavaScript file that powers the Scalar API
|
|
75
|
+
* Reference interface. The file is served with the appropriate MIME type.
|
|
76
|
+
* </p>
|
|
77
|
+
*
|
|
78
|
+
* @return a Mono containing a Resource with the JavaScript bundle
|
|
79
|
+
*/
|
|
80
|
+
@ReadOperation(produces = "application/javascript")
|
|
81
|
+
public final Mono<Resource> scalarJs() {
|
|
82
|
+
return Mono.fromCallable(() -> {
|
|
83
|
+
byte[] jsContent = ScalarHtmlRenderer.getScalarJsContent();
|
|
84
|
+
Resource resource = new ByteArrayResource(jsContent);
|
|
85
|
+
return resource;
|
|
86
|
+
})
|
|
87
|
+
.subscribeOn(Schedulers.boundedElastic())
|
|
88
|
+
.onErrorMap(IOException.class, e -> new RuntimeException("Failed to load JavaScript bundle", e));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Hook method that allows subclasses to configure properties before rendering.
|
|
93
|
+
* Override this method to customize the ScalarProperties before they are
|
|
94
|
+
* converted to JSON and rendered.
|
|
95
|
+
*
|
|
96
|
+
* @param properties the properties to configure
|
|
97
|
+
* @param request the HTTP request
|
|
98
|
+
* @return the configured properties
|
|
99
|
+
*/
|
|
100
|
+
protected ScalarProperties configureProperties(ScalarProperties properties, ServerHttpRequest request) {
|
|
101
|
+
return properties;
|
|
102
|
+
}
|
|
103
|
+
}
|