Comments (16)
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.
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.
What server type are you using? simple or default? Can you please share your configuration file?
from dropwizard-swagger.
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.
Looks like we use default.
from dropwizard-swagger.
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.
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.
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.
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.
Awesome, thank you! I'll take a look at the fix first thing tomorrow when I'm back at my computer).
from dropwizard-swagger.
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.
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.
Doh, sorry, I thought @ApiOperation was optional. Added that annotation and everything works great now - thanks!
from dropwizard-swagger.
Great!
Closing this issue. Thanks.
from dropwizard-swagger.
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.
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)
- Template was precompiled with an older version of Handlebars than the current runtime. Please update your precompiler to a newer version (>= 4.0.0) or downgrade your runtime to an older version (>= 2.0.0-beta.1) HOT 1
- NoSuchMethodError: org.apache.commons.lang3.StringUtils HOT 3
- Disable Try It Out Button
- API page stuck at fetching resource list http://localhost/api/swagger.json
- Multiple swagger related endpoints published
- Dropwizard with @Auth issues
- You need to provide an instance of SwaggerBundleConfiguration error while running the sample app provided in the swagger documentation
- Jakarta XML support HOT 1
- FR: Support for Dropwizard 3.0
- FR: Support for Dropwizard 4.0 HOT 1
- SwaggerBundleConfiguration schemes default
- 2.2 POM is broken in Maven Central HOT 1
- File button not showing up on swagger ui HOT 2
- SwaggerBundleConfig variables HOT 2
- Dropwizard 1.0.0 support HOT 1
- dropwizard-swagger doesn't work with dropwizard version 1.0.0 HOT 5
- Error while Running dropwizard-swagger HOT 1
- Value.Immutable classes
- Allow to define custom swagger path HOT 4
- swagger not running behind nginx. static context not loading
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dropwizard-swagger.