SwaggerSuffixAspect.java 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package net.mingsoft.config;
  2. import java.util.HashMap;
  3. import java.util.Iterator;
  4. import java.util.Map;
  5. import org.aspectj.lang.annotation.AfterReturning;
  6. import org.aspectj.lang.annotation.Aspect;
  7. import org.springframework.context.annotation.EnableAspectJAutoProxy;
  8. import org.springframework.stereotype.Component;
  9. import io.swagger.models.Path;
  10. import io.swagger.models.Swagger;
  11. /**
  12. * 将接口url中追加模式后缀.do
  13. * @author impler
  14. * @date 2017年9月30日
  15. */
  16. @Aspect
  17. @EnableAspectJAutoProxy
  18. @Component
  19. public class SwaggerSuffixAspect {
  20. @AfterReturning(pointcut="execution(public io.swagger.models.Swagger springfox.documentation.swagger2.mappers.ServiceModelToSwagger2MapperImpl.mapDocumentation(..))",
  21. returning="swagger")
  22. public void doBeforeBussinessCheck(Swagger swagger){
  23. Map<String, Path> paths = swagger.getPaths();
  24. if(null != paths){
  25. Map<String, Path> newPaths = new HashMap<String, Path>(paths);
  26. paths.clear();
  27. Iterator<String> it = newPaths.keySet().iterator();
  28. while(it.hasNext()){
  29. String oldKey = it.next();
  30. // 添加模式后缀 .do
  31. String newKey = oldKey + ".do";
  32. paths.put(newKey, newPaths.get(oldKey));
  33. }
  34. newPaths = null;
  35. }
  36. }
  37. }