Giter Club home page Giter Club logo

Comments (16)

federecio avatar federecio commented on August 15, 2024

Sorry for this late response. The situation you describe should not be a problem. What version of dropwizard-swagger are you using?

from dropwizard-swagger.

derekcicerone-zz avatar derekcicerone-zz commented on August 15, 2024

I'm using io.federecio:dropwizard-swagger:0.5.1 (via Gradle).

The code we are using to put all the REST APIs under /api looks like this:

environment.jersey().setUrlPattern("/api/*");

from dropwizard-swagger.

federecio avatar federecio commented on August 15, 2024

What server type are you using? simple or default? Can you please share your configuration file?

from dropwizard-swagger.

derekcicerone-zz avatar derekcicerone-zz commented on August 15, 2024

Is this the part you are interested in?

server:
  adminConnectors:
    - type: http
      port: 3081
  applicationConnectors:
    - type: https
      port: 3443
      keyStorePath: My_Keystore
      keyStorePassword: keystore
      validateCerts: false
    - type: http
      port: 3080
  requestLog:
    appenders: []

from dropwizard-swagger.

derekcicerone-zz avatar derekcicerone-zz commented on August 15, 2024

Looks like we use default.

from dropwizard-swagger.

federecio avatar federecio commented on August 15, 2024

Ok I see. It's a bug in 0.7.x that fact that you are not able to specify the path in the config file (see dropwizard/dropwizard#665). Apparently this is going be available in 0.8+ as the pull request has been merged. So you are basically using a workaround by setting it programatically (more discussions here https://groups.google.com/forum/#!topic/dropwizard-user/ElrV5BqBcoo)

Let me see how to make it work in this case (default server with a context path other than the root).

If you were using simple server, it would work just fine with the /api path.

from dropwizard-swagger.

derekcicerone-zz avatar derekcicerone-zz commented on August 15, 2024

Are you sure the linked issues are related? We aren't setting a context path - we are only setting a URL pattern for the Jersey stuff so that it will all be under /api and won't potentially collide with static resources. It seems like Swagger needs 2 things: a web page/view for the UI and a resource for the REST APIs where it gets it's data. Currently the UI is being configured via Jersey so it goes under the Jersey path /api but the REST APIs are going under the normal server path which is /. There doesn't seem to be logic for handling a situation in which a non-default Jersey path has been set. I don't think it's necessarily a workaround to set it programmatically but I can definitely believe its a rarely used option.

The pull request you referenced doesn't appear to be merged yet (though it is tagged for inclusion in 0.8.0).

from dropwizard-swagger.

federecio avatar federecio commented on August 15, 2024

I pushed a potential fix for your problem. I took some time to fix it because I wanted to set up Selenium tests to make sure the UI works properly for the different combinations of server types and context path (either set as part of DropWizard configuration or programatically via environment.jersey().setUrlPattern(...)

I will deploy a snapshot shortly and will kindly ask you to try it out and see if your issue is solved.

from dropwizard-swagger.

federecio avatar federecio commented on August 15, 2024

Ok the snapshot is available under version 0.5.2-SNAPSHOT. Please take a look and let me know if it fixes your issue.

It takes a few hours to sync to Central from Sonatype OSS. If you can't get it from central it's available here: https://oss.sonatype.org/content/repositories/snapshots/io/federecio/dropwizard-swagger/0.5.2-SNAPSHOT/

from dropwizard-swagger.

derekcicerone-zz avatar derekcicerone-zz commented on August 15, 2024

Awesome, thank you! I'll take a look at the fix first thing tomorrow when I'm back at my computer).

from dropwizard-swagger.

derekcicerone-zz avatar derekcicerone-zz commented on August 15, 2024

Hmm, looks better - its hitting the right URL now. Unfortunately its still not working. When it calls https://localhost:3443/api/api-docs, it only returns:

{"apiVersion":"0.0","swaggerVersion":"1.2"}

This makes the JavaScript code throw an exception - it looks like there should be an "apis" property in there. I set a class-level @Api annotation on one of my resource classes so hitting https://localhost:3443/api/api-docs/sources works fine but for some reason it doesn't look like "sources" is being listed as an API.

Is there anything else I need to do besides adding annotations to a resource class to make this work? (I hooked up the code in my server class for onInitialize and onRun as well)

from dropwizard-swagger.

federecio avatar federecio commented on August 15, 2024

All your resources need to be annotated with @Api and your resource's methods with @ApiOperation and of course you need to register them with Jersey during the run() method of your Application class:

environment.jersey().register(new YourResource());

It seems you are missing some basic swagger stuff, if you share a sample project with me I could take a look.

from dropwizard-swagger.

derekcicerone-zz avatar derekcicerone-zz commented on August 15, 2024

Doh, sorry, I thought @ApiOperation was optional. Added that annotation and everything works great now - thanks!

from dropwizard-swagger.

federecio avatar federecio commented on August 15, 2024

Great!

Closing this issue. Thanks.

from dropwizard-swagger.

aaaaahaaaaa avatar aaaaahaaaaa commented on August 15, 2024

The problem originally described by @derekcicerone seems to be an existing bug with 0.5.3. Swagger tries to load api-docs from the base url localhost:8080/api-docs instead of localhost:8080/api/api-docs after setting a custom base url with :

environment.jersey().setUrlPattern("/api/*");

from dropwizard-swagger.

yeraabh avatar yeraabh commented on August 15, 2024

I think there is still an issue in version 0.5.3 with simple server and a custom url pattern.

In getContextPath() of SwaggerConfiguration, contextPath is read from applicationContextPath()

if (serverFactory instanceof SimpleServerFactory) {
applicationContextPath = ((SimpleServerFactory) serverFactory).getApplicationContextPath();

from dropwizard-swagger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.