0

PROBLEM I use Spring Rest Docs in my project. It is useful at development stage, but i don't want it to be available for ordinary users and search engines in production.

RESEARCH I see no robot meta tags with content like "nocache" & "noindex". What is expected actually is maybe a spring application.property field like spring.rest-docs.enabled=false. So that I can configure it in production spring profile.

QUESTION How to disable rest docs for some spring profiles.

Zon
  • 18,610
  • 7
  • 91
  • 99
  • 2
    `@Profile` that bean. – Eugene May 06 '21 at 18:06
  • Spring REST Docs should only be used in your application's tests. When you say you "don't want it to be available", what is it, precisely, that you don't want to be available? Perhaps some HTML-based documentation that Asciidoctor has produced using the snippets that Spring REST Docs has generated? – Andy Wilkinson May 09 '21 at 16:23
  • Yupp. It is copied by Maven to a /resources/static/docs folder. – Zon May 10 '21 at 06:58

2 Answers2

1

There were three ways to do it:

  • (failed) block a test with test-class annotations (couldn't setup it to work): @IfProfileValue(name = "spring.profiles.active", values = {"prod"}) or @EnabledIf("${spring.restdocs.enabled}")
  • (failed) configure maven-resources-plugin to work with maven-profiles and spring profiles (looked too cumbersome): https://stackoverflow.com/a/45817386/1112963
  • (worked) disable /resources/static folder access in application-prod.properties with spring.resources.add-mappings=false
Zon
  • 18,610
  • 7
  • 91
  • 99
0

You can add this property to your application.properties

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

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

Configuration available during MockMvc setup:

failOnUndocumentedParams - if build should fail on at least one undocumented parameter failOnUndocumentedFields - if build should fail on at least one undocumented field

Julien
  • 1,765
  • 20
  • 26