Skip to content

Commit

Permalink
feature: support swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
Muluo-cyan committed Oct 15, 2024
1 parent cb5fd7b commit d340516
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 0 deletions.
13 changes: 13 additions & 0 deletions console/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,19 @@
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>

<!-- swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>

<!--<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.seata.console.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.seata.common.result.Code;
import org.apache.seata.common.result.SingleResult;
import org.apache.seata.console.config.ConsoleSecurityConfig;
Expand All @@ -39,6 +41,7 @@
*
*/
@RestController
@Api(tags = "Console authentication APIs")
@RequestMapping("/api/v1/auth")
public class AuthController {
@Autowired
Expand All @@ -57,6 +60,7 @@ public class AuthController {
* @return HTTP code equal to 200 indicates that Seata is in right states. HTTP code equal to 500 indicates that
* Seata is in broken states.
*/
@ApiOperation("login and get access token and refresh token")
@PostMapping("/login")
public SingleResult<String> login(HttpServletResponse response, @RequestBody User user) {
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.seata.console.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.seata.common.result.Code;
import org.apache.seata.common.result.SingleResult;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -31,6 +33,7 @@
*
*/
@RestController
@Api(tags = "Overview APIs")
@RequestMapping("/api/v1/overview")
public class OverviewController {

Expand All @@ -39,6 +42,7 @@ public class OverviewController {
*
* @return the data
*/
@ApiOperation("get data")
@GetMapping(value = "/getData")
public SingleResult<List> getData() {
List<Map<String, Object>> result = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< HEAD
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
Expand All @@ -17,6 +18,12 @@
package org.apache.seata.server.auth.config;

import com.google.common.base.Predicates;
=======
package org.apache.seata.server.auth.config;

import com.google.common.base.Predicates;
import org.apache.seata.console.config.ConsoleSecurityConfig;
>>>>>>> dcbba42f0 (feature: support swagger)
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.seata.server.auth.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.seata.common.result.Code;
import org.apache.seata.common.result.SingleResult;
import org.apache.seata.server.auth.config.ClusterSecurityConfig;
Expand All @@ -36,11 +38,14 @@
import javax.servlet.http.HttpServletResponse;

@RestController
@Api(tags = "Cluster authentication APIs")
@RequestMapping("/metadata/v1/auth")
public class ClusterAuthController {

@Autowired
@Qualifier("clusterJwtTokenUtils")
private ClusterJwtTokenUtils jwtTokenUtils;

@Autowired
@Qualifier("clusterAuthenticationManager")
private AuthenticationManager authenticationManager;
Expand All @@ -53,6 +58,7 @@ public class ClusterAuthController {
* @return HTTP code equal to 200 indicates that Seata is in right states. HTTP code equal to 500 indicates that
* Seata is in broken states.
*/
@ApiOperation("login to get access token and refresh token")
@PostMapping("/login")
public SingleResult<String> login(HttpServletResponse response, @RequestBody User user) {
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.seata.server.console.controller;

import io.swagger.annotations.Api;
import org.apache.seata.server.console.service.BranchSessionService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -26,6 +27,7 @@
* Branch Session Controller
*/
@RestController
@Api(tags = "Branch session APIs")
@RequestMapping("/api/v1/console/branchSession")
public class BranchSessionController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import javax.annotation.Resource;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.seata.common.result.PageResult;
import org.apache.seata.server.console.param.GlobalLockParam;
import org.apache.seata.server.console.vo.GlobalLockVO;
Expand All @@ -32,6 +34,7 @@
* Global Lock Controller
*/
@RestController
@Api(tags = "Global lock APIs")
@RequestMapping("/api/v1/console/globalLock")
public class GlobalLockController {

Expand All @@ -43,6 +46,7 @@ public class GlobalLockController {
* @param param the param
* @return the list of GlobalLockVO
*/
@ApiOperation("query global lock")
@GetMapping("query")
public PageResult<GlobalLockVO> query(@ModelAttribute GlobalLockParam param) {
return globalLockService.query(param);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import javax.annotation.Resource;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.seata.server.console.param.GlobalSessionParam;
import org.apache.seata.common.result.PageResult;
import org.apache.seata.server.console.vo.GlobalSessionVO;
Expand All @@ -31,6 +33,7 @@
* Global Session Controller
*/
@RestController
@Api(tags = "Global session APIs")
@RequestMapping("/api/v1/console/globalSession")
public class GlobalSessionController {

Expand All @@ -42,6 +45,7 @@ public class GlobalSessionController {
* @param param param for query globalSession
* @return the list of GlobalSessionVO
*/
@ApiOperation("query global session")
@GetMapping("query")
public PageResult<GlobalSessionVO> query(@ModelAttribute GlobalSessionParam param) {
return globalSessionService.query(param);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.alipay.sofa.jraft.RouteTable;
import com.alipay.sofa.jraft.conf.Configuration;
import com.alipay.sofa.jraft.entity.PeerId;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.seata.common.ConfigurationKeys;
import org.apache.seata.common.metadata.MetadataResponse;
import org.apache.seata.common.metadata.Node;
Expand Down Expand Up @@ -55,6 +57,7 @@
/**
*/
@RestController
@Api(tags = "Raft cluster APIs")
@RequestMapping("/metadata/v1")
public class ClusterController {

Expand All @@ -73,6 +76,7 @@ private void init() {
this.serverProperties = applicationContext.getBean(ServerProperties.class);
}

@ApiOperation("changeCluster")
@PostMapping("/changeCluster")
public Result<?> changeCluster(@RequestParam String raftClusterStr) {
Result<?> result = new Result<>();
Expand All @@ -89,6 +93,7 @@ public Result<?> changeCluster(@RequestParam String raftClusterStr) {
return result;
}

@ApiOperation("cluster")
@GetMapping("/cluster")
public MetadataResponse cluster(String group) {
MetadataResponse metadataResponse = new MetadataResponse();
Expand Down Expand Up @@ -122,6 +127,7 @@ public MetadataResponse cluster(String group) {
return metadataResponse;
}

@ApiOperation("watch follower")
@PostMapping("/watch")
public void watch(HttpServletRequest request, @RequestParam Map<String, Object> groupTerms,
@RequestParam(defaultValue = "28000") int timeout) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.seata.server.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.seata.server.ServerRunner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -24,6 +26,7 @@
/**
*/
@RestController
@Api(tags = "Health APIs")
public class HealthController {

private static final String OK = "ok";
Expand All @@ -34,6 +37,7 @@ public class HealthController {


@RequestMapping("/health")
@ApiOperation("health")
String healthCheck() {
return serverRunner.started() ? OK : NOT_OK;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.seata.server.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.seata.common.metadata.namingserver.Instance;
import org.apache.seata.common.result.Result;
import org.apache.seata.common.util.StringUtils;
Expand All @@ -37,6 +39,7 @@
import static org.apache.seata.common.ConfigurationKeys.NAMING_SERVER;

@RestController
@Api(tags = "VGroup mapping APIs")
@RequestMapping("/vgroup/v1")
public class VGroupMappingController {

Expand All @@ -59,6 +62,7 @@ private void init() {
* @param vGroup
* @return
*/
@ApiOperation("add VGroup")
@GetMapping("/addVGroup")
public Result<?> addVGroup(@RequestParam String vGroup, @RequestParam String unit) {
Result<?> result = new Result<>();
Expand All @@ -82,6 +86,7 @@ public Result<?> addVGroup(@RequestParam String vGroup, @RequestParam String uni
* @param vGroup
* @return
*/
@ApiOperation("remove VGroup")
@GetMapping("/removeVGroup")
public Result<?> removeVGroup(@RequestParam String vGroup) {
Result<?> result = new Result<>();
Expand Down

0 comments on commit d340516

Please sign in to comment.