SwaggerSuffixAspect.java 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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. @Aspect
  12. @EnableAspectJAutoProxy
  13. @Component
  14. public class SwaggerSuffixAspect {
  15. @AfterReturning(pointcut = "execution(public io.swagger.models.Swagger springfox.documentation.swagger2.mappers.ServiceModelToSwagger2MapperImpl.mapDocumentation(..))", returning = "swagger")
  16. public void doBeforeBussinessCheck(Swagger swagger) {
  17. Map<String, Path> paths = swagger.getPaths();
  18. if (null != paths) {
  19. Map<String, Path> newPaths = new HashMap<String, Path>(paths);
  20. paths.clear();
  21. Iterator<String> it = newPaths.keySet().iterator();
  22. while (it.hasNext()) {
  23. String oldKey = it.next();
  24. String newKey = oldKey + ".do";
  25. paths.put(newKey, newPaths.get(oldKey));
  26. }
  27. newPaths = null;
  28. }
  29. }
  30. }