Merge branch '3.4.x'

Closes gh-45630
This commit is contained in:
Phillip Webb
2025-05-20 13:29:17 -07:00
2 changed files with 51 additions and 17 deletions

View File

@@ -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[]

View File

@@ -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();
}
}
}