From 55268b96b722cfcccf2b61181699fc9764a89b44 Mon Sep 17 00:00:00 2001 From: Ravi Desai Date: Mon, 24 Nov 2025 23:11:11 +0530 Subject: [PATCH 1/8] Added git ignore entry to ignore MacOS .DS_Store files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 18afede..0a1624c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ target *.iws /dep out +.DS_Store \ No newline at end of file From 0da098cf7db2941fb58036facbd2d1b0af029015 Mon Sep 17 00:00:00 2001 From: Ravi Desai Date: Mon, 24 Nov 2025 23:13:32 +0530 Subject: [PATCH 2/8] Corrected LICENSE file and its checksum verification during maven release process --- LICENSE | 2 +- pom.xml | 35 ++++++++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/LICENSE b/LICENSE index d5fde92..37b45d4 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright © 2021 Vector Pro + Copyright © 2021 Vector Pro (teamvectorpro@googlegroups.com) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/pom.xml b/pom.xml index 80616e2..84d22da 100644 --- a/pom.xml +++ b/pom.xml @@ -286,15 +286,32 @@ - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.12 - true - - ossrh - https://s01.oss.sonatype.org/ - true - + org.apache.maven.plugins + maven-enforcer-plugin + 3.6.1 + + + enforce + + true + + + + LICENSE + + + + LICENSE + 52965201dab336f278d9ca6786e36b69cd0db6fbbac88d05923004518fe4166d + sha256 + + + + + enforce + + + From 228f3f9da7c1e997752da17e73d8e425b1b34e44 Mon Sep 17 00:00:00 2001 From: Ravi Desai Date: Mon, 24 Nov 2025 23:15:09 +0530 Subject: [PATCH 3/8] Fixed a test case which was working while executed individually but was failing while running a test suite due to static OpenApiContext by cleaning the context after every test case execution --- .../dropwizard/swagger/DefaultServerWithContactTest.java | 2 -- .../dropwizard/swagger/DropwizardCommonTest.java | 8 ++++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/test/java/in/vectorpro/dropwizard/swagger/DefaultServerWithContactTest.java b/src/test/java/in/vectorpro/dropwizard/swagger/DefaultServerWithContactTest.java index 5448492..63ff077 100644 --- a/src/test/java/in/vectorpro/dropwizard/swagger/DefaultServerWithContactTest.java +++ b/src/test/java/in/vectorpro/dropwizard/swagger/DefaultServerWithContactTest.java @@ -21,7 +21,6 @@ import io.restassured.RestAssured; import org.eclipse.jetty.http.HttpStatus; import org.hamcrest.core.StringContains; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -37,7 +36,6 @@ public DefaultServerWithContactTest() { } @Test - @Disabled("passes when ran standalone, but fails inside the suite") void swaggerHasContactInfo() { RestAssured.expect() .statusCode(HttpStatus.OK_200) diff --git a/src/test/java/in/vectorpro/dropwizard/swagger/DropwizardCommonTest.java b/src/test/java/in/vectorpro/dropwizard/swagger/DropwizardCommonTest.java index 3c59789..901dcc2 100644 --- a/src/test/java/in/vectorpro/dropwizard/swagger/DropwizardCommonTest.java +++ b/src/test/java/in/vectorpro/dropwizard/swagger/DropwizardCommonTest.java @@ -18,9 +18,12 @@ import com.google.common.base.Joiner; import com.google.common.base.Splitter; import io.restassured.RestAssured; +import io.swagger.v3.oas.integration.OpenApiContextLocator; import java.util.ArrayList; import java.util.List; +import org.apache.commons.lang3.reflect.FieldUtils; import org.eclipse.jetty.http.HttpStatus; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -39,6 +42,11 @@ public void setPort() { RestAssured.port = port; } + @AfterAll + public static void clearOpenApiContext() throws IllegalAccessException { + FieldUtils.writeStaticField(OpenApiContextLocator.class, "instance", null, true); + } + @Test public void resourceIsAvailable() { RestAssured.expect().statusCode(HttpStatus.OK_200).when().get(Path.from(basePath, "test.json")); From 5f010a5c4226dff5e96bf3237b309511e1a99509 Mon Sep 17 00:00:00 2001 From: Ravi Desai Date: Mon, 24 Nov 2025 23:34:57 +0530 Subject: [PATCH 4/8] Added support for swagger snippet generation using library referenced below List of snippet generation targets can be configured using SwaggerViewConfiguration Default list has been provided in case user doesn't configure the same Reference Link: https://github.com/tronto20/swagger-snippet-generator/releases/tag/v0.15.2 --- .../dropwizard/swagger/SwaggerView.java | 29 ++--------- .../swagger/SwaggerViewConfiguration.java | 34 +++++++++++-- .../in/vectorpro/dropwizard/swagger/index.ftl | 49 +++++++------------ .../swagger-snippet-generator.min.js | 2 + 4 files changed, 53 insertions(+), 61 deletions(-) create mode 100644 src/main/resources/swagger-static/swagger-snippet-generator.min.js diff --git a/src/main/java/in/vectorpro/dropwizard/swagger/SwaggerView.java b/src/main/java/in/vectorpro/dropwizard/swagger/SwaggerView.java index 884fcda..77eb566 100644 --- a/src/main/java/in/vectorpro/dropwizard/swagger/SwaggerView.java +++ b/src/main/java/in/vectorpro/dropwizard/swagger/SwaggerView.java @@ -86,32 +86,9 @@ public String getContextPath() { return contextPath; } - /** - * Returns the location of the validator URL or null to disable - * - * @return String - */ - @Nullable - public String getValidatorUrl() { - return viewConfiguration.getValidatorUrl(); - } - - /** - * Returns whether to display the authorization input boxes - * - * @return String - */ - public boolean getShowAuth() { - return viewConfiguration.isShowAuth(); - } - - /** - * Returns whether to display the swagger spec selector - * - * @return boolean - */ - public boolean getShowApiSelector() { - return viewConfiguration.isShowApiSelector(); + /** @return {@link SwaggerViewConfiguration} containing every properties to customize swagger */ + public SwaggerViewConfiguration getViewConfiguration() { + return viewConfiguration; } /** @return {@link SwaggerOAuth2Configuration} containing every properties to init oauth2 */ diff --git a/src/main/java/in/vectorpro/dropwizard/swagger/SwaggerViewConfiguration.java b/src/main/java/in/vectorpro/dropwizard/swagger/SwaggerViewConfiguration.java index d18fc52..bc5a02c 100644 --- a/src/main/java/in/vectorpro/dropwizard/swagger/SwaggerViewConfiguration.java +++ b/src/main/java/in/vectorpro/dropwizard/swagger/SwaggerViewConfiguration.java @@ -15,6 +15,8 @@ */ package in.vectorpro.dropwizard.swagger; +import com.google.common.collect.Sets; +import java.util.Set; import javax.annotation.Nullable; /** @@ -25,22 +27,30 @@ public class SwaggerViewConfiguration { private static final String DEFAULT_TITLE = "Swagger UI"; private static final String DEFAULT_TEMPLATE = "index.ftl"; + private static final Set DEFAULT_CODE_SNIPPET_TARGETS = Sets.newHashSet("shell_wget", "python_requests", + "java_okhttp", "node_request", "go_native"); - @Nullable private String pageTitle; + @Nullable + private String pageTitle; - @Nullable private String templateUrl; + @Nullable + private String templateUrl; - @Nullable private String validatorUrl; + @Nullable + private String validatorUrl; private boolean showApiSelector; private boolean showAuth; + private Set codeSnippetTargets; + public SwaggerViewConfiguration() { this.pageTitle = DEFAULT_TITLE; this.templateUrl = DEFAULT_TEMPLATE; this.validatorUrl = null; this.showApiSelector = true; this.showAuth = true; + this.codeSnippetTargets = DEFAULT_CODE_SNIPPET_TARGETS; } @Nullable @@ -85,4 +95,22 @@ public boolean isShowAuth() { public void setShowAuth(boolean showAuth) { this.showAuth = showAuth; } + + public Set getCodeSnippetTargets() { + return codeSnippetTargets; + } + + public void setCodeSnippetTargets(Set codeSnippetTargets) { + + this.codeSnippetTargets = codeSnippetTargets; + + // Syntax highlighting with swagger snippet generator js works only if node is included in the snippet targets + // Otherwise snippets are generated without syntax highlighting + // Hence identifying if node is missing and adding it to the set + final boolean noTargetStartsWithNode = this.codeSnippetTargets.stream() + .noneMatch(target -> target.startsWith("node")); + if (noTargetStartsWithNode) { + this.codeSnippetTargets.add("node_request"); + } + } } diff --git a/src/main/resources/in/vectorpro/dropwizard/swagger/index.ftl b/src/main/resources/in/vectorpro/dropwizard/swagger/index.ftl index 2a52579..3957991 100644 --- a/src/main/resources/in/vectorpro/dropwizard/swagger/index.ftl +++ b/src/main/resources/in/vectorpro/dropwizard/swagger/index.ftl @@ -4,67 +4,52 @@ - Swagger UI - + ${viewConfiguration.pageTitle} + + -
- + +