簡體   English   中英

如何禁用 Spring Rest 文檔

[英]How to Disable Spring Rest Docs

問題我在我的項目中使用Spring Rest 文檔 它在開發階段很有用,但我不希望它在生產中可供普通用戶和搜索引擎使用。

研究我沒有看到帶有“nocache”和“noindex”等內容的機器人元標記。 實際上預期的可能是 spring application.property 字段,例如spring.rest-docs.enabled=false 這樣我就可以在生產 spring 配置文件中配置它。

問題如何為某些 spring 配置文件禁用 rest 文檔。

有三種方法可以做到:

  • 失敗)使用測試類注釋阻止測試(無法將其設置為工作): @IfProfileValue(name = "spring.profiles.active", values = {"prod"})@EnabledIf("${spring.restdocs.enabled}")
  • 失敗)配置 maven-resources-plugin 以使用 maven-profiles 和 spring 配置文件(看起來太麻煩): https://stackoverflow.com/a/45817386/1112963
  • 有效)使用spring.resources.add-mappings=false禁用application-prod.properties中的/resources/static文件夾訪問

您可以將此屬性添加到您的application.properties

spring.test.restdocs.failOnUndocumentedFields=false
spring.test.restdocs.failOnUndocumentedParams=false

https://scacap.github.io/spring-auto-restdocs/#_configuration

在 MockMvc 設置期間可用的配置:

failOnUndocumentedParams - 如果構建應該在至少一個未記錄的參數上失敗 failOnUndocumentedFields - 如果構建應該在至少一個未記錄的字段上失敗

暫無
暫無

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

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