Swagger-ui: Swagger-ui does not hide readOnly nested object from example body

Created on 21 Jun 2019  路  6Comments  路  Source: swagger-api/swagger-ui

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]

Most helpful comment

Is there any way to remove readOnly property from the UI _Request body_ -> _Schema_ section?

Even though id has readOnly notation, it is still weird to have it in the request body schema.
image

All 6 comments

@Yaroslav007 , found any work around or is it still happening?

@anandvarkeyphilips I didn't find a workaround for it

Any solution?

Is there any way to remove readOnly property from the UI _Request body_ -> _Schema_ section?

Even though id has readOnly notation, it is still weird to have it in the request body schema.
image

This would be really nice to resolve, my current workaround is just to include the properties manually. But this creates REALLY redundant output.

Another hack I've considered is having a base object, then in an x-vendor schema creating read and write variations. All of this is a lot of extra work though when you've already defined your schema correctly.

Was this page helpful?
0 / 5 - 0 ratings