diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/docs/antora/modules/api/pages/rest/actuator/info.adoc b/spring-boot-project/spring-boot-actuator-autoconfigure/src/docs/antora/modules/api/pages/rest/actuator/info.adoc index e050c469594..b55397d9a8b 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/docs/antora/modules/api/pages/rest/actuator/info.adoc +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/docs/antora/modules/api/pages/rest/actuator/info.adoc @@ -47,3 +47,12 @@ include::partial$rest/actuator/info/response-fields-beneath-git.adoc[] NOTE: This is the "simple" output. The contributor can also be configured to output all available data. + + +[[info.retrieving.response-structure.os]] +==== OS Response Structure + +The following table describes the structure of the `os` section of the response: + +[cols="2,1,3"] +include::partial$rest/actuator/info/response-fields-beneath-os.adoc[] diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/info/InfoEndpointDocumentationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/info/InfoEndpointDocumentationTests.java index fe19095e8c6..b6860ca84a8 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/info/InfoEndpointDocumentationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/info/InfoEndpointDocumentationTests.java @@ -27,12 +27,15 @@ import org.springframework.boot.actuate.info.BuildInfoContributor; import org.springframework.boot.actuate.info.GitInfoContributor; import org.springframework.boot.actuate.info.InfoContributor; import org.springframework.boot.actuate.info.InfoEndpoint; +import org.springframework.boot.actuate.info.OsInfoContributor; import org.springframework.boot.info.BuildProperties; import org.springframework.boot.info.GitProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; +import org.springframework.restdocs.payload.FieldDescriptor; import org.springframework.restdocs.payload.JsonFieldType; +import org.springframework.restdocs.payload.ResponseFieldsSnippet; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.restdocs.payload.PayloadDocumentation.beneathPath; @@ -49,23 +52,40 @@ class InfoEndpointDocumentationTests extends MockMvcEndpointDocumentationTests { @Test void info() { assertThat(this.mvc.get().uri("/actuator/info")).hasStatusOk() - .apply(MockMvcRestDocumentation.document("info", - responseFields(beneathPath("git"), - fieldWithPath("branch").description("Name of the Git branch, if any."), - fieldWithPath("commit").description("Details of the Git commit, if any."), - fieldWithPath("commit.time").description("Timestamp of the commit, if any.") - .type(JsonFieldType.VARIES), - fieldWithPath("commit.id").description("ID of the commit, if any.")), - responseFields(beneathPath("build"), - fieldWithPath("artifact").description("Artifact ID of the application, if any.").optional(), - fieldWithPath("group").description("Group ID of the application, if any.").optional(), - fieldWithPath("name").description("Name of the application, if any.") - .type(JsonFieldType.STRING) - .optional(), - fieldWithPath("version").description("Version of the application, if any.").optional(), - fieldWithPath("time").description("Timestamp of when the application was built, if any.") - .type(JsonFieldType.VARIES) - .optional()))); + .apply(MockMvcRestDocumentation.document("info", gitInfo(), buildInfo(), osInfo())); + } + + private ResponseFieldsSnippet gitInfo() { + return responseFields(beneathPath("git"), + fieldWithPath("branch").description("Name of the Git branch, if any."), + fieldWithPath("commit").description("Details of the Git commit, if any."), + fieldWithPath("commit.time").description("Timestamp of the commit, if any.").type(JsonFieldType.VARIES), + fieldWithPath("commit.id").description("ID of the commit, if any.")); + } + + private ResponseFieldsSnippet buildInfo() { + return responseFields(beneathPath("build"), + fieldWithPath("artifact").description("Artifact ID of the application, if any.").optional(), + fieldWithPath("group").description("Group ID of the application, if any.").optional(), + fieldWithPath("name").description("Name of the application, if any.") + .type(JsonFieldType.STRING) + .optional(), + fieldWithPath("version").description("Version of the application, if any.").optional(), + fieldWithPath("time").description("Timestamp of when the application was built, if any.") + .type(JsonFieldType.VARIES) + .optional()); + } + + private ResponseFieldsSnippet osInfo() { + return responseFields(beneathPath("os"), osInfoField("name", "Name"), osInfoField("version", "Version"), + osInfoField("arch", "Architecture")); + } + + private FieldDescriptor osInfoField(String field, String desc) { + return fieldWithPath(field) + .description("Operating System " + desc + " (as obtained from the 'os." + field + "' system property).") + .type(JsonFieldType.STRING) + .optional(); } @Configuration(proxyBeanMethods = false) @@ -97,6 +117,11 @@ class InfoEndpointDocumentationTests extends MockMvcEndpointDocumentationTests { return new BuildInfoContributor(buildProperties); } + @Bean + OsInfoContributor osInfoContributor() { + return new OsInfoContributor(); + } + } }