Skip to content

Regression in beneathPath in 2.0.3 #573

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

Closed
andrej-urvantsev opened this issue Jan 14, 2019 · 4 comments
Closed

Regression in beneathPath in 2.0.3 #573

andrej-urvantsev opened this issue Jan 14, 2019 · 4 comments
Labels
Milestone

Comments

@andrej-urvantsev
Copy link

andrej-urvantsev commented Jan 14, 2019

Seems like there was some change in how beneathPath works in 2.0.3

The following worked in 2.0.2:

                ...
                responseFields(
                    beneathPath("ongoing"),
                    fieldWithPath("[].id").description("Order ID").type(JsonFieldType.STRING),
                    fieldWithPath("[].parentId")
                        .optional()
                        .description("Optional parent order ID")
                        .type(JsonFieldType.STRING),
                    fieldWithPath("[].type")
                        .description("Order type: `CONCRETE` or `ABSTRACT`(parent order)")
                        .type(JsonFieldType.STRING),
                ...

where document was(test data no personal info)

{
  "ongoing" : [ {
    "id" : "993",
    "type" : "CONCRETE",
    "state" : "ORDER_NEW",
    "pickupTime" : "2019-01-14T14:03",
    "pickup" : "Hus 556 Östlunds Väg 774, Söderfred, MS 04555",
    "destination" : "Lgh. 845 Åslunds Väg 987, Karlfred, NV 26616",
    "names" : [ "Prof. Erik Nilsson", "Elisabet Nilsson" ],
    "phones" : [ "073-333-0667", "076-383-6377" ]
  } ],
  "finished" : [ {
    "id" : "956",
    "type" : "CONCRETE",
    "state" : "ORDER_COMPLETED",
    "pickupTime" : "2019-01-14T14:03",
    "pickup" : "Eriks Väg 783, Köfors, NV 34227",
    "destination" : "Aspvägen 88, Hatorp, SD 97209",
    "names" : [ "Erik Eriksson", "PhD. Göran Änglund" ],
    "phones" : [ "070-345-5394", "076-173-8762" ]
  } ]
}

But starting from 2.0.3 I get this error message:

org.springframework.restdocs.snippet.SnippetException: The following parts of the payload were not documented:
{
    "id" : "993",
    "type" : "CONCRETE",
    "state" : "ORDER_NEW",
    "pickupTime" : "2019-01-14T14:03",
    "pickup" : "Hus 556 Östlunds Väg 774, Söderfred, MS 04555",
    "destination" : "Lgh. 845 Åslunds Väg 987, Karlfred, NV 26616",
    "names" : [ "Prof. Erik Nilsson", "Elisabet Nilsson" ],
    "phones" : [ "073-333-0667", "076-383-6377" ]
  }
Fields with the following paths were not found in the payload: [[].id, [].type, [].state, [].pickupTime, [].pickup]
	at org.springframework.restdocs.payload.AbstractFieldsSnippet.validateFieldDocumentation(AbstractFieldsSnippet.java:228)
@wilkinsona
Copy link
Member

Thanks for the report. I suspect this is an unintended side-effect of the fix for #473. Does it work with beneathPath('ongoing.[]) and without the []. prefix on each field path?

@wilkinsona wilkinsona added the status: waiting-for-feedback Feedback is required before progress can be made label Jan 14, 2019
@andrej-urvantsev
Copy link
Author

Yes, workaround worked for that case but didn't work for more complicated one with optional field present in one subsection, but not in the another:

{
  "order": {
    "routeNodes": [
      {
        "address": "Lennarts Väg 3,Arfors,SE",
        "position": {
          "latitude": -4.196291170128276,
          "longitude": 117.72075222004281
        },
        "time": "2019-01-14T21:11"
      },
      {
        "address": "Karls Gata 842,Arborg,SE",
        "position": {
          "latitude": -42.12475432500546,
          "longitude": -22.791496608870403
        }
      }
    ]
  }
}
responseFields(
                    beneathPath("order.routeNodes.[]"),
                    fieldWithPath("address").description("Address").type(JsonFieldType.STRING),
                    subsectionWithPath("position")
                        .optional()
                        .description("Optional <<get-order-details-2-route-position,position>>")
                        .type(JsonFieldType.OBJECT),
                    fieldWithPath("time")
                        .optional()
                        .description(
                            "Optional time in format `yyyy-MM-dd'T'HH:mm`. Field will be always set on the first node")
                        .type(JsonFieldType.STRING)),

Then I get:

    org.springframework.restdocs.payload.PayloadHandlingException: order.routeNodes.[] identifies multiple sections of the payload and they do not have a common structure. The following uncommon paths were found: [order.routeNodes.[].time]
        at org.springframework.restdocs.payload.FieldPathPayloadSubsectionExtractor.extractSubsection(FieldPathPayloadSubsectionExtractor.java:94)
        at org.springframework.restdocs.payload.AbstractFieldsSnippet.createModel(AbstractFieldsSnippet.java:162)
        at org.springframework.restdocs.snippet.TemplatedSnippet.document(TemplatedSnippet.java:81)
        at org.springframework.restdocs.generate.RestDocumentationGenerator.handle(RestDocumentationGenerator.java:201)
        at org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.lambda$document$0(WebTestClientRestDocumentation.java:79)
        at org.springframework.test.web.reactive.server.DefaultWebTestClient$DefaultBodyContentSpec.lambda$consumeWith$3(DefaultWebTestClient.java:540)
        at org.springframework.test.web.reactive.server.ExchangeResult.assertWithDiagnostics(ExchangeResult.java:197)
        at org.springframework.test.web.reactive.server.DefaultWebTestClient$DefaultBodyContentSpec.consumeWith(DefaultWebTestClient.java:540)

@andrej-urvantsev
Copy link
Author

@wilkinsona do you want me provide anything else?

@wilkinsona
Copy link
Member

Thanks for the offer. I think I have everything from you that I need. I just need to find the time to look at what the necessary fix should be.

@wilkinsona wilkinsona added type: bug A bug and removed status: waiting-for-feedback Feedback is required before progress can be made labels Feb 11, 2019
@wilkinsona wilkinsona added this to the 2.0.4.RELEASE milestone Feb 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants