I am trying to migrate to springdoc-openapi;
(我正在尝试迁移到springdoc-openapi;)
Everything runs great except being able to run unit-tests from mvn; (除了能够运行mvn的单元测试外,其他所有功能都运行良好;)
The following maven command results in a 404: (以下maven命令生成404:)
Intellij has no problem running it, so I suspect that it is a classloading issue.
(Intellij运行它没有问题,所以我怀疑这是一个类加载问题。)
I have used the code from the example below and just added my unit-test
(我使用了下面示例中的代码,并添加了我的单元测试)
Guthub code: - https://github.com/eugenp/tutorials/tree/master/spring-boot-springdoc
(Guthub代码:-https: //github.com/eugenp/tutorials/tree/master/spring-boot-springdoc)
For the unit-test I added to the pom.xml: (I use rest-assured to check if the swagger-ui page exists)
(对于添加到pom.xml中的单元测试:(我使用rest-assured检查swagger-ui页面是否存在))
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
<version>3.0.2</version>
</dependency>
The test itself:
(测试本身:)
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class SwaggerUITest extends AbstractRestAssuredSetupClass {
/**
* Test successful swagger-UI call
**/
@Test
public void getSwaggerUIPage() {
givenAnAdministratorIsAuthenticated()
.contentType(HTML)
.get("/swagger-ui/index.html?url=/v3/api-docs")
.then()
.statusCode(OK.value());
}
}
public abstract class AbstractRestAssuredSetupClass {
@Value("${request.logging.enabled:true}")
private boolean logRequests;
@Value("${response.logging.enabled:true}")
private boolean logResponses;
@Value("${local.server.port}")
private int port;
@Before
public void setUpRestAssured() {
RestAssured.baseURI = "http://localhost:" + port;
RestAssured.config = config().redirect(redirectConfig().followRedirects(false));
if (logRequests) {
RestAssured.filters(new RequestLoggingFilter());
}
if (logResponses) {
RestAssured.filters(new ResponseLoggingFilter());
}
}
protected RequestSpecification givenAnAdministratorIsAuthenticated() {
return RestAssured.given().auth().preemptive().basic("user", "user");
}
}
I found also someone that has the same problem: https://github.com/springdoc/springdoc-openapi/issues/99
(我也发现有人遇到相同的问题: https : //github.com/springdoc/springdoc-openapi/issues/99)
Unfortunately no solution.
(不幸的是没有解决办法。)
I could also go back to springfox. (我也可以回到springfox。)
Issues like this caused me to migrate: https://github.com/springfox/springfox/issues/2932 . (这样的问题导致我迁移: https : //github.com/springfox/springfox/issues/2932 。)
ask by Dave Weernink translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…