2727import org .springframework .boot .actuate .info .GitInfoContributor ;
2828import org .springframework .boot .actuate .info .InfoContributor ;
2929import org .springframework .boot .actuate .info .InfoEndpoint ;
30+ import org .springframework .boot .actuate .info .OsInfoContributor ;
3031import org .springframework .boot .info .BuildProperties ;
3132import org .springframework .boot .info .GitProperties ;
3233import org .springframework .context .annotation .Bean ;
3334import org .springframework .context .annotation .Configuration ;
3435import org .springframework .restdocs .mockmvc .MockMvcRestDocumentation ;
36+ import org .springframework .restdocs .payload .FieldDescriptor ;
3537import org .springframework .restdocs .payload .JsonFieldType ;
38+ import org .springframework .restdocs .payload .ResponseFieldsSnippet ;
3639
3740import static org .assertj .core .api .Assertions .assertThat ;
3841import static org .springframework .restdocs .payload .PayloadDocumentation .beneathPath ;
@@ -49,23 +52,40 @@ class InfoEndpointDocumentationTests extends MockMvcEndpointDocumentationTests {
4952 @ Test
5053 void info () {
5154 assertThat (this .mvc .get ().uri ("/actuator/info" )).hasStatusOk ()
52- .apply (MockMvcRestDocumentation .document ("info" ,
53- responseFields (beneathPath ("git" ),
54- fieldWithPath ("branch" ).description ("Name of the Git branch, if any." ),
55- fieldWithPath ("commit" ).description ("Details of the Git commit, if any." ),
56- fieldWithPath ("commit.time" ).description ("Timestamp of the commit, if any." )
57- .type (JsonFieldType .VARIES ),
58- fieldWithPath ("commit.id" ).description ("ID of the commit, if any." )),
59- responseFields (beneathPath ("build" ),
60- fieldWithPath ("artifact" ).description ("Artifact ID of the application, if any." ).optional (),
61- fieldWithPath ("group" ).description ("Group ID of the application, if any." ).optional (),
62- fieldWithPath ("name" ).description ("Name of the application, if any." )
63- .type (JsonFieldType .STRING )
64- .optional (),
65- fieldWithPath ("version" ).description ("Version of the application, if any." ).optional (),
66- fieldWithPath ("time" ).description ("Timestamp of when the application was built, if any." )
67- .type (JsonFieldType .VARIES )
68- .optional ())));
55+ .apply (MockMvcRestDocumentation .document ("info" , gitInfo (), buildInfo (), osInfo ()));
56+ }
57+
58+ private ResponseFieldsSnippet gitInfo () {
59+ return responseFields (beneathPath ("git" ),
60+ fieldWithPath ("branch" ).description ("Name of the Git branch, if any." ),
61+ fieldWithPath ("commit" ).description ("Details of the Git commit, if any." ),
62+ fieldWithPath ("commit.time" ).description ("Timestamp of the commit, if any." ).type (JsonFieldType .VARIES ),
63+ fieldWithPath ("commit.id" ).description ("ID of the commit, if any." ));
64+ }
65+
66+ private ResponseFieldsSnippet buildInfo () {
67+ return responseFields (beneathPath ("build" ),
68+ fieldWithPath ("artifact" ).description ("Artifact ID of the application, if any." ).optional (),
69+ fieldWithPath ("group" ).description ("Group ID of the application, if any." ).optional (),
70+ fieldWithPath ("name" ).description ("Name of the application, if any." )
71+ .type (JsonFieldType .STRING )
72+ .optional (),
73+ fieldWithPath ("version" ).description ("Version of the application, if any." ).optional (),
74+ fieldWithPath ("time" ).description ("Timestamp of when the application was built, if any." )
75+ .type (JsonFieldType .VARIES )
76+ .optional ());
77+ }
78+
79+ private ResponseFieldsSnippet osInfo () {
80+ return responseFields (beneathPath ("os" ), osInfoField ("name" , "Name" ), osInfoField ("version" , "Version" ),
81+ osInfoField ("arch" , "Architecture" ));
82+ }
83+
84+ private FieldDescriptor osInfoField (String field , String desc ) {
85+ return fieldWithPath (field )
86+ .description ("Operating System " + desc + " (as obtained from the 'os." + field + "' system property)." )
87+ .type (JsonFieldType .STRING )
88+ .optional ();
6989 }
7090
7191 @ Configuration (proxyBeanMethods = false )
@@ -97,6 +117,11 @@ BuildInfoContributor buildInfoContributor() {
97117 return new BuildInfoContributor (buildProperties );
98118 }
99119
120+ @ Bean
121+ OsInfoContributor osInfoContributor () {
122+ return new OsInfoContributor ();
123+ }
124+
100125 }
101126
102127}
0 commit comments