From c99521ff0faff563d4e3ad04a9005819671c21c6 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 20 May 2025 13:18:13 -0700 Subject: [PATCH] Document the os info contribution Closes gh-45565 --- .../modules/api/pages/rest/actuator/info.adoc | 9 +++ .../info/InfoEndpointDocumentationTests.java | 59 +++++++++++++------ 2 files changed, 51 insertions(+), 17 deletions(-) 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 8621e68d380..3f744925adb 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.springframework.restdocs.payload.PayloadDocumentation.beneathPath; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; @@ -51,23 +54,40 @@ class InfoEndpointDocumentationTests extends MockMvcEndpointDocumentationTests { void info() throws Exception { this.mockMvc.perform(get("/actuator/info")) .andExpect(status().isOk()) - .andDo(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()))); + .andDo(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) @@ -99,6 +119,11 @@ class InfoEndpointDocumentationTests extends MockMvcEndpointDocumentationTests { return new BuildInfoContributor(buildProperties); } + @Bean + OsInfoContributor osInfoContributor() { + return new OsInfoContributor(); + } + } }