Skip to content

Using both generated and configured specs stoped working in 1.6.5 #2213

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

Merged
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 @@ -132,10 +132,11 @@ else if (swaggerUiConfigParameters.isValidUrl(swaggerUiUrl))
else
swaggerUiConfigParameters.addUrl(apiDocsUrl);
if (!CollectionUtils.isEmpty(swaggerUiConfig.getUrls())) {
swaggerUiConfigParameters.setUrls(swaggerUiConfig.cloneUrls());
swaggerUiConfigParameters.getUrls().forEach(swaggerUrl -> {
swaggerUiConfig.cloneUrls().forEach(swaggerUrl -> {
swaggerUiConfigParameters.getUrls().remove(swaggerUrl);
if (!swaggerUiConfigParameters.isValidUrl(swaggerUrl.getUrl()))
swaggerUrl.setUrl(buildUrlWithContextPath(swaggerUrl.getUrl()));
swaggerUiConfigParameters.getUrls().add(swaggerUrl);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package test.org.springdoc.ui.app1;

import org.junit.jupiter.api.Test;
import org.springframework.test.annotation.DirtiesContext;
import test.org.springdoc.ui.AbstractSpringDocActuatorTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand All @@ -30,6 +31,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;


@DirtiesContext
@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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
*
* * 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 org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import test.org.springdoc.ui.AbstractSpringDocActuatorTest;

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;

/*
Test showing how specs generated at runtime and specs configured in can work at the same time.

The expectation is that the openapi.yml file will be shown together with the generated ones.
*/
@DirtiesContext
@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=9002", "management.server.base-path=/demo/api",
"springdoc.swagger-ui.urls[0].url=/api-docs/xxx/v1/openapi.yml",
"springdoc.swagger-ui.urls[0].name=toto",
})
public class SpringDocSwaggerConfigWithBothFileGeneratedSpecsTest 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/api-docs/xxx/v1/openapi.yml")))
.andExpect(jsonPath("urls[1].name", equalTo("toto")))
.andExpect(jsonPath("urls[2].url", equalTo("/demo/api/v3/api-docs/x-actuator")))
.andExpect(jsonPath("urls[2].name", equalTo("x-actuator")));
}


@SpringBootApplication
static class SpringDocTestApp {}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package test.org.springdoc.api.app145;

import org.junit.jupiter.api.Test;
import org.springframework.test.annotation.DirtiesContext;
import test.org.springdoc.api.AbstractSpringDocActuatorTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand All @@ -32,6 +33,7 @@
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;


@DirtiesContext
@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT,
properties = { "management.endpoints.web.exposure.include=*",
"server.port=55594",
Expand Down