Provide an option for a field to be hidden from the documentation while still being validated

Open
#747 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
java, spring

Research direction

Start from the fieldWithPath API and trace how ignored(), optional(), and type(JsonFieldType.STRING) affect validation and generated documentation. Confirm the expected behavior for a nullable hidden field: it remains type-validated while staying out of the documentation, then add coverage for that behavior.

Written by the indexing model from the issue text.

Description

status: waiting-for-votes type: enhancement

Hi,

Let's say we have a field description like this:

fieldWithPath("foo")
          .type(JsonFieldType.STRING)
          .description("some description")

If the returned value is "foo": null, then an exception is being thrown because null is not considered a STRING.
In such cases, we can mark the field as .optional(), signalling that a String may be provided, but can also be null.

The problem I noticed is that .ignored() also gets rid of this exception. IMHO that shouldn't happen, because the returned value (null) still violates the field description. In other words: the value is still optional, and hiding it from the docs does not change that fact.

In short, for a nullable field "foo", which should not be included in the docs, I'd expect this syntax:

fieldWithPath("foo")
          .ignored()
          .optional()
          .type(JsonFieldType.STRING)
          .description("some description")

Of course all of the above is a matter of how we interpret what it means for a description to be ignored.
If the above is expected behavior, maybe it would make sense to split "hiding from docs" and "ignoring type" into separate fields, so we can do this fieldWithPath("foo").hide().optional() (hide, but still validate) ?

Dominant language
Java
Stars
1.2k
Forks
731
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from spring-projects/spring-restdocs

All issues in spring-projects/spring-restdocs

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.