Skip to content

Commit

Permalink
Replace FireFox with Chrome (federecio#51)
Browse files Browse the repository at this point in the history
* [maven-release-plugin] rollback the release of v1.0.0-2

* Added a sample application to view the documentation from within this repo

* Try replacing FireFox with Chrome. The tests are more reliable, but now we're getting ElementNotVisibleExceptions :(

* Upgrade to swagger-ui 2.2.5 and remove custom auth UI code in favor of SecurityDefinition annotations

* Tests with Chrome are now passing. This requires the next SNAPSHOT release of swagger-core to fix an issue with the ApiKeys
  • Loading branch information
jplock committed Oct 3, 2016
1 parent fd0faac commit f4dafa4
Show file tree
Hide file tree
Showing 16 changed files with 877 additions and 541 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dropwizard-swagger

a Dropwizard bundle that serves Swagger UI static content and loads Swagger endpoints. Swagger UI static content is taken from https://github.com/swagger-api/swagger-ui

Current version has been tested with Dropwizard 1.0.0 and Swagger 1.5.10 which supports Swagger 2 spec!
Current version has been tested with Dropwizard 1.0.2 and Swagger 1.5.10 which supports Swagger 2 spec!

Note: if you come from previous versions there have been some changes in the way the bundle is configured, see details below.

Expand All @@ -27,7 +27,7 @@ dropwizard-swagger| Dropwizard |Swagger API|Swagger UI
0.7.x | 0.8.x | 1.5.1-M2| v2.1.4-M1
0.7.2 | 0.8.4 | 1.5.3 | v2.1.2
0.9.x | 0.9.x | 1.5.9 | v2.1.5
1.0.x | 1.0.x | 1.5.10 | v2.2.2
1.0.x | 1.0.x | 1.5.10 | v2.2.5

How to use it
-------------
Expand All @@ -38,7 +38,7 @@ How to use it
<dependency>
<groupId>com.smoketurner</groupId>
<artifactId>dropwizard-swagger</artifactId>
<version>1.0.0-1</version>
<version>1.0.2-1</version>
</dependency>
```

Expand Down Expand Up @@ -73,8 +73,8 @@ public void initialize(Bootstrap<YourConfiguration> bootstrap) {
protected SwaggerBundleConfiguration getSwaggerBundleConfiguration(YourConfiguration configuration) {
return configuration.swaggerBundleConfiguration;
}
}
});
});
}
```

* As usual, add Swagger annotations to your resource classes and methods
Expand Down
24 changes: 12 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.smoketurner</groupId>
<artifactId>dropwizard-swagger</artifactId>
<version>1.0.0-3-SNAPSHOT</version>
<version>1.0.2-1-SNAPSHOT</version>

<name>Dropwizard Swagger support</name>
<description>A simple way to document your REST APIs in DropWizard using Swagger</description>
Expand Down Expand Up @@ -56,12 +56,12 @@
</scm>

<properties>
<dropwizard.version>1.0.0</dropwizard.version>
<dropwizard.version>1.0.2</dropwizard.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<file.encoding>UTF-8</file.encoding>
<jdk.version>1.8</jdk.version>
<swagger.version>1.5.10</swagger.version>
<swagger.version>1.5.11-SNAPSHOT</swagger.version>
</properties>

<ciManagement>
Expand Down Expand Up @@ -134,6 +134,10 @@
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-auth</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-assets</artifactId>
Expand Down Expand Up @@ -224,7 +228,7 @@
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand All @@ -245,11 +249,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-auth</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
Expand Down Expand Up @@ -318,12 +317,12 @@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-javac-errorprone</artifactId>
<version>2.8</version>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>2.0.11</version>
<version>2.0.13</version>
</dependency>
</dependencies>
</plugin>
Expand Down Expand Up @@ -430,7 +429,7 @@
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.2.0</version>
<version>4.3.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
Expand Down Expand Up @@ -488,6 +487,7 @@
<exclude>**/.gitattributes</exclude>
<exclude>src/test/resources/**</exclude>
<exclude>src/main/resources/**</exclude>
<exclude>src/main/java/io/federecio/dropwizard/sample/**</exclude>
<exclude>src/site/**</exclude>
<exclude>*.xml</exclude>
<exclude>*.sh</exclude>
Expand Down
20 changes: 20 additions & 0 deletions sample.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Swagger-specific options.
swagger:

resourcePackage: io.federecio.dropwizard.sample
title: Sample API
version: v1
description: Sample service API
contact: [email protected]
license: Apache 2.0
licenseUrl: https://www.apache.org/licenses/LICENSE-2.0

# HTTP-specific options.
server:

type: simple
applicationContextPath: /
adminContextPath: /admin
connector:
type: http
port: 8080
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package io.federecio.dropwizard.sample;

import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature;
import io.dropwizard.Application;
import io.dropwizard.auth.AuthDynamicFeature;
import io.dropwizard.auth.AuthValueFactoryProvider;
import io.dropwizard.auth.PrincipalImpl;
import io.dropwizard.auth.basic.BasicCredentialAuthFilter;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import io.federecio.dropwizard.swagger.SwaggerBundle;
import io.federecio.dropwizard.swagger.SwaggerBundleConfiguration;

public class SampleApplication extends Application<SampleConfiguration> {

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

@Override
public String getName() {
return "sample";
}

@Override
public void initialize(Bootstrap<SampleConfiguration> bootstrap) {
bootstrap.addBundle(new SwaggerBundle<SampleConfiguration>() {
@Override
protected SwaggerBundleConfiguration getSwaggerBundleConfiguration(
SampleConfiguration configuration) {
return configuration.getSwagger();
}
});
};

@Override
public void run(SampleConfiguration configuration, Environment environment)
throws Exception {

environment.jersey().register(new AuthDynamicFeature(
new BasicCredentialAuthFilter.Builder<PrincipalImpl>()
.setAuthenticator(new SampleAuthenticator())
.setRealm("SUPER SECRET STUFF").buildAuthFilter()));
environment.jersey().register(RolesAllowedDynamicFeature.class);
environment.jersey().register(
new AuthValueFactoryProvider.Binder<>(PrincipalImpl.class));

// resources
environment.jersey().register(new SampleResource());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.federecio.dropwizard.sample;

import java.util.Optional;
import io.dropwizard.auth.AuthenticationException;
import io.dropwizard.auth.Authenticator;
import io.dropwizard.auth.PrincipalImpl;
import io.dropwizard.auth.basic.BasicCredentials;

public class SampleAuthenticator
implements Authenticator<BasicCredentials, PrincipalImpl> {

@Override
public Optional<PrincipalImpl> authenticate(BasicCredentials credentials)
throws AuthenticationException {
if ("secret".equals(credentials.getPassword())) {
return Optional.of(new PrincipalImpl(credentials.getUsername()));
}
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.federecio.dropwizard.sample;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.dropwizard.Configuration;
import io.federecio.dropwizard.swagger.SwaggerBundleConfiguration;

public class SampleConfiguration extends Configuration {

@Valid
@NotNull
private final SwaggerBundleConfiguration swagger = new SwaggerBundleConfiguration();

@JsonProperty("swagger")
public SwaggerBundleConfiguration getSwagger() {
return swagger;
}
}
40 changes: 40 additions & 0 deletions src/main/java/io/federecio/dropwizard/sample/SampleResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.federecio.dropwizard.sample;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import io.dropwizard.auth.Auth;
import io.dropwizard.auth.PrincipalImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.BasicAuthDefinition;
import io.swagger.annotations.SecurityDefinition;
import io.swagger.annotations.SwaggerDefinition;

@Api("/")
@Path("/")
@SwaggerDefinition(securityDefinition = @SecurityDefinition(basicAuthDefinions = {
@BasicAuthDefinition(key = "sample") }))
public class SampleResource {

@GET
@Path("/hello")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Hello", notes = "Returns hello")
@ApiResponses(value = { @ApiResponse(code = 200, message = "hello") })
public Saying hello() {
return new Saying("hello");
}

@GET
@Path("/secret")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Secret", notes = "Returns secret")
@ApiResponses(value = { @ApiResponse(code = 200, message = "secret") })
public Saying secret(@Auth PrincipalImpl user) {
return new Saying("secret");
}
}
17 changes: 17 additions & 0 deletions src/main/java/io/federecio/dropwizard/sample/Saying.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.federecio.dropwizard.sample;

import com.fasterxml.jackson.annotation.JsonProperty;

public class Saying {

private final String message;

public Saying(String message) {
this.message = message;
}

@JsonProperty
public String getMessage() {
return message;
}
}
55 changes: 0 additions & 55 deletions src/main/resources/io/federecio/dropwizard/swagger/index.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
onComplete: function(swaggerApi, swaggerUi){
if(typeof initOAuth == "function") {
/*
initOAuth({
clientId: "your-client-id",
clientSecret: "your-client-secret-if-required",
Expand All @@ -62,7 +61,6 @@
scopeSeparator: " ",
additionalQueryStringParams: {}
});
*/
}
if(window.SwaggerTranslator) {
Expand All @@ -79,51 +77,6 @@
showRequestHeaders: false
});
<#if showAuth>
function addApiKeyAuthorization() {
var key = encodeURIComponent($('#input_apiKey')[0].value);
if (key && key.trim() != "") {
var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("api_key", key, "query");
window.swaggerUi.api.clientAuthorizations.add("api_key", apiKeyAuth);
log("added key " + key);
}
}
function addAuthorizationHeader() {
var key = $('#input_authHeader')[0].value;
if (key && key.trim() != "") {
var headerAuth = new SwaggerClient.ApiKeyAuthorization("Authorization", key, "header");
window.swaggerUi.api.clientAuthorizations.add("Custom Authorization", headerAuth);
log("added key " + key);
}
}
$('#input_apiKey').change(addApiKeyAuthorization);
$('#input_authHeader').change(addAuthorizationHeader);
$('#input_headerSelect').change(function() {
var toShow = $( this ).val();
$('#header_'+toShow).show();
var toHide = (Number(toShow)+1)%2;
$('#header_'+toHide).hide();
});
// if you have an apiKey you would like to pre-populate on the page for demonstration purposes...
/*
var apiKey = "myApiKeyXXXX123456789";
$('#input_apiKey').val(apiKey);
addApiKeyAuthorization();
*/
<#else>
$('#input_apiKey').hide();
$('#input_authHeader').hide();
$('#input_headerSelect').hide();
</#if>
<#if !showApiSelector>
$('#explore').hide();
$('#input_baseUrl').hide();
</#if>
window.swaggerUi.load();
function log() {
Expand All @@ -141,14 +94,6 @@
<a id="logo" href="http://swagger.io"><img class="logo__img" alt="swagger" height="30" width="30" src="${swaggerAssetsPath}/images/logo_small.png" /><span class="logo__title">swagger</span></a>
<form id='api_selector'>
<div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
<div class='input'>
<select id="input_headerSelect">
<option value="0">api_key</option>
<option value="1">Auth Header</option>
</select>
</div>
<div class='input' id="header_0"><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text"/></div>
<div class='input' id="header_1" style="display: none;"><input placeholder="Basic ..." id="input_authHeader" name="authHeader" type="text"/></div>
<div id='auth_container'></div>
<div class='input'><a id="explore" class="header__btn" href="#" data-sw-translate>Explore</a></div>
</form>
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/swagger-static/lib/sanitize-html.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit f4dafa4

Please sign in to comment.