Why Swagger automatically adds :80 to the service url when the port is not specified?

2,318 views
Skip to first unread message

Paolo Starace

unread,
Jun 11, 2014, 3:28:09 AM6/11/14
to swagger-sw...@googlegroups.com
Hello

I'm getting this strange behavior when the path is specified without an explicit port. I don't want to use :80 explicitly because as side effect the header of the response is empty (while calling my service without port number I correctly get the header in the response as expected).
I noticed that also in several other services (not only jersey or rest in general) the header is removed if :80 is added. So I don't think is due to my server configuration.

To solve I'm trying to change the swagger-ui.js to intercept the url and manually remove the :80 when present but I cannot find the correct line to change.
Can someone help me on that? Did anyone ever get the same issue?

Thanks
Paolo

Ron

unread,
Jun 11, 2014, 3:37:11 AM6/11/14
to swagger-sw...@googlegroups.com
Hi Paolo,

Is the :80 port added in the Swagger json output or do you see it added in the swagger-ui requests?
If it's in the Swagger json, can you please attach it?


--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paolo Starace

unread,
Jun 11, 2014, 4:16:16 AM6/11/14
to swagger-sw...@googlegroups.com
Hi Ron

I see it appearing in the result URL once I click the "Try it out!" button (see attached pic). 

So I suppose it is automatically added once the url I set in the SwaggerUI constructor is processed by swagger-ui.js

$(function () {
      window.swaggerUi = new SwaggerUi({
        dom_id:"swagger-ui-container"
    });

Do you know if the url is processed by swagger-ui.js in some way before exec the call to the service? If so, do you know where so I can change its behavior?

Thanks
Paolo


To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
screenshot.png

Ron

unread,
Jun 11, 2014, 4:29:10 AM6/11/14
to swagger-sw...@googlegroups.com
I actually don't know, as I'm not that familiar with that code base.

However, you can easily test it out using your browser's developer tools (I assume Firefox or Chrome). You should be able to say the full request as it is issued by the "Try it out!" button.

Also, it has nothing to do with the url you set with in the javascript code. Is there any chance you can attach the Swagger json? (that is, the output of "http://myhost/api/myservice/api-docs")


To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Paolo Starace

unread,
Jun 11, 2014, 5:16:18 AM6/11/14
to swagger-sw...@googlegroups.com
this is the json

{
  • apiVersion"v1",
  • swaggerVersion"1.2",
  • apis
    [
    • {
      • path"/provincia",
      • description"provinces"
      },
    • {
      • path"/comune",
      • description"municipalities"
      },
    • {
      • path"/regione",
      • description"regions"
      }
    ],
  • info
    {
    • title"title",
    • description"description",
    • contact"mail"
    }
}

However you are right about the url. The one used to call the service is the basePath defined with SwaggerConfig.setBasePath(BASE_PATH) during swagger configuration

SwaggerConfig config = new SwaggerConfig();
config.setBasePath(BASE_PATH);
config.setApiVersion(API_VERSION);
config.setApiInfo(new ApiInfo(API_TITLE, API_DESCRIPTION, null, API_CONTACT, null, null));
ConfigFactory.setConfig(config);
ScannerFactory.setScanner(new DefaultJaxrsScanner());
ClassReaders.setReader(new JerseyApiReader());

So I was looking in the wrong place. I'll give a look to the swagger-core code to better understand.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsubscri...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ron

unread,
Jun 11, 2014, 5:17:33 AM6/11/14
to swagger-sw...@googlegroups.com
How have you defined the BASE_PATH?


To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Paolo Starace

unread,
Jun 11, 2014, 6:31:49 AM6/11/14
to swagger-sw...@googlegroups.com
it is defined in a property file as 
swagger.basepath = http://myhost/webappappname

For sure the issue is there as changing it to an endpoint with a port like :8080, it works like a charm..


You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/WjyS1SrJo7c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.

Paolo Starace

unread,
Jun 11, 2014, 6:32:14 AM6/11/14
to swagger-sw...@googlegroups.com
it is defined in a property file as 
swagger.basepath = http://myhost/webappappname
and loaded on webapp startup.

For sure the issue is there as changing it to an endpoint with a port like :8080, it works like a charm..

Ron

unread,
Jun 11, 2014, 6:37:09 AM6/11/14
to swagger-sw...@googlegroups.com
okay, and when you look at the swagger json for one of the resources (for example /provincia), do you see the :80 in the basePath property?


To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

tony tam

unread,
Jun 11, 2014, 8:33:19 AM6/11/14
to swagger-sw...@googlegroups.com
Hi, this is a known issue in shred, the underlying http client.  You can see here:

Paolo Starace

unread,
Jun 11, 2014, 11:03:03 AM6/11/14
to swagger-sw...@googlegroups.com
OK I solved.
the issue was not related to the port :80 but to the cross domain call. I added already the CORS support as explained here https://github.com/wordnik/swagger-core/wiki/CORS but I just noticed the Access-Control-Allow-Headers part was missing the Authorization property (mandatory for my service). 
So I edited the line of the Tomcat filter class from:
    res.addHeader("Access-Control-Allow-Headers", "Content-Type");
to:
    res.addHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");


Now it works fine.

Thanks to all
Paolo
Reply all
Reply to author
Forward
0 new messages