Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-7563

Non-unique operationIds in swagger.json result in '_1' appended

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.1.11
    • 3.2.1
    • JAX-RS
    • None
    • Unknown

    Description

      We are using SpringBoot + JAX-RS server and define two service beans that lie under 2 separate packages. The jaxrs server is configured with Swagger2Feature to generate the swagger.json, but the operationIds and thus the URIs for these services get appended with '_1'.

      Sample (Gradle + IDEA) project:
      https://github.com/yeralin/ReproduceBug-CXF-7563-

      Structure:

      Sample Java class:

      @SpringBootApplication
      public class DemoApplication {
      
          @Autowired
          private SampleService sampleService;
      
          @Autowired
          private SampleServiceInternal sampleServiceInternal;
      
          public static void main(String[] args) {
              SpringApplication.run(DemoApplication.class, args);
          }
      
          @Bean(destroyMethod = "shutdown")
          public SpringBus cxf() {
              return new SpringBus();
          }
      
          @Bean(destroyMethod = "destroy")
          @DependsOn("cxf")
          public Server jaxRsServer() {
              final JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
              factory.setServiceBeans(Arrays.asList(sampleService, sampleServiceInternal));
              factory.setBus(cxf());
              factory.setAddress("/");
              factory.setFeatures(Arrays.asList(configureSwagger()));
              return factory.create();
          }
      
          private Swagger2Feature configureSwagger() {
              Swagger2Feature feature = new Swagger2Feature();
              feature.setBasePath("/");
              return feature;
          }
      
      }
      

      Swagger.json:

      // 20171114155626
      // http://localhost:17070/services/swagger.json
      {
        "swagger": "2.0",
        "info": {
          "description": "The Application",
          "version": "1.0.0",
          "title": "Sample REST Application",
          "contact": {
            "name": "users@cxf.apache.org"
          },
          "license": {
            "name": "Apache 2.0 License",
            "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
          }
        },
        "basePath": "/services",
        "tags": Array[2][
          {
            "name": "internal"
          },
          {
            "name": "test"
          }
        ],
        "paths": {
          "/Internal/internal": {
            "get": {
              "tags": Array[1][
                "internal"
              ],
              "operationId": "getInternal_1",
              "parameters": Array[0][
                
              ],
              "responses": {
                "200": {
                  "description": "successful operation",
                  "schema": {
                    "type": "string"
                  },
                  "headers": {
                    
                  }
                }
              }
            }
          },
          "/test/test": {
            "get": {
              "tags": Array[1][
                "test"
              ],
              "operationId": "getTest_1",
              "parameters": Array[0][
                
              ],
              "responses": {
                "200": {
                  "description": "successful operation",
                  "schema": {
                    "type": "string"
                  },
                  "headers": {
                    
                  }
                }
              }
            }
          }
        }
      }
      

      Logs at startup:

        .   ____          _            __ _ _
       /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
      ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
       \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
        '  |____| .__|_| |_|_| |_\__, | / / / /
       =========|_|==============|___/=/_/_/_/
       :: Spring Boot ::        (v1.5.8.RELEASE)
      
      2017-11-14 16:25:11.655  INFO 69492 --- [           main] reproduce.bug.demo.DemoApplication       : Starting DemoApplication on daniyars-mbp.usny.ibm.com with PID 69492 (/Users/Daniyar.Yeralin/Repositories/demo/out/production/classes started by Daniyar.Yeralin in /Users/Daniyar.Yeralin/Repositories/demo)
      2017-11-14 16:25:11.657  INFO 69492 --- [           main] reproduce.bug.demo.DemoApplication       : The following profiles are active: reactive
      2017-11-14 16:25:11.714  INFO 69492 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6af93788: startup date [Tue Nov 14 16:25:11 EST 2017]; root of context hierarchy
      2017-11-14 16:25:12.893  INFO 69492 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 17070 (http)
      2017-11-14 16:25:12.906  INFO 69492 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
      2017-11-14 16:25:12.907  INFO 69492 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.23
      2017-11-14 16:25:13.001  INFO 69492 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
      2017-11-14 16:25:13.002  INFO 69492 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1292 ms
      2017-11-14 16:25:13.286  INFO 69492 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
      2017-11-14 16:25:13.289  INFO 69492 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'CXFServlet' to [/services/*]
      2017-11-14 16:25:13.291  INFO 69492 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
      2017-11-14 16:25:13.291  INFO 69492 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
      2017-11-14 16:25:13.291  INFO 69492 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
      2017-11-14 16:25:13.291  INFO 69492 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
      2017-11-14 16:25:13.448  INFO 69492 --- [           main] org.apache.cxf.endpoint.ServerImpl       : Setting the server's publish address to be /
      2017-11-14 16:25:13.693  INFO 69492 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6af93788: startup date [Tue Nov 14 16:25:11 EST 2017]; root of context hierarchy
      2017-11-14 16:25:13.741  INFO 69492 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
      2017-11-14 16:25:13.742  INFO 69492 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
      2017-11-14 16:25:13.761  INFO 69492 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
      2017-11-14 16:25:13.762  INFO 69492 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
      2017-11-14 16:25:13.785  INFO 69492 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
      2017-11-14 16:25:13.887  INFO 69492 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
      2017-11-14 16:25:13.946  INFO 69492 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 17070 (http)
      2017-11-14 16:25:13.951  INFO 69492 --- [           main] reproduce.bug.demo.DemoApplication       : Started DemoApplication in 2.663 seconds (JVM running for 3.025)
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            daniyar94 Daniyar Yeralin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: