-
Notifications
You must be signed in to change notification settings - Fork 737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consistency with the subsection path. #937
Labels
Comments
See also #627. |
@ddaaac could you please share your complete tests? I'd like to be able to run them to see exactly what's happening with the field paths. |
wilkinsona
added
the
status: waiting-for-feedback
Feedback is required before progress can be made
label
Aug 13, 2024
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.restdocs.RestDocumentationExtension
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get
import org.springframework.restdocs.payload.JsonFieldType
import org.springframework.restdocs.payload.PayloadDocumentation.*
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController
@SpringBootTest
@AutoConfigureMockMvc
@AutoConfigureRestDocs
@ExtendWith(RestDocumentationExtension::class)
class ArrayTest {
@Autowired
private lateinit var mockMvc: MockMvc
@Test
fun `test response1`() {
mockMvc.perform(get("/response1"))
.andDo(
document(
"response1",
responseFields(
fieldWithPath("a.b[].c").type(JsonFieldType.STRING).description("root")
),
responseFields(
beneathPath("a.b[]").withSubsectionId("array"),
fieldWithPath("c").type(JsonFieldType.STRING).description("c")
)
// responseFields(
// beneathPath("a.b[]").withSubsectionId("nestedArray"),
// fieldWithPath("[].c").type(JsonFieldType.STRING).description("c")
// )
)
)
}
@Test
fun `test response2`() {
mockMvc.perform(get("/response2"))
.andExpect(status().isOk)
.andDo(
document(
"response2",
responseFields(
fieldWithPath("a[].b[].c").type(JsonFieldType.STRING).description("root")
),
// responseFields(
// beneathPath("a[].b[]").withSubsectionId("array"),
// fieldWithPath("c").type(JsonFieldType.STRING).description("c")
// )
responseFields(
beneathPath("a[].b[]").withSubsectionId("nestedArray"),
fieldWithPath("[].c").type(JsonFieldType.STRING).description("c")
)
)
)
}
}
@RestController
class MyController {
@GetMapping("/response1")
fun getResponse1(): Map<String, Any> {
return mapOf(
"a" to mapOf(
"b" to listOf(
mapOf(
"c" to "c1"
)
)
)
)
}
@GetMapping("/response2")
fun getResponse2(): Map<String, Any> {
return mapOf(
"a" to listOf(
mapOf(
"b" to listOf(
mapOf(
"c" to "c1"
)
)
)
)
)
}
} I use kotlin. The commented part is the part that fails. |
spring-projects-issues
added
status: feedback-provided
Feedback has been provided
and removed
status: waiting-for-feedback
Feedback is required before progress can be made
labels
Aug 19, 2024
Thanks. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Hi, I have two JSON string.
First one, A(B(List))
responseFields(fieldWithPath("a.b[].c"))
<- Test passed.responseFields(beneathPath("a.b[]"), listOf(fieldWithPath("c")))
<- Test passed.responseFields(beneathPath("a.b[]"), listOf(fieldWithPath("[].c")))
<- Test failed.Second one, A(List<B(List)>)
responseFields(fieldWithPath("a[].b[].c"))
<- Test passed.responseFields(beneathPath("a[].b[]"), listOf(fieldWithPath("c")))
<- Test failed.responseFields(beneathPath("a[].b[]"), listOf(fieldWithPath("[].c")))
<- Test passed.Is this intentional? Does the way to find the path change if there is an array in the root?
Additional information.
responseFields(fieldWithPath("a.b[].c[].d"))
<- Test passed.responseFields(beneathPath("a.b[].c[]"), listOf(fieldWithPath("d")))
<- Test failed.responseFields(beneathPath("a.b[].c[]"), listOf(fieldWithPath("[].d")))
<- Test Passed.responseFields(fieldWithPath("a.b[].c.d"))
<- Test passed.responseFields(beneathPath("a.b[].c"), listOf(fieldWithPath("d")))
<- Test Passed.responseFields(beneathPath("a.b[].c"), listOf(fieldWithPath("[].d")))
<- Test failed.I think an array of 1 depth behaves differently from an array of n depth(n >= 2).
The text was updated successfully, but these errors were encountered: