Skip to content

Commit

Permalink
GEODE-10312: Fix the v1/v3 mismatch. (#7720)
Browse files Browse the repository at this point in the history
* Remove SpringBootApplication annotation from swagger APIs.
* Change v1 to v3 in swagger api-docs URLs.
  • Loading branch information
Patrick Johnson authored Jun 1, 2022
1 parent 7578407 commit eedbe29
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static void beforeClass() throws IOException {

client = new GeodeDevRestClient("/management", "localhost", locator.getHttpPort(), false);
JsonNode jsonObject =
client.doGetAndAssert("/v1/api-docs").getJsonObject().get("paths");
client.doGetAndAssert("/v3/api-docs").getJsonObject().get("paths");
Iterator<Map.Entry<String, JsonNode>> urls = jsonObject.fields();
while (urls.hasNext()) {
Map.Entry<String, JsonNode> url = urls.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public void testWithSecurityManager() {

// Unsecured no credentials
assertResponse(client.doGet("/swagger-ui.html", null, null)).hasStatusCode(200);
assertResponse(client.doGet("/v1/api-docs", null, null)).hasStatusCode(200);
assertResponse(client.doGet("/v3/api-docs", null, null)).hasStatusCode(200);

// unsecured with credentials
assertResponse(client.doGet("/swagger-ui.html", "cluster", "cluster")).hasStatusCode(200);
assertResponse(client.doGet("/v1/api-docs", "cluster", "cluster")).hasStatusCode(200);
assertResponse(client.doGet("/v3/api-docs", "cluster", "cluster")).hasStatusCode(200);

// secured with credentials
assertResponse(client.doGet("/v1", "data", "data")).hasStatusCode(200);
Expand All @@ -67,11 +67,11 @@ public void testWithoutSecurityManager() {

// Unsecured no credentials
assertResponse(client.doGet("/swagger-ui.html", null, null)).hasStatusCode(200);
assertResponse(client.doGet("/v1/api-docs", null, null)).hasStatusCode(200);
assertResponse(client.doGet("/v3/api-docs", null, null)).hasStatusCode(200);

// unsecured with credentials
assertResponse(client.doGet("/swagger-ui.html", "cluster", "cluster")).hasStatusCode(200);
assertResponse(client.doGet("/v1/api-docs", "cluster", "cluster")).hasStatusCode(200);
assertResponse(client.doGet("/v3/api-docs", "cluster", "cluster")).hasStatusCode(200);

// secured with credentials
assertResponse(client.doGet("/v1", "data", "data")).hasStatusCode(200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public void testWithSecurityManager() {

// Unsecured no credentials
assertResponse(client.doGet("/swagger-ui.html", null, null)).hasStatusCode(200);
assertResponse(client.doGet("/v1/api-docs", null, null)).hasStatusCode(200);
assertResponse(client.doGet("/v3/api-docs", null, null)).hasStatusCode(200);

// unsecured with credentials
assertResponse(client.doGet("/swagger-ui.html", "cluster", "cluster")).hasStatusCode(200);
assertResponse(client.doGet("/v1/api-docs", "cluster", "cluster")).hasStatusCode(200);
assertResponse(client.doGet("/v3/api-docs", "cluster", "cluster")).hasStatusCode(200);

// secured with credentials
assertResponse(client.doGet("/v1/regions", "cluster", "cluster")).hasStatusCode(200);
Expand All @@ -66,11 +66,11 @@ public void testWithoutSecurityManager() {

// Unsecured no credentials
assertResponse(client.doGet("/swagger-ui.html", null, null)).hasStatusCode(200);
assertResponse(client.doGet("/v1/api-docs", null, null)).hasStatusCode(200);
assertResponse(client.doGet("/v3/api-docs", null, null)).hasStatusCode(200);

// unsecured with credentials
assertResponse(client.doGet("/swagger-ui.html", "cluster", "cluster")).hasStatusCode(200);
assertResponse(client.doGet("/v1/api-docs", "cluster", "cluster")).hasStatusCode(200);
assertResponse(client.doGet("/v3/api-docs", "cluster", "cluster")).hasStatusCode(200);

// secured with credentials
assertResponse(client.doGet("/v1/regions", "cluster", "cluster")).hasStatusCode(200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void isSwaggerRunning() throws Exception {

// Check the JSON
JsonNode json =
assertResponse(client.get("/management/v1/api-docs")).hasStatusCode(200)
assertResponse(client.get("/management/v3/api-docs")).hasStatusCode(200)
.getJsonObject();
assertThat(json.get("openapi").asText(), is("3.0.1"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void isSwaggerRunning() throws Exception {

// Check the JSON
JsonNode json =
assertResponse(client.get("/geode/v1/api-docs")).hasStatusCode(200)
assertResponse(client.get("/geode/v3/api-docs")).hasStatusCode(200)
.getJsonObject();
assertThat(json.get("openapi").asText(), is("3.0.1"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ protected void configure(HttpSecurity http) throws Exception {

http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests()
.antMatchers("/docs/**", "/swagger-ui.html", "/swagger-ui/index.html",
.antMatchers("/docs/**", "/swagger-ui.html", "/swagger-ui/index.html", "/swagger-ui/**",
Links.URI_VERSION + "/api-docs/**", "/webjars/springdoc-openapi-ui/**",
"/swagger-resources/**")
"/v3/api-docs/**", "/swagger-resources/**")
.permitAll().and().csrf().disable();

if (authProvider.getSecurityService().isIntegratedSecurity()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,59 @@
package org.apache.geode.rest.internal.web.swagger.config;



import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration;
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;


@PropertySource({"classpath:swagger.properties"})
@SpringBootApplication(exclude = {TransactionAutoConfiguration.class, LdapAutoConfiguration.class})
@EnableWebMvc
@Configuration("swaggerConfigApi")
@ComponentScan(basePackages = {"org.springdoc"})
@SuppressWarnings("unused")
public class SwaggerConfig {
public class SwaggerConfig implements WebApplicationInitializer {

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
WebApplicationContext context = getContext();
servletContext.addListener(new ContextLoaderListener(context));
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("geode",
new DispatcherServlet(context));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/*");
}

private AnnotationConfigWebApplicationContext getContext() {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.scan("org.apache.geode.rest");
context.register(this.getClass(), org.springdoc.webmvc.ui.SwaggerConfig.class,
org.springdoc.core.SwaggerUiConfigProperties.class,
org.springdoc.core.SwaggerUiOAuthProperties.class,
org.springdoc.webmvc.core.SpringDocWebMvcConfiguration.class,
org.springdoc.webmvc.core.MultipleOpenApiSupportConfiguration.class,
org.springdoc.core.SpringDocConfiguration.class,
org.springdoc.core.SpringDocConfigProperties.class,
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration.class);

return context;
}

@Bean
public GroupedOpenApi api() {
Expand Down
4 changes: 2 additions & 2 deletions geode-web-api/src/main/resources/swagger.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
#
springdoc.api-docs.path=/v1/api-docs
springdoc.swagger-ui.path=/swagger-ui.html
springdoc.swagger-ui.path=/swagger-ui.html
springdoc.writer-with-order-by-keys=true
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public boolean isMultipart(HttpServletRequest request) {
protected void configure(HttpSecurity http) throws Exception {
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests()
.antMatchers("/docs/**", "/swagger-ui.html", "/swagger-ui/index.html", "/",
Links.URI_VERSION + "/api-docs/**", "/webjars/springdoc-openapi-ui/**",
"/swagger-resources/**")
.antMatchers("/docs/**", "/swagger-ui.html", "/swagger-ui/index.html", "/swagger-ui/**",
"/", Links.URI_VERSION + "/api-docs/**", "/webjars/springdoc-openapi-ui/**",
"/v3/api-docs/**", "/swagger-resources/**")
.permitAll()
.and().csrf().disable();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,65 @@
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springdoc.core.GroupedOpenApi;
import org.springdoc.webmvc.ui.SwaggerUiHome;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration;
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import org.apache.geode.management.internal.rest.security.GeodeAuthenticationProvider;


@PropertySource({"classpath:swagger-management.properties"})
@SpringBootApplication(exclude = {TransactionAutoConfiguration.class, LdapAutoConfiguration.class})
@EnableWebMvc
@Configuration("swaggerConfigManagement")
@ComponentScan(basePackages = {"org.springdoc"},
excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,
classes = SwaggerUiHome.class))
@SuppressWarnings("unused")
public class SwaggerConfig {
public class SwaggerConfig implements WebApplicationInitializer {

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
WebApplicationContext context = getContext();
servletContext.addListener(new ContextLoaderListener(context));
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("geode",
new DispatcherServlet(context));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/*");
}

private AnnotationConfigWebApplicationContext getContext() {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.scan("org.apache.geode.management.internal.rest");
context.register(this.getClass(), org.springdoc.webmvc.ui.SwaggerConfig.class,
org.springdoc.core.SwaggerUiConfigProperties.class,
org.springdoc.core.SwaggerUiOAuthProperties.class,
org.springdoc.webmvc.core.SpringDocWebMvcConfiguration.class,
org.springdoc.webmvc.core.MultipleOpenApiSupportConfiguration.class,
org.springdoc.core.SpringDocConfiguration.class,
org.springdoc.core.SpringDocConfigProperties.class,
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration.class);

return context;
}

@Bean
public GroupedOpenApi api() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
#
springdoc.api-docs.path=/v1/api-docs
springdoc.swagger-ui.path=/swagger-ui.html
springdoc.swagger-ui.path=/swagger-ui.html
springdoc.writer-with-order-by-keys=true

0 comments on commit eedbe29

Please sign in to comment.