Comments (6)
Thanks for trying it out. Is that error stopping you from testing the resource?
Just in case, I put together a sample project which you can try out -> https://github.com/federecio/dropwizard-swagger-sample-app/
from dropwizard-swagger.
I think I figured out the issue! The use of the with a String causes the swagger ui to fail. I am putting as a comment a diff to your example project that demonstrates the problem.
diff --git a/src/main/java/io/federecio/dropwizard/swagger/sample/SampleResource.java b/src/main/java/io/federecio/dropwizard/swagger/sample/SampleResource.java
index 3d840c5..bd2a999 100644
--- a/src/main/java/io/federecio/dropwizard/swagger/sample/SampleResource.java
+++ b/src/main/java/io/federecio/dropwizard/swagger/sample/SampleResource.java
@@ -1,10 +1,12 @@
package io.federecio.dropwizard.swagger.sample;
+import com.google.common.base.Optional;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
/**
@@ -16,7 +18,7 @@ public class SampleResource {
@GET
@ApiOperation("Sample endpoint")
- public Response get() {
- return Response.ok(new SamplePojo("Federico", 1234)).build();
+ public Response get(@QueryParam("name") Optional<String> name) {
+ return Response.ok(new SamplePojo(name.get(), 1234)).build();
}
}
from dropwizard-swagger.
It seems that the Swagger UI files bundled in the project don't support Optional parameters. I will check if the latest Swagger UI distribution handles Optional parameters.
from dropwizard-swagger.
I stumbled apon the same bug, any news?
from dropwizard-swagger.
seems related to swagger-api/swagger-core#609
looks like we need to wait for swagger-core 1.5.0
from dropwizard-swagger.
ok, found a workaround till the official patch:
- Implement a SwaggerSpecFilter that will filter out ApiParam on its access attribute (here, access="hidden" means filter out)
public class GuavaOptionalHackFilter implements SwaggerSpecFilter {
@Override
public boolean isOperationAllowed(Operation operation, ApiDescription apiDescription, Map<String, List<String>> stringListMap, Map<String, String> stringStringMap, Map<String, List<String>> stringListMap2) {
return true;
}
@Override
public boolean isParamAllowed(Parameter parameter, Operation operation, ApiDescription apiDescription, Map<String, List<String>> stringListMap, Map<String, String> stringStringMap, Map<String, List<String>> stringListMap2) {
return !parameterAccessValueIsHidden(parameter);
}
public static boolean parameterAccessValueIsHidden(Parameter parameter) {
return parameter.paramAccess().isDefined() && parameter.paramAccess().get().equalsIgnoreCase("hidden");
}
}
- actually filter out the params that are of type Optional
public Response getAbout(@ApiParam(access = "hidden") @QueryParam("qparam") Optional<String> qparam) {
return Response.ok().entity(qparam).build();
}
- use the @ApiImplicitParam annotation to provide what you want the parameters to look like
@GET
@Timed
@ApiImplicitParams(value = {@ApiImplicitParam(name = "qparam", value = "Query Parameter", dataType = "string", required = true, paramType = "query")})
public Response getAbout(@ApiParam(access = "hidden") @QueryParam("qparam") Optional<String> qparam) {
return Response.ok().entity(qparam).build();
}
- register the filter in your app run method:
@Override
public void run(Configuration configuration, Environment environment) throws Exception {
environment.jersey().register(new Resource());
swaggerDropwizard.onRun(configuration, environment);
com.wordnik.swagger.config.FilterFactory.setFilter(new GuavaOptionalHackFilter());
}
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.