swagger-api / swagger-api/swagger-ui
Swagger-ui does not hide readOnly nested object from example body
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
I'm developing spring-boot app with swagger-ui and lombok. Currently I'm trying to hide nested object from request body, but it still shows in example json on swagger-ui page.
I have my class with annotations(simplified to only related stuff):
@Setter
@Getter
@ApiModel(description = "Character model")
public class Character {
@ApiModelProperty(readOnly = true)
private Long id;
@ApiModelProperty(readOnly = true)
private SearchAnnouncement searchAnnouncement;
}
When I access example model on swagger page "id" filed is properly hidden in example json, and visible in response model. But "searchAnnouncement" is not hidden in example json.
I tried:
using readOnly = true
using hidden = true
using accessMode = ApiModelProperty.AccessMode.READ_ONLY
using @Setter(AccessLevel.NONE), which prevents generation of setter for that field, as I read somewhere that something is checking if setter exist and sets readOnly based on that
different combinations of above
but in all cases example json looks like this (id hidden, and searchAnnouncement visible):
{
"searchAnnouncement": {
"id": 0,
},
}
So in short my question is:
Is it possible to hide from example json nested object?
Q&A (please complete the following information)
- OS: [e.g. windows]
- Browser: [Chrome ]
- Version: [74]
- Swagger-UI version: [2.9.2]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Swagger UI 2.9.2's example-body rendering for the supplied Character model and compare how top-level and nested readOnly properties are handled. Reproduce the shown schema with the listed annotations; done means searchAnnouncement is absent from the request example while remaining visible in the response model.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, javascript, openapi, spring-boot
- Domain
- api, documentation, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100