readOnly field shouldn't have a set property with Java CodeGen
If you have a field marked as readOnly in your schema, the Java code generator still renders a set Method. For example: "uri": { "description": "URI of the object", "type": "string", "readOnly": true }
And the generator gives me: @ApiModelProperty(value = "URI of the object") @JsonProperty("uri") public String getUri() { return uri; } public void setUri(String uri) { this.uri = uri; }
A read only field should not be settable.
This is using the Swagger Editor Version 2.9.8 online at http://editor.swagger.io/#/
@SolaceMike yes, agree that it should not have a setter if the property is readOnly.
May I know critical is this feature in your use case?
Not urgent. I just wanted to raise it for completeness. Do you happen to know if the other (non java) code gens do anything different than the java one does?
Other code gens do not have readOnly support and we just updated C# code gen to support it: https://github.com/swagger-api/swagger-codegen/pull/2199
Don't forget that a "readOnly" property should only indicate that the client can read this value from the server but don't have the right to send a new value. I agree it could be a good thing to remove the setters, but only for the "Client" codegens. The server *HAVE TO be able to set a value.
Spring Server Side Code Generation - BROKEN.
Looks like this change - https://github.com/swagger-api/swagger-codegen/pull/2206 seems to have broken backward compatibility and the setter methods in Java POJO's are not getting generated for spring server code generation.
I did already log a bug on this one - https://github.com/swagger-api/swagger-codegen/issues/3793 din't hear from anyone though.
Any inputs?
IMHO, readOnly has nothing to do with immutable model properties. According to the spec, it just means that the property must not be serialized in requests. See https://github.com/OAI/OpenAPI-Specification/issues/228#issuecomment-69207084
I am fine with both the client and server code generations do nothing w.r.t to readOnly and generate both getter/setter methods.
Currently it looks like we tried to differentiate it for the client models and the server models seems to be broken now with no setter methods getting generated for readOnly properties.
Could you please fix that server Setters are generated, otherwise read only property are unusable. Or is there a workaround?
Any update on this issue