swagger-api / swagger-api/swagger-codegen

readOnly field shouldn't have a set property with Java CodeGen

Open
#2,189 9 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: General
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

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/#/

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.

Research direction

Start at the Java code generator entry point used by Swagger Editor and trace how the readOnly schema property is rendered. Verify that generated models omit a setter for readOnly fields while retaining the getter, then run the relevant generator tests if available.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.