提交 05393b19 authored 作者: mry's avatar mry

fix(web): 将Example修改为Environment,优化了swaggerController

上级 e8bfada3
......@@ -2,8 +2,8 @@ package org.matrix.autotest.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.matrix.autotest.entity.Example;
import org.matrix.autotest.service.ExampleService;
import org.matrix.autotest.entity.Environment;
import org.matrix.autotest.service.EnvironmentService;
import org.springframework.web.bind.annotation.*;
import java.util.List;
......@@ -17,14 +17,14 @@ import java.util.List;
* @since 2022-01-07
*/
@RestController
@RequestMapping("/examples")
@RequestMapping("/environments")
@Api(tags = "对实例表example的基本操作")
public class ExampleController {
public class EnvironmentController {
private final ExampleService exampleService;
private final EnvironmentService environmentService;
public ExampleController(ExampleService exampleService) {
this.exampleService = exampleService;
public EnvironmentController(EnvironmentService environmentService) {
this.environmentService = environmentService;
}
/**
......@@ -34,8 +34,8 @@ public class ExampleController {
*/
@ApiOperation(value = "查询所有实例")
@GetMapping
public List<Example> findAllExample() {
return exampleService.findAllExample();
public List<Environment> findAllEnvironment() {
return environmentService.findAllEnvironment();
}
/**
......@@ -46,44 +46,44 @@ public class ExampleController {
*/
@ApiOperation(value = "根据id查询实例")
@GetMapping("/{id}")
public Example findByIdExample(@PathVariable Integer id) {
return exampleService.findByIdExample(id);
public Environment findByIdEnvironment(@PathVariable Integer id) {
return environmentService.findByIdEnvironment(id);
}
/**
* 添加实例
*
* @param example 实例
* @param environment 实例
* @return 添加的实例
*/
@ApiOperation(value = "添加实例")
@PostMapping
public Example insertExample(@RequestBody Example example) {
return exampleService.insertExample(example);
public Environment insertEnvironment(@RequestBody Environment environment) {
return environmentService.insertEnvironment(environment);
}
/**
* 修改实例
*
* @param example 实例
* @param environment 实例
* @return 修改后的实例
*/
@ApiOperation(value = "根据id修改实例")
@PutMapping("/{id}")
public Example updateExample(@RequestBody Example example) {
return exampleService.updateExample(example);
public Environment updateEnvironment(@RequestBody Environment environment) {
return environmentService.updateEnvironment(environment);
}
/**
* 删除实例
*
* @param example 实例
* @param environment 实例
* @return 删除的实例
*/
@ApiOperation(value = "根据id删除实例")
@DeleteMapping("/{id}")
public Example deleteExample(@RequestBody Example example) {
return exampleService.deleteExample(example);
public Environment deleteEnvironment(@RequestBody Environment environment){
return environmentService.deleteEnvironment(environment);
}
}
......@@ -2,7 +2,7 @@ package org.matrix.autotest.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.matrix.autotest.entity.Example;
import org.matrix.autotest.entity.Environment;
/**
* <p>
......@@ -13,6 +13,6 @@ import org.matrix.autotest.entity.Example;
* @since 2022-01-07
*/
@Mapper
public interface ExampleMapper extends BaseMapper<Example> {
public interface EnvironmentMapper extends BaseMapper<Environment> {
}
......@@ -21,8 +21,8 @@ import java.time.LocalDateTime;
@Data
@Accessors(chain = true)
@ApiModel(value = "实例表")
@TableName(value = "example")
public class Example {
@TableName(value = "environment")
public class Environment {
private static final long serialVersionUID = 1L;
......
package org.matrix.autotest.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.matrix.autotest.entity.Example;
import org.matrix.autotest.entity.Environment;
import java.util.List;
......@@ -13,13 +13,13 @@ import java.util.List;
* @author mry
* @since 2022-01-07
*/
public interface ExampleService extends IService<Example> {
public interface EnvironmentService extends IService<Environment> {
/**
* 查询所有实例
*
* @return 实例
*/
List<Example> findAllExample();
List<Environment> findAllEnvironment();
/**
* 根据id查询实例
......@@ -27,29 +27,29 @@ public interface ExampleService extends IService<Example> {
* @param id 实例id
* @return 实例
*/
Example findByIdExample(Integer id);
Environment findByIdEnvironment(Integer id);
/**
* 添加实例
*
* @param example 实例
* @param environment 实例
* @return 添加的实例
*/
Example insertExample(Example example);
Environment insertEnvironment(Environment environment);
/**
* 修改实例
*
* @param example 实例
* @param environment 实例
* @return 修改后的实例
*/
Example updateExample(Example example);
Environment updateEnvironment(Environment environment);
/**
* 删除实例
*
* @param example 实例
* @param environment 实例
* @return 删除的实例
*/
Example deleteExample(Example example);
Environment deleteEnvironment(Environment environment);
}
package org.matrix.autotest.service.Impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.matrix.autotest.dao.EnvironmentMapper;
import org.matrix.autotest.entity.Environment;
import org.matrix.autotest.service.EnvironmentService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 实例表,项目对应的环境实例,例如:实验室环境,开发环境等 服务实现类
* </p>
*
* @author mry
* @since 2022-01-07
*/
@Service
public class EnvironmentServiceImpl extends ServiceImpl<EnvironmentMapper, Environment> implements EnvironmentService {
private final EnvironmentMapper environmentMapper;
public EnvironmentServiceImpl(EnvironmentMapper environmentMapper) {
this.environmentMapper = environmentMapper;
}
@Override
public List<Environment> findAllEnvironment() {
return environmentMapper.selectList(null);
}
@Override
public Environment findByIdEnvironment(Integer id) {
return environmentMapper.selectById(id);
}
@Override
public Environment insertEnvironment(Environment environment) {
environmentMapper.insert(environment);
return environment;
}
@Override
public Environment updateEnvironment(Environment environment) {
environmentMapper.updateById(environment);
return environment;
}
@Override
public Environment deleteEnvironment(Environment environment) {
environmentMapper.deleteById(environment.getId());
return environment;
}
}
package org.matrix.autotest.service.Impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.matrix.autotest.dao.ExampleMapper;
import org.matrix.autotest.entity.Example;
import org.matrix.autotest.service.ExampleService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 实例表,项目对应的环境实例,例如:实验室环境,开发环境等 服务实现类
* </p>
*
* @author mry
* @since 2022-01-07
*/
@Service
public class ExampleServiceImpl extends ServiceImpl<ExampleMapper, Example> implements ExampleService {
private final ExampleMapper exampleMapper;
public ExampleServiceImpl(ExampleMapper exampleMapper) {
this.exampleMapper = exampleMapper;
}
@Override
public List<Example> findAllExample() {
return exampleMapper.selectList(null);
}
@Override
public Example findByIdExample(Integer id) {
return exampleMapper.selectById(id);
}
@Override
public Example insertExample(Example example) {
exampleMapper.insert(example);
return example;
}
@Override
public Example updateExample(Example example) {
exampleMapper.updateById(example);
return example;
}
@Override
public Example deleteExample(Example example) {
exampleMapper.deleteById(example.getId());
return example;
}
}
package org.matrix.autotest.SwaggerData;
package org.matrix.autotest.swaggerData;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
......@@ -48,6 +48,7 @@ public class SwaggerController {
@GetMapping
public Object parameter(String url) {
@SuppressWarnings("all")
List<String> list = new ArrayList();
//获得json字符串
String json = loadJson(url);
......@@ -58,6 +59,7 @@ public class SwaggerController {
Object basePath = swaggerJson.get("basePath");
Object paths = swaggerJson.get("paths");
//将paths转成map集合
@SuppressWarnings("unchecked")
Map<String, String> pathsMaps = (Map<String, String>) paths;
//获取key
Set<String> methodUrls = pathsMaps.keySet();
......@@ -68,17 +70,21 @@ public class SwaggerController {
//通过JSON获取到methodUrl,用来获取methodUrl内部的信息
Object objMethodUrls = objPaths.get(methodUrl);
JSONObject objUrlsJson = (JSONObject) objMethodUrls;
@SuppressWarnings("unchecked")
Map<String, String> objMethodUrlsMaps = (Map<String, String>) objMethodUrls;
Set<String> requests = objMethodUrlsMaps.keySet();
for (String request : requests) {
//拿到请求内部的信息
Object objRequest = objUrlsJson.get(request);
@SuppressWarnings("unchecked")
Map<String, String> objRequestMaps = (Map<String, String>) objRequest;
Object parameters = objRequestMaps.get("parameters");
List<String> parameterAllList = new ArrayList<>();
if (parameters != null) {
@SuppressWarnings("all")
List<String> parameterLists = (List<String>) parameters;
for (Object parameterList : parameterLists) {
@SuppressWarnings("unchecked")
Map<String, String> parameterMaps = (Map<String, String>) parameterList;
String name = parameterMaps.get("name");
String type = parameterMaps.get("type");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论