Skip to content

Commit 88f5bba

Browse files
authored
Merge pull request FASP-QAT#13 from decode-development/springdoc
Add SpringDoc Swagger endpoint and documentation Set up SpringDoc to enable Swagger UI for local API exploration and testing. This allows interactive API testing with the Swagger UI at /swagger-ui.html and OpenAPI spec download in JSON (/api-docs) or YAML (/api-docs.yaml) format which will be used to generate API documentation. Added OpenAPI annotations to JwtAuthenticationRestController to support authentication through the Swagger UI, which is needed to use the other endpoints. Added API documentation to the REST endpoints to enable us to use Swagger effectively.
2 parents 0096ad3 + 068d8b0 commit 88f5bba

File tree

64 files changed

+5707
-1052
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+5707
-1052
lines changed

.gitignore

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,13 @@ src/main/resources/fasp - db design2.mwb.bak
3838
/target/
3939
docs/
4040
HELP.md
41-
README.md
41+
README.md
42+
43+
# Mac
44+
.DS_Store
45+
46+
# JEnv
47+
.java-version
48+
49+
# VS Code
50+
.vscode

pom.xml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,8 @@
9898
</dependency>
9999
<dependency>
100100
<groupId>org.springdoc</groupId>
101-
<artifactId>springdoc-openapi-ui</artifactId>
102-
<version>1.3.1</version>
103-
</dependency>
104-
<dependency>
105-
<groupId>org.springdoc</groupId>
106-
<artifactId>springdoc-openapi-data-rest</artifactId>
107-
<version>1.3.1</version>
101+
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
102+
<version>2.3.0</version>
108103
</dependency>
109104
<!-- API, java.xml.bind module -->
110105
<dependency>

src/main/java/cc/altius/FASP/ARTMIS/controller/ExportOrderIdsCsv.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,18 @@
2626
import org.springframework.stereotype.Controller;
2727
import org.springframework.web.bind.annotation.RequestMapping;
2828
import org.springframework.web.bind.annotation.ResponseBody;
29+
import io.swagger.v3.oas.annotations.tags.Tag;
30+
import io.swagger.v3.oas.annotations.Operation;
2931

