Skip to content

@ApiModelProperty#readOnly() ignored #2379

@rtomsick

Description

@rtomsick

Basically, whenever swagger determines (incorrectly) that a property is read-only due to a lack of setters on a model class (see #2169), there appears to be no way to mark it otherwise.

Example

@ApiModel("foo")
public class Foo
{
    private final int bar;

    @JsonCreator
    public Foo(@JsonProperty("bar") int bar)
    {
        this.bar = bar;
    }

    @JsonGetter("bar")
    @ApiModelProperty(value = "some description", readOnly = false)
    public int getBar(){return 0;}
}

This class is immutable, but Jackson handles serialization/de-serialization just fine.

Unfortunately, for the API spec we get:

"foo" : {
      "type" : "object",
      "properties" : {
        "bar" : {
          "type" : "integer",
          "format" : "int32",
          "description" : "some description",
          "readOnly" : true
        }
      }
    }

So basically, right now the situation is that if you use immutable model classes you're pretty much just screwed with no workaround.

Ideally #2169 will get fixed, but at the very least I would suggest at the very least that @ApiModelProperty#readOnly() be honored.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions