Skip to content

Commit

Permalink
Add basic swagger documentation (when you run, it's available at loca…
Browse files Browse the repository at this point in the history
…lhost:38443/cws-ui/swagger-ui/index.html)
  • Loading branch information
wcgunter committed Mar 19, 2024
1 parent 2f41156 commit d3af1ae
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cws-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,19 @@
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
</dependency>

<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
Expand Down
43 changes: 43 additions & 0 deletions cws-service/src/main/java/jpl/cws/controller/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package jpl.cws.controller;

import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger.web.UiConfiguration;
import springfox.documentation.swagger.web.UiConfigurationBuilder;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableSwagger2
@EnableWebMvc
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo());
}

private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("API")
.description("API Desc")
.version("V1")
.build();
}

@Bean
public UiConfiguration uiConfiguration() {
return UiConfigurationBuilder
.builder()
.defaultModelExpandDepth(-1)
.build();
}
}
5 changes: 5 additions & 0 deletions cws-ui/src/main/webapp/WEB-INF/springmvc-servlet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
<context:annotation-config/>

<context:property-placeholder location="classpath:cws-ui.properties"/>

<mvc:resources mapping="/swagger-ui/**" location="classpath:/META-INF/resources/webjars/springfox-swagger-ui/"/>
<mvc:view-controller path="/swagger-ui/" view-name="forward:/swagger-ui/index.html"/>
<mvc:resources mapping="index.html" location="classpath:/META-INF/resources/webjars/springfox-swagger-ui/"/>
<bean id="swaggerConfig" class="jpl.cws.controller.SwaggerConfig"/>

<mvc:annotation-driven>
<mvc:path-matching suffix-pattern="true" />
Expand Down
13 changes: 13 additions & 0 deletions cws-ui/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@
<url-pattern>/initiators</url-pattern>
<url-pattern>/logout</url-pattern>
<url-pattern>/not_authorized</url-pattern>
<url-pattern>/swagger-ui/index.html</url-pattern>
<url-pattern>/swagger-ui/springfox.css</url-pattern>
<url-pattern>/swagger-ui/swagger-ui.css</url-pattern>
<url-pattern>/swagger-ui/springfox.js</url-pattern>
<url-pattern>/swagger-ui/swagger-ui.js</url-pattern>
<url-pattern>/swagger-ui/swagger-ui-bundle.js</url-pattern>
<url-pattern>/swagger-ui/swagger-ui-standalone-preset.js</url-pattern>
<url-pattern>/swagger-ui/favicon-32x32.png</url-pattern>
<url-pattern>/swagger-ui/favicon-16x16.png</url-pattern>
<url-pattern>/swagger-resources/configuration/ui</url-pattern>
<url-pattern>/swagger-resources/configuration/security</url-pattern>
<url-pattern>/swagger-resources</url-pattern>
<url-pattern>/v2/api-docs</url-pattern>
<url-pattern>*.mvc</url-pattern>
</servlet-mapping>

Expand Down
16 changes: 16 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,22 @@
<version>${xmlunit.version}</version>
</dependency>

<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>

</dependencies>
</dependencyManagement>

Expand Down

0 comments on commit d3af1ae

Please sign in to comment.