Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to disable the swagger validation URL #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void run(T configuration, Environment environment) throws Exception {
ConfigurationHelper configurationHelper = new ConfigurationHelper(configuration, swaggerBundleConfiguration);
new AssetsBundle(Constants.SWAGGER_RESOURCES_PATH, configurationHelper.getSwaggerUriPath(), null, Constants.SWAGGER_ASSETS_NAME).run(environment);

environment.jersey().register(new SwaggerResource(configurationHelper.getUrlPattern()));
environment.jersey().register(new SwaggerResource(configurationHelper.getUrlPattern(), swaggerBundleConfiguration.isValidationUrlDisabled()));
environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);

setUpSwagger(swaggerBundleConfiguration, configurationHelper.getUrlPattern());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public class SwaggerBundleConfiguration {
@JsonProperty
private String licenseUrl;

@JsonProperty
private boolean isValidationUrlDisabled;

/**
* For most of the scenarios this property is not needed.
* <p/>
Expand Down Expand Up @@ -141,6 +144,14 @@ public void setUriPrefix(String uriPrefix) {
this.uriPrefix = uriPrefix;
}

public boolean isValidationUrlDisabled() {
return isValidationUrlDisabled;
}

public void setIsValidationUrlDisabled(final boolean isValidationUrlDisabled) {
this.isValidationUrlDisabled = isValidationUrlDisabled;
}

@Override
public String toString() {
return "SwaggerBundleConfiguration{" +
Expand All @@ -152,6 +163,7 @@ public String toString() {
", contact='" + contact + '\'' +
", license='" + license + '\'' +
", licenseUrl='" + licenseUrl + '\'' +
", isValidationUrlDisabled='" + isValidationUrlDisabled + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
@Produces(MediaType.TEXT_HTML)
public class SwaggerResource {
private final String urlPattern;
private final boolean isValidationUrlDisabled;

public SwaggerResource(String urlPattern) {
public SwaggerResource(String urlPattern, final boolean isValidationUrlDisabled) {
this.urlPattern = urlPattern;
this.isValidationUrlDisabled = isValidationUrlDisabled;
}

@GET
public SwaggerView get() {
return new SwaggerView(urlPattern);
return new SwaggerView(urlPattern, isValidationUrlDisabled);
}
}
10 changes: 9 additions & 1 deletion src/main/java/io/federecio/dropwizard/swagger/SwaggerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ public class SwaggerView extends View {

private final String swaggerAssetsPath;
private final String contextPath;
private boolean isValidationUrlDisabled;

protected SwaggerView(String urlPattern) {
protected SwaggerView(String urlPattern, final boolean isValidationUrlDisabled) {
super("index.ftl", Charsets.UTF_8);

if (urlPattern.equals("/")) {
Expand All @@ -44,6 +45,8 @@ protected SwaggerView(String urlPattern) {
} else {
contextPath = urlPattern;
}

this.isValidationUrlDisabled = isValidationUrlDisabled;
}

/**
Expand All @@ -61,4 +64,9 @@ public String getSwaggerAssetsPath() {
public String getContextPath() {
return contextPath;
}

@SuppressWarnings("unused")
public boolean isValidationUrlDisabled() {
return isValidationUrlDisabled;
}
}
3 changes: 3 additions & 0 deletions src/main/resources/io/federecio/dropwizard/swagger/index.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
$(function () {
window.swaggerUi = new SwaggerUi({
url: "${contextPath}/swagger.json",
<#if validationUrlDisabled>
validatorUrl: null,
</#if>
dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
onComplete: function(swaggerApi, swaggerUi){
Expand Down