Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger integration into Dropwizard

I am fairly new to drop wizard (dropwizard.io) and just completed their tutorial. I would like to integrate Swagger (swagger.io) into this sample app. I found:

  • github.com/federecio/dropwizard-swagger-sample-app
  • github.com/federecio/dropwizard-swagger

The generated JSON seems to be quite similar, however I cannot expand the REST resources to see their respective operations. The only difference I noted was that the example code of the swagger integration uses SERVER whereas the official drop wizard example is using APPLICATION

Here an Image

Please could you tell me what is wrong in my approach?

Here is the code to my approach: https://github.com/geoHeil/dropwizardSwaggerIntegrationNotWorking

Edit:

for api - docs {
  "apiVersion": "0.0",
  "swaggerVersion": "1.2",
  "apis": [{
    "path": "/sample"
  }, {
    "path": "/hello-world",
    "description": "Operations about greetings"
  }]
}


for sample {
  "apiVersion": "0.0",
  "swaggerVersion": "1.2",
  "basePath": "http://geoHeil.local:8080",
  "resourcePath": "/sample",
  "apis": [{
    "path": "/sample",
    "operations": [{
      "method": "GET",
      "summary": "Sample endpoint",
      "notes": "",
      "type": "void",
      "nickname": "get",
      "authorizations": {},
      "parameters": []
    }]
  }, {
    "path": "/sample/hello-with-path-param/{name}",
    "operations": [{
      "method": "GET",
      "summary": "Sample endpoint with path param",
      "notes": "",
      "type": "void",
      "nickname": "getWithPathParam",
      "authorizations": {},
      "parameters": [{
        "name": "name",
        "required": true,
        "type": "string",
        "paramType": "path"
      }]
    }]
  }, {
    "path": "/sample/hello-with-query-param",
    "operations": [{
      "method": "GET",
      "summary": "Sample endpoint with query param",
      "notes": "",
      "type": "void",
      "nickname": "getWithQueryParam",
      "authorizations": {},
      "parameters": [{
        "name": "name",
        "required": false,
        "type": "string",
        "paramType": "query"
      }]
    }]
  }]
}

for hello - world {
  "apiVersion": "0.0",
  "swaggerVersion": "1.2",
  "basePath": "http://geoHeil.local:8080",
  "resourcePath": "/hello-world",
  "apis": [{
    "path": "/hello-world",
    "operations": [{
      "method": "GET",
      "summary": "Greetings endpoint",
      "notes": "",
      "type": "void",
      "nickname": "sayHello",
      "authorizations": {},
      "parameters": [{
        "name": "name",
        "required": false,
        "items": {
          "type": "string"
        },
        "paramType": "query"
      }]
    }]
  }]
}
like image 556
Georg Heiler Avatar asked May 26 '26 08:05

Georg Heiler


1 Answers

There is now a Swagger spec 2.0 example available:

https://github.com/swagger-api/swagger-samples/tree/master/java/java-dropwizard

This uses the latest swagger core libraries with minimal dependencies. Note, the version of Jackson needed to be updated from dropwizard's 2.3.2 to swagger's 2.4.2.

like image 177
fehguy Avatar answered May 30 '26 05:05

fehguy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!