package com.github.kongchen.swagger.docgen.reader;

import io.swagger.models.Path;
import io.swagger.models.Swagger;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugin.logging.SystemStreamLog;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.util.HashSet;
import java.util.Map;

import static java.util.Collections.singletonList;

public class SpringMvcApiReaderTest {

    @Test
    public void testReadWithEmptyPathOnMethodLevel() throws Exception {

        Log log = new SystemStreamLog();

        SpringMvcApiReader springMvcApiReader = new SpringMvcApiReader(null, log);
        Swagger swagger = springMvcApiReader.read(new HashSet<>(singletonList(ExampleController.class)));

        Map<String, Path> paths = swagger.getPaths();

        Assert.assertTrue(paths.keySet().contains("/api"));
        Assert.assertEquals(paths.get("/api").getGet().getOperationId(), "emptyPathEndpoint");

        Assert.assertTrue(paths.keySet().contains("/api/someendpoint"));
        Assert.assertEquals(paths.get("/api/someendpoint").getGet().getOperationId(), "someEndpoint");
    }


    @RestController
    @RequestMapping("/api")
    static class ExampleController {

        @GetMapping("someendpoint")
        public void someEndpoint() {

        }

        @GetMapping("")
        public void emptyPathEndpoint() {

        }
    }

}

@@ -45,16 +45,60 @@
 eader;%0A%0A
+import io.swagger.annotations.ApiOperation;%0A
 import i
@@ -638,24 +638,76 @@
 aderTest %7B%0A%0A
+    private final Log log = new SystemStreamLog();%0A%0A
     @Test%0A  
@@ -781,50 +781,8 @@
  %7B%0A%0A
-        Log log = new SystemStreamLog();%0A%0A
     
@@ -1362,16 +1362,436 @@
     %7D%0A%0A%0A
+    @Test%0A    public void testApiOperationNickname() throws Exception %7B%0A%0A        SpringMvcApiReader springMvcApiReader = new SpringMvcApiReader(null, log);%0A        Swagger swagger = springMvcApiReader.read(new HashSet%3C%3E(singletonList(ExampleController.class)));%0A%0A        Path path = swagger.getPaths().get(%22/api/endpoint-with-nickname%22);%0A        Assert.assertEquals(path.getGet().getOperationId(), %22nicknamed%22);%0A    %7D%0A%0A%0A
     @Res
@@ -2012,32 +2012,193 @@
 thEndpoint() %7B%0A%0A
+        %7D%0A%0A        @GetMapping(%22endpoint-with-nickname%22)%0A        @ApiOperation(nickname = %22nicknamed%22, value = %22%22)%0A        public void endpointWithNickname() %7B%0A%0A
         %7D%0A    %7D%0A

add testApiOperationNickname