question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optional subsections are not aware that they are optional.

See original GitHub issue

Hello, I want to document the following payload.

{
  "list" : [ {
    "necessary" : "first",
    "optional" : {
      "field" : "b"
    }
  }, {
    "necessary" : "second"
  } ]
}

list[].optional field is literally an optional field. And here is my documentation code.

responseFields(
        subsectionWithPath("list[]").description("list"),
),
responseFields(
        beneathPath("list[]").withSubsectionId("sub1"),
        fieldWithPath("necessary").description("necessary"),
        subsectionWithPath("optional").description("optional").optional(),
),
responseFields(
        beneathPath("list[].optional").withSubsectionId("sub2"),
        fieldWithPath("field").description("field").optional(),
)

And I got an exception.

list[].optional identifies multiple sections of the payload and they do not have a common structure. The following non-optional uncommon paths were found: [list[].optional]

I’m guessing it’s because the list[].optional path doesn’t have a clue that it is optional (because the fact that list[].optional should be optional appears in the list[] path).

So, is there any feature like beneathPath("path").optional()?

I’m using spring-restdocs-mockmvc:2.0.6

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
wilkinsonacommented, Feb 9, 2022

You were relying on a bug, unfortunately.

A wildcard selecting multiple keys in a map is very similar to an array in that we’re then dealing with multiple parts of the payload that need to have the same structure for them to be documented accurately. Differing structures were being missed in some cases and throwing unhelpful errors in others. The changes for #715 mean that differing structures should now always be identified and the error message should be more helpful.

Unfortunately, I don’t think the behaviour you were relying on can be reinstated without regressing that fix.

0reactions
ddaaaccommented, Feb 9, 2022

Thank you 😃

I will fix my code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

sectioning - optional subsection numbering: 2.1 2.2A 2.2B 2.3 ...
For a document, I'm trying to refer the reader to either section 2.2A or 2.2B depending on what they are looking for. Is...
Read more >
Java 8 DateTimeFormatter parsing optional sections
The problem is that your pattern is considering the entire string as the year. You can use .appendValue(ChronoField.YEAR, 4) to limit it to ......
Read more >
Creating optional sections with the section macro
The section macro lets you create optional sections that you can enable/disable by clicking on a checkbox. The section can contain text, ...
Read more >
Template anatomy - AWS CloudFormation
You can refer to resources in the Resources and Outputs sections of the template. Outputs (optional). Describes the values that are returned whenever...
Read more >
G.600 - PHS Assignment Request Form
This form is optional. Use it only if you wish to communicate specific awarding component assignments or review preferences. There is no ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found