org.springframework.restdocs.payload.FieldDescriptor Java Examples
The following examples show how to use
org.springframework.restdocs.payload.FieldDescriptor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DataElementControllerDocumentation.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@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<>(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()] ) ) ) ); }
Example #2
Source File: GroupRestTest.java From SMSC with Apache License 2.0 | 6 votes |
/** * 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() }; }
Example #3
Source File: DashboardBoxTypeRestTest.java From SMSC with Apache License 2.0 | 6 votes |
/** * 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() }; }
Example #4
Source File: Snippets.java From genie with Apache License 2.0 | 6 votes |
private static FieldDescriptor[] getApplicationFieldDescriptors() { return ArrayUtils.addAll( getConfigFieldDescriptors(APPLICATION_CONSTRAINTS), PayloadDocumentation .fieldWithPath("type") .attributes(getConstraintsForField(APPLICATION_CONSTRAINTS, "type")) .description("The type of application this is (e.g. hadoop, presto, spark). Can be used to group.") .type(JsonFieldType.STRING) .optional(), PayloadDocumentation .fieldWithPath("status") .attributes(getConstraintsForField(APPLICATION_CONSTRAINTS, "status")) .description( "The status of the application. Options: " + Arrays.toString(ApplicationStatus.values()) ) .type(JsonFieldType.STRING), PayloadDocumentation .fieldWithPath("dependencies") .attributes(getConstraintsForField(APPLICATION_CONSTRAINTS, "dependencies")) .description("The dependencies for the application") .type(JsonFieldType.ARRAY) .optional() ); }
Example #5
Source File: FieldDocumentationGenerator.java From spring-auto-restdocs with Apache License 2.0 | 6 votes |
public FieldDescriptors generateDocumentation(Type baseType, TypeFactory typeFactory) throws JsonMappingException { JavaType javaBaseType = typeFactory.constructType(baseType); List<JavaType> types = resolveAllTypes(javaBaseType, typeFactory, typeMapping); FieldDescriptors result = new FieldDescriptors(); FieldDocumentationVisitorWrapper visitorWrapper = FieldDocumentationVisitorWrapper.create( javadocReader, constraintReader, deserializationConfig, new TypeRegistry(typeMapping, types), typeFactory, translationResolver, skipAccessor); for (JavaType type : types) { log.debug("(TOP) {}", type.getRawClass().getSimpleName()); if (RESOURCES_TYPES.contains(type.getRawClass().getCanonicalName())) { result.setNoContentMessageKey("body-as-embedded-resources"); continue; } writer.acceptJsonFormatVisitor(type, visitorWrapper); } for (FieldDescriptor descriptor : visitorWrapper.getFields()) { result.putIfAbsent(descriptor.getPath(), descriptor); } return result; }
Example #6
Source File: StandardTableSnippet.java From spring-auto-restdocs with Apache License 2.0 | 6 votes |
protected Map<String, Object> createModelForDescriptor(FieldDescriptor descriptor, TemplateFormatting templateFormatting, SnippetTranslationResolver translationResolver) { String path = descriptor.getPath(); String type = toString(descriptor.getType()); String methodComment = resolveComment(descriptor); String deprecatedComment = resolveDeprecated(descriptor, translationResolver); String completeComment = join("<p>", deprecatedComment, methodComment); String description = convertFromJavadoc(completeComment, templateFormatting); String optional = resolveOptional(descriptor, templateFormatting); List<String> constraints = resolveConstraints(descriptor); final String defaultValue = resolveDefaultValue(descriptor, translationResolver); description = joinAndFormat(description, constraints, defaultValue, templateFormatting); Map<String, Object> model = new HashMap<>(); model.put("path", path); model.put("type", type); model.put("optional", optional); model.put("description", description); return model; }
Example #7
Source File: UserControllerDocumentation.java From spring-tutorials with Apache License 2.0 | 6 votes |
/** * User fields used in requests and responses. * An array field equivalent can be proveded * @param isJsonArray if the fields are used in a JsonArray * @return */ private static FieldDescriptor[] userFields(boolean isJsonArray) { return isJsonArray ? new FieldDescriptor[]{ fieldWithPath("[]").description("Users list"), fieldWithPath("[].userId").description(USERS_ID_DESCRIPTION), fieldWithPath("[].firstName").description(USERS_FIRST_NAME_DESCRIPTION), fieldWithPath("[].lastName").description(USERS_LAST_NAME_DESCRIPTION), fieldWithPath("[].username").description(USERS_USERNAME_DESCRIPTION) } : new FieldDescriptor[]{ fieldWithPath("userId").description(USERS_ID_DESCRIPTION), fieldWithPath("firstName").description(USERS_FIRST_NAME_DESCRIPTION), fieldWithPath("lastName").description(USERS_LAST_NAME_DESCRIPTION), fieldWithPath("username").description(USERS_USERNAME_DESCRIPTION) }; }
Example #8
Source File: JWTAuthenticationTest.java From SMSC with Apache License 2.0 | 6 votes |
@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))); }
Example #9
Source File: JWTAuthenticationTest.java From SMSC with Apache License 2.0 | 6 votes |
@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))); }
Example #10
Source File: Snippets.java From genie with Apache License 2.0 | 6 votes |
private static FieldDescriptor[] getClusterFieldDescriptors() { return ArrayUtils.addAll( getConfigFieldDescriptors(CLUSTER_CONSTRAINTS), PayloadDocumentation .fieldWithPath("status") .attributes(getConstraintsForField(CLUSTER_CONSTRAINTS, "status")) .description( "The status of the cluster. Options: " + Arrays.toString(ClusterStatus.values()) ) .type(JsonFieldType.STRING), PayloadDocumentation .fieldWithPath("dependencies") .attributes(getConstraintsForField(CLUSTER_CONSTRAINTS, "dependencies")) .description("The dependencies for the cluster") .type(JsonFieldType.ARRAY) .optional() ); }
Example #11
Source File: ArticleCommentMvcTests.java From jakduk-api with MIT License | 6 votes |
private List<FieldDescriptor> getArticleCommentsDescriptor(FieldDescriptor... descriptors) { List<FieldDescriptor> fieldDescriptors = new ArrayList<>( Arrays.asList( fieldWithPath("comments").type(JsonFieldType.ARRAY).description("댓글 목록"), fieldWithPath("comments.[].id").type(JsonFieldType.STRING).description("댓글 ID"), subsectionWithPath("comments.[].article").type(JsonFieldType.OBJECT).description("연동 글"), subsectionWithPath("comments.[].writer").type(JsonFieldType.OBJECT).description("글쓴이"), fieldWithPath("comments.[].content").type(JsonFieldType.STRING).description("댓글 내용"), fieldWithPath("comments.[].numberOfLike").type(JsonFieldType.NUMBER).description("좋아요 수"), fieldWithPath("comments.[].numberOfDislike").type(JsonFieldType.NUMBER).description("싫어요 수"), fieldWithPath("comments.[].myFeeling").type(JsonFieldType.STRING).description("나의 감정 상태. 인증 쿠키가 있고, 감정 표현을 한 경우 포함 된다."), subsectionWithPath("comments.[].galleries").type(JsonFieldType.ARRAY).description("그림 목록"), subsectionWithPath("comments.[].logs").type(JsonFieldType.ARRAY).description("로그 기록 목록") ) ); CollectionUtils.mergeArrayIntoCollection(descriptors, fieldDescriptors); return fieldDescriptors; }
Example #12
Source File: AbstractWebApiTest.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testGetAll() throws Exception { Map<Class<? extends IdentifiableObject>, IdentifiableObject> defaultObjectMap = manager.getDefaults(); IdentifiableObject defaultTestObject = defaultObjectMap.get( testClass ); int valueToTest = defaultTestObject != null ? 5 : 4; manager.save( createTestObject( testClass, 'A' ) ); manager.save( createTestObject( testClass, 'B' ) ); manager.save( createTestObject( testClass, 'C' ) ); manager.save( createTestObject( testClass, 'D' ) ); MockHttpSession session = getSession( "ALL" ); List<FieldDescriptor> fieldDescriptors = new ArrayList<>(); fieldDescriptors.addAll( ResponseDocumentation.pager() ); fieldDescriptors.add( fieldWithPath( schema.getPlural() ).description( schema.getPlural() ) ); mvc.perform( get( schema.getRelativeApiEndpoint() ).session( session ).accept( TestUtils.APPLICATION_JSON_UTF8 ) ) .andExpect( status().isOk() ) .andExpect( content().contentTypeCompatibleWith( TestUtils.APPLICATION_JSON_UTF8 ) ) .andExpect( jsonPath( "$." + schema.getPlural() ).isArray() ) .andExpect( jsonPath( "$." + schema.getPlural() + ".length()" ).value( valueToTest ) ) .andDo( documentPrettyPrint( schema.getPlural() + "/all", responseFields( fieldDescriptors.toArray( new FieldDescriptor[fieldDescriptors.size()] ) ) ) ); }
Example #13
Source File: Snippets.java From genie with Apache License 2.0 | 6 votes |
private static FieldDescriptor[] getBaseFieldDescriptors(final ConstraintDescriptions constraintDescriptions) { return new FieldDescriptor[]{ PayloadDocumentation .fieldWithPath("id") .attributes(getConstraintsForField(constraintDescriptions, "id")) .description("The id. If not set the system will set one.") .type(JsonFieldType.STRING) .optional(), PayloadDocumentation .fieldWithPath("created") .attributes(getConstraintsForField(constraintDescriptions, "created")) .description("The UTC time of creation. Set by system. ISO8601 format including milliseconds.") .type(JsonFieldType.STRING) .optional(), PayloadDocumentation .fieldWithPath("updated") .attributes(getConstraintsForField(constraintDescriptions, "updated")) .description("The UTC time of last update. Set by system. ISO8601 format including milliseconds.") .type(JsonFieldType.STRING) .optional(), }; }
Example #14
Source File: AbstractWebApiTest.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testCreate() throws Exception { MockHttpSession session = getSession( "ALL" ); T object = createTestObject( testClass, 'A' ); Set<FieldDescriptor> fieldDescriptors = TestUtils.getFieldDescriptors( schema ); mvc.perform( post( schema.getRelativeApiEndpoint() ) .session( session ) .contentType( TestUtils.APPLICATION_JSON_UTF8 ) .content( TestUtils.convertObjectToJsonBytes( object ) ) ) .andExpect( status().is( createdStatus ) ) .andDo( documentPrettyPrint( schema.getPlural() + "/create", requestFields( fieldDescriptors.toArray( new FieldDescriptor[fieldDescriptors.size()] ) ) ) ); }
Example #15
Source File: AttributeControllerDocumentation.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void testCreate() throws Exception { InputStream input = new ClassPathResource( "attribute/SQLViewAttribute.json" ).getInputStream(); MockHttpSession session = getSession( "ALL" ); Set<FieldDescriptor> fieldDescriptors = TestUtils.getFieldDescriptors( schema ); mvc.perform( post( schema.getRelativeApiEndpoint() ) .session( session ) .contentType( TestUtils.APPLICATION_JSON_UTF8 ) .content( ByteStreams.toByteArray( input ) ) ) .andExpect( status().is( createdStatus ) ) .andDo( documentPrettyPrint( schema.getPlural() + "/create", requestFields( fieldDescriptors.toArray( new FieldDescriptor[fieldDescriptors.size()] ) ) ) ); }
Example #16
Source File: DescriptorExtractorTest.java From restdocs-raml with MIT License | 6 votes |
@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!"); }
Example #17
Source File: AttributeControllerDocumentation.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void testGetByIdOk() throws Exception { InputStream input = new ClassPathResource( "attribute/SQLViewAttribute.json" ).getInputStream(); MockHttpSession session = getSession( "ALL" ); MvcResult postResult = mvc.perform( post( schema.getRelativeApiEndpoint() ) .session( session ) .contentType( TestUtils.APPLICATION_JSON_UTF8 ) .content( ByteStreams.toByteArray( input ) ) ) .andExpect( status().is( createdStatus ) ).andReturn(); Set<FieldDescriptor> fieldDescriptors = TestUtils.getFieldDescriptors( schema ); String uid = TestUtils.getCreatedUid( postResult.getResponse().getContentAsString() ); mvc.perform( get( schema.getRelativeApiEndpoint() + "/{id}", uid ).session( session ).accept( MediaType.APPLICATION_JSON ) ) .andExpect( status().isOk() ) .andExpect( content().contentTypeCompatibleWith( MediaType.APPLICATION_JSON ) ) .andExpect( jsonPath( "$.name" ).value( "sqlViewAttribute") ) .andDo( documentPrettyPrint( schema.getPlural() + "/id", responseFields( fieldDescriptors.toArray( new FieldDescriptor[fieldDescriptors.size()] ) ) ) ); }
Example #18
Source File: ResponseDocumentation.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static List<FieldDescriptor> identifiableObject() { return Lists.newArrayList( fieldWithPath( "id" ).description( "Identifier" ), fieldWithPath( "name" ).description( "Name" ), fieldWithPath( "displayName" ).description( "Property" ), fieldWithPath( "code" ).description( "Code" ), fieldWithPath( "created" ).description( "Property" ), fieldWithPath( "lastUpdated" ).description( "Property" ), fieldWithPath( "href" ).description( "Property" ), fieldWithPath( "publicAccess" ).description( "Property" ), fieldWithPath( "externalAccess" ).description( "Property" ), fieldWithPath( "access" ).description( "Property" ), fieldWithPath( "userGroupAccesses" ).description( "Property" ), fieldWithPath( "attributeValues" ).description( "Property" ), fieldWithPath( "translations" ).description( "Property" ) ); }
Example #19
Source File: AuthorityRestTest.java From SMSC with Apache License 2.0 | 6 votes |
/** * 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() }; }
Example #20
Source File: RoleRestTest.java From SMSC with Apache License 2.0 | 6 votes |
/** * 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() }; }
Example #21
Source File: ResponseDocumentation.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static List<FieldDescriptor> nameableObject() { return Lists.newArrayList( fieldWithPath( "shortName" ).description( "Property" ), fieldWithPath( "displayShortName" ).description( "Property" ), fieldWithPath( "description" ).description( "Property" ), fieldWithPath( "displayDescription" ).description( "Property" ) ); }
Example #22
Source File: ContactRestTest.java From SMSC with Apache License 2.0 | 5 votes |
/** * Contact 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[] contactFieldsForResponse(boolean isJsonArray) { return isJsonArray ? new FieldDescriptor[]{ fieldWithPath("_embedded.customer-contacts[]").description("CustomerContact list"), fieldWithPath("_embedded.customer-contacts[].id").description("CustomerContact's id"), fieldWithPath("_embedded.customer-contacts[].firstname").description("CustomerContact's firstname"), fieldWithPath("_embedded.customer-contacts[].surname").description("CustomerContact's surname"), fieldWithPath("_embedded.customer-contacts[].phone").description("CustomerContact's phone"), fieldWithPath("_embedded.customer-contacts[].mobilePhone").description("CustomerContact's mobilePhone"), fieldWithPath("_embedded.customer-contacts[].fax").description("CustomerContact's fax"), fieldWithPath("_embedded.customer-contacts[].emailAddress").description("CustomerContact's emailAddress"), fieldWithPath("_embedded.customer-contacts[].type").type(Type.class).description("CustomerContact's type"), fieldWithPath("_embedded.customer-contacts[].salutation").type(Salutation.class) .description("CustomerContact's salutation"), fieldWithPath("_embedded.customer-contacts[].lastModifiedDate").type(Date.class) .description("CustomerContact's date of last modification"), fieldWithPath("_links").optional().ignored(), fieldWithPath("page").optional().ignored() } : new FieldDescriptor[]{ fieldWithPath("id").description("CustomerContact's id"), fieldWithPath("firstname").description("CustomerContact's firstname"), fieldWithPath("surname").description("CustomerContact's surname"), fieldWithPath("phone").description("CustomerContact's phone"), fieldWithPath("mobilePhone").description("CustomerContact's mobilePhone"), fieldWithPath("fax").description("CustomerContact's fax"), fieldWithPath("emailAddress").description("CustomerContact's emailAddress"), fieldWithPath("type").type(Type.class).description("CustomerContact's type"), fieldWithPath("salutation").type(Salutation.class).description("CustomerContact's salutation"), fieldWithPath("lastModifiedDate").type(Date.class) .description("CustomerContact's date of last modification"), fieldWithPath("_links").optional().ignored(), fieldWithPath("page").optional().ignored() }; }
Example #23
Source File: FieldDocumentationGeneratorTest.java From spring-auto-restdocs with Apache License 2.0 | 5 votes |
private List<ExtendedFieldDescriptor> cast(Collection<FieldDescriptor> original) { List<ExtendedFieldDescriptor> casted = new ArrayList<>(original.size()); for (FieldDescriptor d : original) { casted.add(new ExtendedFieldDescriptor(d)); } return casted; }
Example #24
Source File: AttributeControllerDocumentation.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void testGetAll() throws Exception { InputStream input = new ClassPathResource( "attribute/SQLViewAttribute.json" ).getInputStream(); MockHttpSession session = getSession( "ALL" ); mvc.perform( post( schema.getRelativeApiEndpoint() ) .session( session ) .contentType( TestUtils.APPLICATION_JSON_UTF8 ) .content( ByteStreams.toByteArray( input ) ) ) .andExpect( status().is( createdStatus ) ).andReturn(); List<FieldDescriptor> fieldDescriptors = new ArrayList<>(); fieldDescriptors.addAll( ResponseDocumentation.pager() ); fieldDescriptors.add( fieldWithPath( schema.getPlural() ).description( schema.getPlural() ) ); mvc.perform( get( schema.getRelativeApiEndpoint() ).session( session ).accept( TestUtils.APPLICATION_JSON_UTF8 ) ) .andExpect( status().isOk() ) .andExpect( content().contentTypeCompatibleWith( TestUtils.APPLICATION_JSON_UTF8 ) ) .andExpect( jsonPath( "$." + schema.getPlural() ).isArray() ) .andExpect( jsonPath( "$." + schema.getPlural() + ".length()" ).value( 1 ) ) .andDo( documentPrettyPrint( schema.getPlural() + "/all", responseFields( fieldDescriptors.toArray( new FieldDescriptor[fieldDescriptors.size()] ) ) ) ); }
Example #25
Source File: CategoryControllerDocumentation.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test @Override public void testCreate() throws Exception { MockHttpSession session = getSession( "F_CATEGORY_PUBLIC_ADD" ); CategoryOption categoryOptionA = createCategoryOption( 'A' ); CategoryOption categoryOptionB = createCategoryOption( 'B' ); CategoryOption categoryOptionC = createCategoryOption( 'C' ); Category cat = createCategory( 'A', categoryOptionA, categoryOptionB, categoryOptionC ); Schema schema = schemaService.getSchema( Category.class ); Set<FieldDescriptor> fieldDescriptors = TestUtils.getFieldDescriptors( schema ); mvc.perform( post( "/" + ENDPOINT ) .session( session ) .contentType( TestUtils.APPLICATION_JSON_UTF8 ) .content( TestUtils.convertObjectToJsonBytes( cat ) ) ) .andExpect( status().is( createdStatus ) ) .andDo( documentPrettyPrint( "categories/create", requestFields( fieldDescriptors.toArray( new FieldDescriptor[fieldDescriptors.size()] ) ) ) ); cat = manager.getByName( Category.class, "CategoryA" ); assertNotNull( cat ); }
Example #26
Source File: FieldDescriptorsTest.java From restdocs-raml with MIT License | 5 votes |
@Test public void should_combine_descriptors_with_prefix() { fieldDescriptors = givenFieldDescriptors(); then(fieldDescriptors.andWithPrefix("d.", fieldWithPath("c")).getFieldDescriptors()) .extracting(FieldDescriptor::getPath).contains("a", "b", "d.c"); }
Example #27
Source File: ArticleCommentMvcTests.java From jakduk-api with MIT License | 5 votes |
private FieldDescriptor[] getWriteArticleCommentFormDescriptor() { ConstraintDescriptions userConstraints = new ConstraintDescriptions(WriteArticleComment.class); return new FieldDescriptor[] { fieldWithPath("content").type(JsonFieldType.STRING).description("댓글 내용. " + userConstraints.descriptionsForProperty("content")), subsectionWithPath("galleries").type(JsonFieldType.ARRAY).description("(optional) 그림 목록") }; }
Example #28
Source File: Snippets.java From genie with Apache License 2.0 | 5 votes |
private static FieldDescriptor[] getSetupFieldDescriptors(final ConstraintDescriptions constraintDescriptions) { return ArrayUtils.addAll( getCommonFieldDescriptors(constraintDescriptions), PayloadDocumentation .fieldWithPath("setupFile") .attributes(getConstraintsForField(constraintDescriptions, "setupFile")) .description("A location for any setup that needs to be done when installing") .type(JsonFieldType.STRING) .optional() ); }
Example #29
Source File: DescriptorExtractorTest.java From restdocs-raml with MIT License | 5 votes |
@Test public void should_extract_request_field_descriptors() { // given RequestFieldsSnippet snippet = requestFields( fieldWithPath("object.field").description("Is documented!") ); // when List<FieldDescriptor> descriptors = extract(snippet); then(descriptors).hasSize(1); then(descriptors.get(0).getPath()).isEqualTo("object.field"); then(descriptors.get(0).getDescription()).isEqualTo("Is documented!"); }
Example #30
Source File: CommonRestDocumentation.java From taskana with Apache License 2.0 | 5 votes |
@BeforeEach void setUp() { selfLinkFieldDescriptionsMap.put("_links", "Links section"); selfLinkFieldDescriptionsMap.put("_links.self", "Link to self"); selfLinkFieldDescriptionsMap.put("_links.self.href", "Link to instance"); selfLinkFieldDescriptors = new FieldDescriptor[] { fieldWithPath("classificationId").ignored(), fieldWithPath("key").ignored(), fieldWithPath("parentId").ignored(), fieldWithPath("parentKey").ignored(), fieldWithPath("category").ignored(), fieldWithPath("type").ignored(), fieldWithPath("domain").ignored(), fieldWithPath("isValidInDomain").ignored(), fieldWithPath("created").ignored(), fieldWithPath("modified").ignored(), fieldWithPath("name").ignored(), fieldWithPath("description").ignored(), fieldWithPath("priority").ignored(), fieldWithPath("serviceLevel").ignored(), fieldWithPath("applicationEntryPoint").ignored(), fieldWithPath("custom1").ignored(), fieldWithPath("custom2").ignored(), fieldWithPath("custom3").ignored(), fieldWithPath("custom4").ignored(), fieldWithPath("custom5").ignored(), fieldWithPath("custom6").ignored(), fieldWithPath("custom7").ignored(), fieldWithPath("custom8").ignored(), fieldWithPath("_links").description(selfLinkFieldDescriptionsMap.get("_links")), fieldWithPath("_links.self").description(selfLinkFieldDescriptionsMap.get("_links.self")), fieldWithPath("_links.self.href") .description(selfLinkFieldDescriptionsMap.get("_links.self.href")) }; }