簡體   English   中英

如何將openapi本地文件加載到localhost上的swagger? (由 restdocs 生成的文件)

[英]How to load openapi local files into swagger on localhost? (Files generated by restdocs)

我的 api 文檔由 restdocs 通過單元測試生成。 盡管它可以很好地滿足我的大部分需求,但我仍然缺乏一些不錯的 swagger 功能,所以我試圖通過將 restdocs 轉換為 swagger 來充分利用這兩個詞。嘗試了很長時間后,我終於設法在一些第三方庫的幫助下完成它( https://github.com/ePages-de/restdocs-api-spec https://github.com/BerkleyTechnologyServices/restdocs-spec )。 這會在 static 文檔文件夾下生成打開的 api 文件。 但是,當我嘗試訪問 swagger url http://localhost:8081/swagger-ui/index.html時,它不會在那里顯示,如果直接在 88432188 上添加 swagger 注釋,默認情況下會起作用controller。我可以手動導入 openapi yml 文件並通過https://editor.swagger.io/查看它,但可能有更好的方法 map swagger 直接從我的代碼中自動找到 openapi 文件,這樣我就可以繼續使用這個默認swagger url?

謝謝你。

 <plugin>
        <groupId>io.github.berkleytechnologyservices</groupId>
            <artifactId>restdocs-spec-maven-plugin</artifactId>
            <version>${restdocs-spec.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <!--suppress MavenModelInspection -->
                        <skip>${skipTests}</skip>
                        <host>localhost:8081</host>
                        <specification>OPENAPI_V3</specification>
                        <outputDirectory>${project.build.directory}/classes/static/docs</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>

在此處輸入圖像描述

在此處輸入圖像描述

更新

嘗試使用資源文件夾下的文檔,但仍然出現相同的錯誤。 我在這里打開了一個包含詳細信息的新問題Failed to load api definition when loading files from application properties

![在此處輸入圖片描述

你需要將openapi規范yml放在資源文件夾中,並在spring啟動應用程序的application.properties文件中設置springdoc.swagger-ui.url=/openapi-3.yaml

檢查springdoc api 文檔

在應用程序屬性中需要確保

spring.web.resources.add-mappings=false

不應添加其阻止提供 static 內容。

openapi-3.0.yml也應該放在resources/static文件夾中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM