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 .springframework .restdocs .payload .PayloadDocumentation .beneathPath ;
3841import static org .springframework .restdocs .payload .PayloadDocumentation .fieldWithPath ;
@@ -51,23 +54,40 @@ class InfoEndpointDocumentationTests extends MockMvcEndpointDocumentationTests {
5154 void info () throws Exception {
5255 this .mockMvc .perform (get ("/actuator/info" ))
5356 .andExpect (status ().isOk ())
54- .andDo (MockMvcRestDocumentation .document ("info" ,
55- responseFields (beneathPath ("git" ),
56- fieldWithPath ("branch" ).description ("Name of the Git branch, if any." ),
57- fieldWithPath ("commit" ).description ("Details of the Git commit, if any." ),
58- fieldWithPath ("commit.time" ).description ("Timestamp of the commit, if any." )
59- .type (JsonFieldType .VARIES ),
60- fieldWithPath ("commit.id" ).description ("ID of the commit, if any." )),
61- responseFields (beneathPath ("build" ),
62- fieldWithPath ("artifact" ).description ("Artifact ID of the application, if any." ).optional (),
63- fieldWithPath ("group" ).description ("Group ID of the application, if any." ).optional (),
64- fieldWithPath ("name" ).description ("Name of the application, if any." )
65- .type (JsonFieldType .STRING )
66- .optional (),
67- fieldWithPath ("version" ).description ("Version of the application, if any." ).optional (),
68- fieldWithPath ("time" ).description ("Timestamp of when the application was built, if any." )
69- .type (JsonFieldType .VARIES )
70- .optional ())));
57+ .andDo (MockMvcRestDocumentation .document ("info" , gitInfo (), buildInfo (), osInfo ()));
58+ }
59+
60+ private ResponseFieldsSnippet gitInfo () {
61+ return responseFields (beneathPath ("git" ),
62+ fieldWithPath ("branch" ).description ("Name of the Git branch, if any." ),
63+ fieldWithPath ("commit" ).description ("Details of the Git commit, if any." ),
64+ fieldWithPath ("commit.time" ).description ("Timestamp of the commit, if any." ).type (JsonFieldType .VARIES ),
65+ fieldWithPath ("commit.id" ).description ("ID of the commit, if any." ));
66+ }
67+
68+ private ResponseFieldsSnippet buildInfo () {
69+ return responseFields (beneathPath ("build" ),
70+ fieldWithPath ("artifact" ).description ("Artifact ID of the application, if any." ).optional (),
71+ fieldWithPath ("group" ).description ("Group ID of the application, if any." ).optional (),
72+ fieldWithPath ("name" ).description ("Name of the application, if any." )
73+ .type (JsonFieldType .STRING )
74+ .optional (),
75+ fieldWithPath ("version" ).description ("Version of the application, if any." ).optional (),
76+ fieldWithPath ("time" ).description ("Timestamp of when the application was built, if any." )
77+ .type (JsonFieldType .VARIES )
78+ .optional ());
79+ }
80+
81+ private ResponseFieldsSnippet osInfo () {
82+ return responseFields (beneathPath ("os" ), osInfoField ("name" , "Name" ), osInfoField ("version" , "Version" ),
83+ osInfoField ("arch" , "Architecture" ));
84+ }
85+
86+ private FieldDescriptor osInfoField (String field , String desc ) {
87+ return fieldWithPath (field )
88+ .description ("Operating System " + desc + " (as obtained from the 'os." + field + "' system property)." )
89+ .type (JsonFieldType .STRING )
90+ .optional ();
7191 }
7292
7393 @ Configuration (proxyBeanMethods = false )
@@ -99,6 +119,11 @@ BuildInfoContributor buildInfoContributor() {
99119 return new BuildInfoContributor (buildProperties );
100120 }
101121
122+ @ Bean
123+ OsInfoContributor osInfoContributor () {
124+ return new OsInfoContributor ();
125+ }
126+
102127 }
103128
104129}
0 commit comments