Swagger Dropwizard 0.7 - TextArea for JSON parameter not displayed
NickName:user3642813 Ask DateTime:2015-06-11T04:08:21

Swagger Dropwizard 0.7 - TextArea for JSON parameter not displayed

The problem

I can't find the reason Swagger doesn't show the POST end point with the textarea 'body' available so I can paste JSON into.

I expected to see a page like this the POST in PetStore Swagger

But my form is simply posted after I click 'Try it out' and I get

Response Body

    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Error 415 Unsupported Media Type</title>
      </head>
      <body><h2>HTTP ERROR 415</h2>
        <p>Problem accessing /promotions. Reason:
          <pre>    Unsupported Media Type</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/>
      </body>
    </html>

Response Headers

{
  "access-control-allow-origin": "http://localhost:8080",
  "date": "Thu, 11 Jun 2015 07:37:15 GMT",
  "cache-control": "must-revalidate,no-cache,no-store",
  "access-control-allow-credentials": "true",
  "content-type": "text/html; charset=ISO-8859-1",
  "content-length": "320",
  "access-control-expose-headers": ""
}

Can you help me with this please?

More information on my project

$ java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

Maven

parent
    - pom.xml:   <dropwizard.version>0.8.1</dropwizard.version>
                 <swagger.version>0.7.0</swagger.version>)
  app
    - pom.xml:   <dependency>
                    <groupId>io.dropwizard</groupId>
                    <artifactId>dropwizard-core</artifactId>
                    <version>${dropwizard.version}</version>
                 </dependency>
                 <dependency>
                    <groupId>io.federecio</groupId>
                    <artifactId>dropwizard-swagger</artifactId>
                    <version>${swagger.version}</version>
                 </dependency>
    - config.yml: 
                 swagger:
                   resourcePackage: myproject.promotion.v1.resource             
  representation
    - pom.xml

Configuration

package myproject.promotion.app.config;

public class PromotionServiceConfiguration extends Configuration {

    @JsonProperty("swagger")
    public SwaggerBundleConfiguration swaggerBundleConfiguration;    

}

Application

package myproject.promotion.app;

public class PromotionServiceApplication extends Application<PromotionServiceConfiguration> {

public static void main(String[] args) throws Exception {
    new PromotionServiceApplication().run(args);
}

@Override
public void initialize(Bootstrap<PromotionServiceConfiguration> bootstrap) {
    bootstrap.addBundle(new PromotionSwaggerBundle());
}

@Override
public void run(PromotionServiceConfiguration configuration, Environment environment) {
//Deleted to make it short
}

}

PromotionSwaggerBundle

package myproject.promotion.app.config;

public class PromotionSwaggerBundle extends SwaggerBundle<PromotionServiceConfiguration> {

@Override
protected SwaggerBundleConfiguration getSwaggerBundleConfiguration(PromotionServiceConfiguration configuration) {
    return configuration.swaggerBundleConfiguration;
}

}

End point

package myproject.v1.resource;

@Path("/promotions")
@Api(value = "/promotions/", description = "Promotions' possible operations", consumes = "application/json", produces = "application/json")
public class PromotionManagementResource {

    private static final String PROMO_PARAM = "promotionId";

    private final PromotionManagementService promotionManagementService;

    @Inject
    public PromotionManagementResource(PromotionManagementService promotionManagementService) {
        this.promotionManagementService = promotionManagementService;
    }

    @POST
    @Consumes(APPLICATION_JSON)
    @ApiOperation(value = "Create promotion")
    @ApiResponses(value = {
            @ApiResponse(code = 201, message = "Promotion created. Link to it in Location HEADER"),
            @ApiResponse(code = 409, message = "Promotion already exists")
            })
    public Response create(final Promotion promotion, @Context final UriInfo uriInfo) throws IOException {
        Promotion createdPromotion = promotionManagementService.create(promotion);

        URI createdInventoryURI = inventory(createdPromotion, uriInfo);
        return Response.created(createdInventoryURI).build();
    }

Copyright Notice:Content Author:「user3642813」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30766313/swagger-dropwizard-0-7-textarea-for-json-parameter-not-displayed

Answers
user3642813 2015-06-21T21:50:37

In the end the annotation @ApiParam did the trick.\n\nNew POST method (with the new annotation)\n\n@POST\n@Consumes(APPLICATION_JSON)\n@ApiOperation(value = \"Create promotion\", notes = \"\", response = Promotion.class)\n@ApiResponses(value = {\n @ApiResponse(code = 201, message = \"Promotion created. Link to it in Location HEADER.\"),\n @ApiResponse(code = 409, message = \"Promotion already exist.\")\n})\npublic Response create(@ApiParam final Promotion promotion, @Context final UriInfo uriInfo) throws IOException {\n Promotion createdPromotion = promotionManagementService.create(promotion);\n\n URI createdPromotionURI = uriTo(createdPromotion, uriInfo);\n return Response.created(createdPromotionURI).build();\n}\n\n\nThanks for your help cyrbil.",


More about “Swagger Dropwizard 0.7 - TextArea for JSON parameter not displayed” related questions

Swagger Dropwizard 0.7 - TextArea for JSON parameter not displayed

The problem I can't find the reason Swagger doesn't show the POST end point with the textarea 'body' available so I can paste JSON into. I expected to see a page like this the POST in PetStore Sw...

Show Detail

Jersey 2.7 with Dropwizard 0.7 - is this supported?

I am having a Dropwizard based RESTful application. Dropwizard v0.7 seems to have a dependency on jersey 1.18. I am trying to upgrade jersey to 2.7 retaining dropwizard 0.7. But there seems to be

Show Detail

How to access the JSON created by swagger at compile time using Dropwizard Testing?

I have a simple Dropwizard application with swagger integrated and I want to access the JSON created by swagger at compile time using Dropwizard Testing. Is this possible, and If it is, please guid...

Show Detail

Integrate Swagger with Dropwizard, not able to produce the swagger.json file

I have done the following steps: I have a existing drop-wizard project setup [0.8 version]. Added dependence &lt;dependency&gt; &lt;groupId&gt;com.wordnik&lt;/groupId&gt; ..

Show Detail

Dropwizard-swagger with Dropwizard 1.3

I am using the dropwizard-swagger dependency with Dropwizard 1.3 as follows &lt;dependency&gt; &lt;groupId&gt;com.smoketurner&lt;/groupId&gt; &lt;artifactId&gt;dropwizard-s...

Show Detail

dropwizard 0.7 @Session annotation

i'm trying to get Dropwizard working with sessions. I've read that in 0.7, Dropwizard added session support. from release notes: "Added support for HTTP Sessions. Add the annotated parameter to your

Show Detail

How to tell dropwizard-swagger/swagger-ui that there is no request body on a resource method?

I'm integrating dropwizard-swagger into a large existing project. I've got the Swagger UI endpoint up and running now, but I'm noticing that it seems adamant that every method must have a body par...

Show Detail

How to use swagger with dropwizard .0.7.0

I have the latest dropwizard setup. Now I have created a simple API and I am trying to add Swagger on top. There is a Swagger implementation for dropwizard but the sample code is against Yammer

Show Detail

Swagger integration into Dropwizard

I am fairly new to drop wizard (dropwizard.io) &amp; just completed their tutorial. I would like to integrate Swagger (swagger.io) into this sample app. I found: github.com/federecio/dropwizard-sw...

Show Detail

Swagger UI into dropwizard

I added folder dist from swagger-ui github and provide path to openapi.yaml in index.html url: &quot;/openapi/openapi.yaml&quot; Now I can see UI by the address http://localhost:63342/dropwizard-e...

Show Detail