本文整理汇总了Java中org.springframework.restdocs.payload.FieldDescriptor类的典型用法代码示例。如果您正苦于以下问题:Java FieldDescriptor类的具体用法?Java FieldDescriptor怎么用?Java FieldDescriptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FieldDescriptor类属于org.springframework.restdocs.payload包,在下文中一共展示了FieldDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: roleFieldsForResponse
import org.springframework.restdocs.payload.FieldDescriptor; //导入依赖的package包/类
/**
* Role fields used in responses.
* An array field equivalent can be provided.
*
* @param isJsonArray if the fields are used in a JsonArray
* @return FieldDescriptor
*/
private FieldDescriptor[] roleFieldsForResponse(boolean isJsonArray) {
return isJsonArray ?
new FieldDescriptor[]{
fieldWithPath("_embedded.roles[]").description("Roles list"),
fieldWithPath("_embedded.roles[].id").description("Role's id"),
fieldWithPath("_embedded.roles[].name").description("Role's name"),
fieldWithPath("_embedded.roles[].lastModifiedDate").type(Date.class).description("Role's date of last modification"),
fieldWithPath("_links").optional().ignored(),
fieldWithPath("page").optional().ignored()
} :
new FieldDescriptor[]{
fieldWithPath("id").description("Role's id"),
fieldWithPath("name").description("Role's name"),
fieldWithPath("lastModifiedDate").type(Date.class).description("Role's date of last modification"),
fieldWithPath("_links").optional().ignored(),
fieldWithPath("page").optional().ignored()
};
}
示例2: roleFieldsForRequest
import org.springframework.restdocs.payload.FieldDescriptor; //导入依赖的package包/类
/**
* Role fields used in requests.
*
* @return FieldDescriptor
*/
private FieldDescriptor[] roleFieldsForRequest(boolean isPatchRequest) {
return isPatchRequest ?
new FieldDescriptor[]{
fieldWithPath("name").optional().type(String.class).description("Role's name")
.attributes(key("mandatory").value(false)),
fieldWithPath("id").optional().ignored(),
fieldWithPath("lastModifiedDate").optional().ignored(),
fieldWithPath("_links").optional().ignored(),
fieldWithPath("page").optional().ignored()
} :
new FieldDescriptor[]{
fieldWithPath("name").type(String.class).description("Role's name")
.attributes(key("mandatory").value(true)),
fieldWithPath("id").optional().ignored(),
fieldWithPath("lastModifiedDate").optional().ignored(),
fieldWithPath("_links").optional().ignored(),
fieldWithPath("page").optional().ignored()
};
}
示例3: toFieldDescriptor
import org.springframework.restdocs.payload.FieldDescriptor; //导入依赖的package包/类
private static FieldDescriptor toFieldDescriptor(LinkDescriptor linkDescriptor) {
FieldDescriptor descriptor = fieldWithPath("_links." + linkDescriptor.getRel()) //change to subsectionWithPath on spring-rest-docs 1.2
.description(linkDescriptor.getDescription())
.type(JsonFieldType.OBJECT)
.attributes(linkDescriptor.getAttributes().entrySet().stream()
.map(e -> new Attribute(e.getKey(), e.getValue()))
.toArray(Attribute[]::new));
if (linkDescriptor.isOptional()) {
descriptor = descriptor.optional();
}
if (linkDescriptor.isIgnored()) {
descriptor = descriptor.ignored();
}
return descriptor;
}
示例4: should_extract_response_field_descriptors
import org.springframework.restdocs.payload.FieldDescriptor; //导入依赖的package包/类
@Test
public void should_extract_response_field_descriptors() {
// given
ResponseFieldsSnippet snippet = responseFields(
fieldWithPath("object.field").description("Is documented!"),
fieldWithPath("object.anotherField").description("Is documented, too!")
);
// when
List<FieldDescriptor> descriptors = extract(snippet);
then(descriptors).hasSize(2);
then(descriptors.stream().map(FieldDescriptor::getPath).collect(toList()))
.containsExactly("object.field", "object.anotherField");
then(descriptors.stream().map(AbstractDescriptor::getDescription).collect(toList()))
.containsExactly("Is documented!", "Is documented, too!");
}
示例5: post
import org.springframework.restdocs.payload.FieldDescriptor; //导入依赖的package包/类
@Test
public void post() throws Exception {
ConstrainedFields fields = new ConstrainedFields(FactTransactionJson.class);
List<FieldDescriptor> fieldDescriptors = Descriptors.getFactFieldDescriptors("facts[].",
fields);
fieldDescriptors.add(0, fields.withPath("facts").description(
"Non empty list with the facts to commit in this transaction"));
Snippet requestFieldSnippet = requestFields(//
fieldDescriptors);
FactTransactionJson factTransactionJson = objectMapper.readValue(this.getClass()
.getResourceAsStream("TransactionJson.json"), FactTransactionJson.class);
final Response response = target("/transactions").register(documentationConfiguration(
this.documentation))
.register(document("facts-transactions", preprocessRequest(
removeHeaders("User-Agent"), prettyPrint()), preprocessResponse(
prettyPrint()), requestFieldSnippet))
.request()
.post(Entity.entity(
factTransactionJson, MediaType.APPLICATION_JSON));
assertThat(response.getStatus(), is(204));
}
示例6: authorityFieldsForResponse
import org.springframework.restdocs.payload.FieldDescriptor; //导入依赖的package包/类
/**
* Authority fields used in responses.
* An array field equivalent can be provided.
*
* @param isJsonArray if the fields are used in a JsonArray
* @return FieldDescriptor
*/
private FieldDescriptor[] authorityFieldsForResponse(boolean isJsonArray) {
return isJsonArray ?
new FieldDescriptor[]{
fieldWithPath("_embedded.authorities[]").description("Authorities list"),
fieldWithPath("_embedded.authorities[].id").description("Authority's id"),
fieldWithPath("_embedded.authorities[].name").description("Authority's name"),
fieldWithPath("_embedded.authorities[].lastModifiedDate").type(Date.class).description("Authority's date of last modification"),
fieldWithPath("_links").optional().ignored(),
fieldWithPath("page").optional().ignored()
} :
new FieldDescriptor[]{
fieldWithPath("id").description("Authority's id"),
fieldWithPath("name").description("Authority's name"),
fieldWithPath("lastModifiedDate").type(Date.class).description("Authority's date of last modification"),
fieldWithPath("_links").optional().ignored(),
fieldWithPath("page").optional().ignored()
};
}
示例7: authorityFieldsForRequest
import org.springframework.restdocs.payload.FieldDescriptor; //导入依赖的package包/类
/**
* Authority fields used in requests.
*
* @return FieldDescriptor
*/
private FieldDescriptor[] authorityFieldsForRequest(boolean isPatchRequest) {
return isPatchRequest ?
new FieldDescriptor[]{
fieldWithPath("name").optional().type(String.class).description("Authority's name")
.attributes(key("mandatory").value(false)),
fieldWithPath("id").optional().ignored(),
fieldWithPath("lastModifiedDate").optional().ignored(),
fieldWithPath("_links").optional().ignored(),
fieldWithPath("page").optional().ignored()
} :
new FieldDescriptor[]{
fieldWithPath("name").type(String.class).description("Authority's name")
.attributes(key("mandatory").value(true)),
fieldWithPath("id").optional().ignored(),
fieldWithPath("lastModifiedDate").optional().ignored(),
fieldWithPath("_links").optional().ignored(),
fieldWithPath("page").optional().ignored()
};
}
示例8: groupFieldsForResponse
import org.springframework.restdocs.payload.FieldDescriptor; //导入依赖的package包/类
/**
* Group fields used in responses.
* An array field equivalent can be provided.
*
* @param isJsonArray if the fields are used in a JsonArray
* @return FieldDescriptor
*/
private FieldDescriptor[] groupFieldsForResponse(boolean isJsonArray) {
return isJsonArray ?
new FieldDescriptor[]{
fieldWithPath("_embedded.groups[]").description("Groups list"),
fieldWithPath("_embedded.groups[].id").description("Group's id"),
fieldWithPath("_embedded.groups[].name").description("Group's name"),
fieldWithPath("_embedded.groups[].lastModifiedDate").type(Date.class).description("Group's date of last modification"),
fieldWithPath("_links").optional().ignored(),
fieldWithPath("page").optional().ignored()
} :
new FieldDescriptor[]{
fieldWithPath("id").description("Group's id"),
fieldWithPath("name").description("Group's name"),
fieldWithPath("lastModifiedDate").type(Date.class).description("Group's date of last modification"),
fieldWithPath("_links").optional().ignored(),
fieldWithPath("page").optional().ignored()
};
}
示例9: groupFieldsForRequest
import org.springframework.restdocs.payload.FieldDescriptor; //导入依赖的package包/类
/**
* Group fields used in requests.
*
* @return FieldDescriptor
*/
private FieldDescriptor[] groupFieldsForRequest(boolean isPatchRequest) {
return isPatchRequest ?
new FieldDescriptor[]{
fieldWithPath("name").optional().type(String.class).description("Group's name")
.attributes(key("mandatory").value(false)),
fieldWithPath("id").optional().ignored(),
fieldWithPath("lastModifiedDate").optional().ignored(),
fieldWithPath("_links").optional().ignored(),
fieldWithPath("page").optional().ignored()
} :
new FieldDescriptor[]{
fieldWithPath("name").type(String.class).description("Group's name")
.attributes(key("mandatory").value(true)),
fieldWithPath("id").optional().ignored(),
fieldWithPath("lastModifiedDate").optional().ignored(),
fieldWithPath("_links").optional().ignored(),
fieldWithPath("page").optional().ignored()
};
}
示例10: dashboardBoxTypeFieldsForResponse
import org.springframework.restdocs.payload.FieldDescriptor; //导入依赖的package包/类
/**
* DashboardBoxType fields used in responses.
* An array field equivalent can be provided.
*
* @param isJsonArray if the fields are used in a JsonArray
* @return FieldDescriptor
*/
private FieldDescriptor[] dashboardBoxTypeFieldsForResponse(boolean isJsonArray) {
return isJsonArray ?
new FieldDescriptor[]{
fieldWithPath("_embedded.dashboard-box-types[]").description("DashboardBoxType list"),
fieldWithPath("_embedded.dashboard-box-types[].id").description("DashboardBoxType's id"),
fieldWithPath("_embedded.dashboard-box-types[].name").description("DashboardBoxType's name"),
fieldWithPath("_embedded.dashboard-box-types[].type").description("DashboardBoxType's type"),
fieldWithPath("_embedded.dashboard-box-types[].kind").description("DashboardBoxType's kind"),
fieldWithPath("_embedded.dashboard-box-types[].lastModifiedDate").type(Date.class)
.description("DashboardBoxType's date of last modification"),
fieldWithPath("_links").optional().ignored(),
fieldWithPath("page").optional().ignored()
} :
new FieldDescriptor[]{
fieldWithPath("id").description("DashboardBoxType's id"),
fieldWithPath("name").description("DashboardBoxType's name"),
fieldWithPath("type").description("DashboardBoxType's type"),
fieldWithPath("kind").description("DashboardBoxType's kind"),
fieldWithPath("lastModifiedDate").type(Date.class)
.description("DashboardBoxType's date of last modification"),
fieldWithPath("_links").optional().ignored(),
fieldWithPath("page").optional().ignored()
};
}
示例11: dashboardFieldsForResponse
import org.springframework.restdocs.payload.FieldDescriptor; //导入依赖的package包/类
/**
* Dashboard fields used in responses.
* An array field equivalent can be provided
*
* @param isJsonArray if the fields are used in a JsonArray
* @return FieldDescriptor
*/
private FieldDescriptor[] dashboardFieldsForResponse(boolean isJsonArray) {
return isJsonArray ?
new FieldDescriptor[]{
fieldWithPath("_embedded.dashboards[]").description("Dashboard list"),
fieldWithPath("_embedded.dashboards[].id").description("Dashboard's id"),
fieldWithPath("_embedded.dashboards[].name").description("Dashboard's name"),
fieldWithPath("_embedded.dashboards[].icon").description("Dashboard's icon"),
fieldWithPath("_embedded.dashboards[].lastModifiedDate").type(Date.class)
.description("AdminUser's date of last modification"),
fieldWithPath("_links").optional().ignored(),
fieldWithPath("page").optional().ignored()
} :
new FieldDescriptor[]{
fieldWithPath("id").description("Dashboard's id"),
fieldWithPath("name").description("Dashboard's name"),
fieldWithPath("icon").description("Dashboard's icon"),
fieldWithPath("lastModifiedDate").type(Date.class)
.description("Dashboard's date of last modification"),
fieldWithPath("_links").optional().ignored(),
fieldWithPath("page").optional().ignored()
};
}
示例12: testLoginAdmin
import org.springframework.restdocs.payload.FieldDescriptor; //导入依赖的package包/类
@Test
public void testLoginAdmin() throws Exception {
FieldDescriptor[] JWTAuthenticationRequestFields = new FieldDescriptor[]{
fieldWithPath("username").description("User's username")
.attributes(key("mandatory").value(true)),
fieldWithPath("password").description("User's password")
.attributes(key("mandatory").value(true))
};
FieldDescriptor[] JWTAuthenticationResponseFields = new FieldDescriptor[]{
fieldWithPath("token").description("Access token"),
fieldWithPath("refreshToken").description("Refresh token")
};
mockMvc.perform(post("/rest/auth/token")
.contentType(MediaType.APPLICATION_JSON)
.content(json(new JWTAuthenticationRequest("admin", "admin"))))
.andExpect(status().isOk())
.andDo(document("getTokens",
requestFields(JWTAuthenticationRequestFields),
responseFields(JWTAuthenticationResponseFields)));
}
示例13: testRefreshToken
import org.springframework.restdocs.payload.FieldDescriptor; //导入依赖的package包/类
@Test
public void testRefreshToken() throws Exception {
FieldDescriptor[] JWTRefreshTokenRequestFields = new FieldDescriptor[]{
fieldWithPath("refreshToken").description("Refresh token")
.attributes(key("mandatory").value(true))
};
FieldDescriptor[] JWTRefreshTokenResponseFields = new FieldDescriptor[]{
fieldWithPath("refreshedToken").description("New access token")
};
UserDetails adminDetails = createJWTUser();
String refreshToken = jwtTokenGenerationService.generateRefreshToken(adminDetails);
mockMvc.perform(put("/rest/auth/token")
.contentType(MediaType.APPLICATION_JSON)
.content(json(new JWTRefreshTokenRequest(refreshToken))))
.andExpect(status().isOk())
.andDo(document("refreshToken",
requestFields(JWTRefreshTokenRequestFields),
responseFields(JWTRefreshTokenResponseFields)));
}
示例14: testFilterLike
import org.springframework.restdocs.payload.FieldDescriptor; //导入依赖的package包/类
@Test
public void testFilterLike() throws Exception
{
MockHttpSession session = getSession( "F_DATAELEMENT_PUBLIC_ADD" );
DataElement de = createDataElement( 'A' );
manager.save( de );
List<FieldDescriptor> fieldDescriptors = new ArrayList<>();
fieldDescriptors.addAll( ResponseDocumentation.pager() );
fieldDescriptors.add( fieldWithPath( "dataElements" ).description( "Data elements" ) );
mvc.perform( get( "/dataElements?filter=name:like:DataElementA" )
.session( session )
.contentType( TestUtils.APPLICATION_JSON_UTF8 ) )
.andExpect( jsonPath( "$.pager.total", new GreaterThan<Integer>( 0 ) ) )
.andDo( documentPrettyPrint( "data-elements/filter",
responseFields( fieldDescriptors.toArray( new FieldDescriptor[fieldDescriptors.size()] ) ) ) );
}
示例15: testFieldsFilterOk
import org.springframework.restdocs.payload.FieldDescriptor; //导入依赖的package包/类
@Test
public void testFieldsFilterOk() throws Exception
{
MockHttpSession session = getSession( "F_DATAELEMENT_PUBLIC_ADD" );
DataElement de = createDataElement( 'A' );
manager.save( de );
List<FieldDescriptor> fieldDescriptors = new ArrayList<>();
fieldDescriptors.addAll( ResponseDocumentation.pager() );
fieldDescriptors.add( fieldWithPath( "dataElements" ).description( "Data elements" ) );
mvc.perform( get( "/dataElements?filter=name:eq:DataElementA&fields=id,name,valueType" )
.session( session )
.contentType( TestUtils.APPLICATION_JSON_UTF8 ) )
.andExpect( jsonPath( "$.dataElements[*].id" ).exists() )
.andExpect( jsonPath( "$.dataElements[*].name" ).exists() )
.andExpect( jsonPath( "$.dataElements[*].valueType" ).exists() )
.andExpect( jsonPath( "$.dataElements[*].categoryCombo" ).doesNotExist() )
.andDo( documentPrettyPrint( "data-elements/fields",
responseFields( fieldDescriptors.toArray( new FieldDescriptor[fieldDescriptors.size()] ) ) ) );
}