3032
/**
3133
*
3234
* @author altius
3335
*/
3436
@Controller
37+
@Tag(
38+
name = "Export Order IDs",
39+
description = "Export Order IDs to CSV"
40+
)
3541
public class ExportOrderIdsCsv {
3642

3743
@Autowired
@@ -50,6 +56,7 @@ public class ExportOrderIdsCsv {
5056

5157
@RequestMapping(value = "/exportOrderData")
5258
@ResponseBody
59+
@Operation(summary = "Export order data", description = "Export order data")
5360
// @Scheduled(cron = "0 0 21 * * MON-FRI",zone="EST")
5461
// @Scheduled(cron = "00 */02 * * * *")
5562
public String exportOrderData() {

src/main/java/cc/altius/FASP/ARTMIS/controller/ExportProgramCsv.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@
2626
import org.springframework.stereotype.Controller;
2727
import org.springframework.web.bind.annotation.RequestMapping;
2828
import org.springframework.web.bind.annotation.ResponseBody;
29-
29+
import io.swagger.v3.oas.annotations.tags.Tag;
30+
import io.swagger.v3.oas.annotations.Operation;
3031
/**
3132
*
3233
* @author altius
3334
*/
3435
@Controller
36+
@Tag(
37+
name = "Export Programs",
38+
description = "Export Programs to CSV"
39+
)
3540
public class ExportProgramCsv {
3641

3742
@Autowired
@@ -50,6 +55,7 @@ public class ExportProgramCsv {
5055

5156
@RequestMapping(value = "/exportProgramData")
5257
@ResponseBody
58+
@Operation(summary = "Export program data", description = "Export program data")
5359
// @Scheduled(cron = "0 0 21 * * MON-FRI",zone="EST")
5460
// @Scheduled(cron = "00 */02 * * * *")
5561
public String exportProgramCsv() {

src/main/java/cc/altius/FASP/ARTMIS/controller/ExportShipmentLinkingCsv.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package cc.altius.FASP.ARTMIS.controller;
77

88
import cc.altius.FASP.ARTMIS.service.ExportArtmisDataService;
9-
import cc.altius.FASP.model.DTO.ExportOrderDataDTO;
109
import cc.altius.FASP.model.DTO.ExportShipmentLinkingDTO;
1110
import cc.altius.FASP.model.EmailTemplate;
1211
import cc.altius.FASP.model.Emailer;
@@ -27,12 +26,18 @@
2726
import org.springframework.stereotype.Controller;
2827
import org.springframework.web.bind.annotation.RequestMapping;
2928
import org.springframework.web.bind.annotation.ResponseBody;
29+
import io.swagger.v3.oas.annotations.tags.Tag;
30+
import io.swagger.v3.oas.annotations.Operation;
3031

3132
/**
3233
*
3334
* @author altius
3435
*/
3536
@Controller
37+
@Tag(
38+
name = "Export Shipment Linking",
39+
description = "Export Shipment Linking to CSV"
40+
)
3641
public class ExportShipmentLinkingCsv {
3742

3843
@Autowired
@@ -51,6 +56,7 @@ public class ExportShipmentLinkingCsv {
5156

5257
@RequestMapping(value = "/exportShipmentLinkingData")
5358
@ResponseBody
59+
@Operation(summary = "Export shipment linking data", description = "Export shipment linking data")
5460
// @Scheduled(cron = "0 0 21 * * MON-FRI",zone="EST")
5561
// @Scheduled(cron = "00 */02 * * * *")
5662
public String exportOrderData() {

src/main/java/cc/altius/FASP/ARTMIS/controller/ExportSupplyPlanJson.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,18 @@
3434
import org.springframework.stereotype.Controller;
3535
import org.springframework.web.bind.annotation.GetMapping;
3636
import org.springframework.web.bind.annotation.ResponseBody;
37+
import io.swagger.v3.oas.annotations.tags.Tag;
38+
import io.swagger.v3.oas.annotations.Operation;
3739

3840
/**
3941
*
4042
* @author akil
4143
*/
4244
@Controller
45+
@Tag(
46+
name = "Export Supply Plan",
47+
description = "Export Supply Plan to JSON"
48+
)
4349
public class ExportSupplyPlanJson {
4450

4551
@Autowired
@@ -62,6 +68,7 @@ public class ExportSupplyPlanJson {
6268

6369
@GetMapping("/exportSupplyPlan")
6470
@ResponseBody
71+
@Operation(summary = "Export supply plan", description = "Export supply plan")
6572
public String exportSupplyPlan(Authentication auth) {
6673
logger.info(" ################ Going to start Supply Plan export process ############## ");
6774
String newLine = "<br/>\n";
@@ -174,6 +181,7 @@ public String exportSupplyPlan(Authentication auth) {
174181

175182
@GetMapping("/exportManualJson")
176183
@ResponseBody
184+
@Operation(summary = "Export manual supply plan json", description = "Export manual supply plan json")
177185
public String exportManualJson(Authentication auth) {
178186
logger.info(" ################ Going to start Manual Json export process ############## ");
179187
String newLine = "<br/>\n";

src/main/java/cc/altius/FASP/ARTMIS/controller/ImportArtmisDataController.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@
1212
import cc.altius.FASP.ARTMIS.service.ImportArtmisDataService;
1313
import org.springframework.web.bind.annotation.GetMapping;
1414
import org.springframework.web.bind.annotation.RestController;
15+
import io.swagger.v3.oas.annotations.tags.Tag;
1516

1617
/**
1718
*
1819
* @author altius
1920
*/
2021
@RestController
22+
@Tag(
23+
name = "Import Shipment Data",
24+
description = "Import Shipment Data from ARTMIS"
25+
)
2126
public class ImportArtmisDataController {
2227

2328
@Autowired

src/main/java/cc/altius/FASP/ARTMIS/controller/ImportProductCatalogueController.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@
1313
import org.springframework.web.bind.annotation.RequestMapping;
1414
import org.springframework.web.bind.annotation.ResponseBody;
1515
import org.xml.sax.SAXException;
16+
import io.swagger.v3.oas.annotations.tags.Tag;
1617

1718
/**
1819
*
1920
* @author altius
2021
*/
2122
@Controller
23+
@Tag(
24+
name = "Import Product Catalogue",
25+
description = "Import Product Catalogue from ARTMIS"
26+
)
2227
public class ImportProductCatalogueController {
2328

2429
@Autowired
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package cc.altius.FASP;
2+
3+
import io.swagger.v3.oas.models.Components;
4+
import io.swagger.v3.oas.models.OpenAPI;
5+
import io.swagger.v3.oas.models.info.Info;
6+
import io.swagger.v3.oas.models.info.License;
7+
import io.swagger.v3.oas.models.security.SecurityRequirement;
8+
import io.swagger.v3.oas.models.security.SecurityScheme;
9+
10+
import org.springframework.beans.factory.annotation.Value;
11+
import org.springframework.context.annotation.Bean;
12+
import org.springframework.context.annotation.Configuration;
13+
14+
@Configuration
15+
public class OpenApiConfig {
16+
17+
private final String appName;
18+
private final String appVersion;
19+
private final String appDescription;
20+
21+
public OpenApiConfig(
22+
@Value("${info.app.name}") String appName,
23+
@Value("${info.app.version}") String appVersion,
24+
@Value("${info.app.description}") String appDescription) {
25+
this.appName = appName;
26+
this.appVersion = appVersion;
27+
this.appDescription = appDescription;
28+
}
29+
30+
@Bean
31+
public OpenAPI faspOpenAPI() {
32+
final String securitySchemeName = "bearerAuth";
33+
return new OpenAPI()
34+
.addSecurityItem(new SecurityRequirement()
35+
.addList(securitySchemeName))
36+
.components(new Components()
37+
.addSecuritySchemes(securitySchemeName,
38+
new SecurityScheme()
39+
.name(securitySchemeName)
40+
.type(SecurityScheme.Type.HTTP)
41+
.scheme("bearer")
42+
.bearerFormat("JWT")
43+
.description(
44+
"Enter the JWT token in the format: Bearer <token>")))
45+
46+
.info(new Info()
47+
.title(appName)
48+
.description(appDescription)
49+
.version(appVersion)
50+
.license(new License()
51+
.name("Apache License Version 2.0")
52+
.url("https://www.apache.org/licenses/LICENSE-2.0")));
53+
}
54+
}

src/main/java/cc/altius/FASP/jwt/JWTWebSecurityConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
8181
.requestMatchers(HttpMethod.GET, refreshPath).permitAll()
8282
.requestMatchers(HttpMethod.GET, "/").permitAll()
8383
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll()
84+
.requestMatchers("/v3/api-docs/**").permitAll()
85+
.requestMatchers("/v3/api-docs.yaml").permitAll()
86+
.requestMatchers("/swagger-ui/**").permitAll()
87+
.requestMatchers("/swagger-ui.html").permitAll()
8488
.requestMatchers(
8589
"/error",
8690
"/api/logout",

0 commit comments

Comments
 (0)