Zon
Zon

Reputation: 19880

How to Disable Spring Rest Docs

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.

Upvotes: 0

Views: 648

Answers (2)

Julien
Julien

Reputation: 1925

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

Upvotes: 0

Zon
Zon

Reputation: 19880

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

Upvotes: 1

Related Questions