本文介绍了springdoc-openapi-maven-plugin配置/apiDocsUrl的作用是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行 springdoc-openapi-maven-plugin,具有以下(标准)配置:

I'm running the springdoc-openapi-maven-plugin, with the following (standard) configuration:

        <plugin>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-maven-plugin</artifactId>
            <version>0.2</version>
            <executions>
                <execution>
                    <id>integration-test</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

插件似乎可以运行,但没有输出.

The plugin appears to run, but there is no output.

我在 Maven 输出中收到 404 错误:

I am getting a 404 error in the Maven output:

[INFO] --- springdoc-openapi-maven-plugin:0.2:generate (integration-test) @ paatinc-util-websrv ---
10:40:33.930 [http-nio-8080-exec-1] INFO  o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring DispatcherServlet 'dispatcherServlet'
10:40:33.931 [http-nio-8080-exec-1] INFO  o.s.web.servlet.DispatcherServlet - Initializing Servlet 'dispatcherServlet'
10:40:33.956 [http-nio-8080-exec-1] INFO  o.s.web.servlet.DispatcherServlet - Completed initialization in 25 ms
10:40:33.969 [http-nio-8080-exec-1] INFO  io.paat.util.filter.LoggingFilter - GET http://localhost:8080/v3/api-docs from 127.0.0.1
[ERROR] An error has occured: Response code 404

我可以从我的日志中看到 404 正在调用:http://localhost:8080/v3/api-docs

I can see from my log that the 404 is on a call to: http://localhost:8080/v3/api-docs

我还在 springdoc-openapi-maven-plugin 文档中看到以下配置:

I also see in the springdoc-openapi-maven-plugin docs the following configuration:

 <configuration>
  <apiDocsUrl>http://localhost:8080/v3/api-docs</apiDocsUrl>
  <outputFileName>openapi.json</outputFileName>
  <outputDir>/home/springdoc/maven-output</outputDir>
 </configuration>

因此,插件似乎在集成测试期间尝试打开本地服务器并且失败了.这有什么意义?我认为该插件会读取我的源文件并生成一个 openapi.json 文件.为什么需要与/v3/api-docs 建立 HTTP 连接?

So, it appears that the plugin is attempting to open the local server during integration tests and is failing. What is the point of this? I thought that the plugin would read though my source files and generate an openapi.json file. Why does it need to make an HTTP connection to /v3/api-docs?

推荐答案

通过使用 springdoc-openapi-ui,您可以在 runtime 生成文档(html、json 和 yaml)strong>,当您的应用部署时.

By using springdoc-openapi-ui you generate the documentation (html, json & yaml) at runtime, when your app is deployed.

在某些情况下,您可能希望在构建时拥有文档,这就是 springdoc-openapi-maven-plugin 的用途.为了使其正常工作,您还需要在集成阶段让您的应用程序开始使用 spring-boot,如 在文档中解释.

In some scenarios you may want to have the documentation at build time, and that's what the springdoc-openapi-maven-plugin is for. In order for it to work you need as well to have your application started using spring-boot during the integration phase, as explained in the documentation.

这篇关于springdoc-openapi-maven-plugin配置/apiDocsUrl的作用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 13:00