From af63811a484e37320bd9fae6379d87e363c2da74 Mon Sep 17 00:00:00 2001 From: bnasslah Date: Sat, 2 Oct 2021 16:57:47 +0200 Subject: [PATCH] Inconsistent casing of swagger-config causes fetch error. Fixes #1277. --- .../AbstractSwaggerUiConfigProperties.java | 3 + .../ui/app1/SpringDocSwaggerConfigTest.java | 56 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app1/SpringDocSwaggerConfigTest.java diff --git a/springdoc-openapi-common/src/main/java/org/springdoc/core/AbstractSwaggerUiConfigProperties.java b/springdoc-openapi-common/src/main/java/org/springdoc/core/AbstractSwaggerUiConfigProperties.java index 4bc468932..97c813715 100644 --- a/springdoc-openapi-common/src/main/java/org/springdoc/core/AbstractSwaggerUiConfigProperties.java +++ b/springdoc-openapi-common/src/main/java/org/springdoc/core/AbstractSwaggerUiConfigProperties.java @@ -24,6 +24,7 @@ import java.util.Objects; import java.util.Set; +import com.fasterxml.jackson.annotation.JsonProperty; import org.springdoc.core.SwaggerUiConfigProperties.SyntaxHighlight; import static org.springdoc.core.Constants.GROUP_NAME_NOT_NULL; @@ -643,11 +644,13 @@ public static class SwaggerUrl { /** * The Url. */ + @JsonProperty("url") private String url; /** * The Name. */ + @JsonProperty("name") private String name; /** diff --git a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app1/SpringDocSwaggerConfigTest.java b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app1/SpringDocSwaggerConfigTest.java new file mode 100644 index 000000000..3ec16fc21 --- /dev/null +++ b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app1/SpringDocSwaggerConfigTest.java @@ -0,0 +1,56 @@ +/* + * + * * Copyright 2019-2020 the original author or authors. + * * + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * https://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * + */ + +package test.org.springdoc.ui.app1; + +import org.junit.jupiter.api.Test; +import test.org.springdoc.ui.AbstractSpringDocActuatorTest; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + properties = {"spring.jackson.property-naming-strategy=UPPER_CAMEL_CASE", "springdoc.show-actuator=true", + "management.endpoints.web.base-path=/management", + "server.servlet.context-path=/demo/api", "management.server.port=9001", "management.server.base-path=/demo/api" }) +public class SpringDocSwaggerConfigTest extends AbstractSpringDocActuatorTest { + + @Test + public void testIndexSwaggerConfig() throws Exception { + mockMvc.perform(get("/demo/api/v3/api-docs/swagger-config").contextPath("/demo/api")) + .andExpect(status().isOk()) + .andExpect(jsonPath("validatorUrl", equalTo(""))) + .andExpect(jsonPath("oauth2RedirectUrl", equalTo("http://localhost/demo/api/swagger-ui/oauth2-redirect.html"))) + .andExpect(jsonPath("url").doesNotExist()) + .andExpect(jsonPath("urls[0].url", equalTo("/demo/api/v3/api-docs/springdocDefault"))) + .andExpect(jsonPath("urls[0].name", equalTo("springdocDefault"))) + .andExpect(jsonPath("urls[1].url", equalTo("/demo/api/v3/api-docs/x-actuator"))) + .andExpect(jsonPath("urls[1].name", equalTo("x-actuator"))); + } + + + @SpringBootApplication + static class SpringDocTestApp {} + +} \ No newline at end of file