swagger-api / swagger-api/swagger-codegen
[Java] error: <identifier> expected if model has property with name 'on'
Open
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Invalid code is generated by swagger swaggerCodegen("io.swagger.codegen.v3:swagger-codegen-cli:3.0.35")
Swagger-codegen version
3.0.35
Swagger declaration file content or url
Having a schema
components:
schemas:
Test:
properties:
on:
type: string
enum:
- score
- updated_at
This java code is generated:
public class Test {
/**
* Gets or Sets true
*/
public enum TrueEnum {
SCORE("score"),
UPDATED_AT("updated_at");
private String value;
TrueEnum(String value) {
this.value = value;
}
@JsonValue
public String getValue() {
return value;
}
@Override
public String toString() {
return String.valueOf(value);
}
@JsonCreator
public static TrueEnum fromValue(String input) {
for (TrueEnum b : TrueEnum.values()) {
if (b.value.equals(input)) {
return b;
}
}
return null;
}
} @JsonProperty("true")
private TrueEnum true = null;
public Test true(TrueEnum true) {
this.true = true;
return this;
}
/**
* Get true
* @return true
**/
@Schema(description = "")
public TrueEnum getTrue() {
return true;
}
public void setTrue(TrueEnum true) {
this.true = true;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Test test = (Test) o;
return Objects.equals(this.true, test.true);
}
@Override
public int hashCode() {
return Objects.hash(true);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Test {\n");
sb.append(" true: ").append(toIndentedString(true)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}
Renaming property on to something else solvess issue
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
Reproduce the issue with swagger-codegen 3.0.35 using the provided OpenAPI schema and inspect the generated Java for the on property. Trace the Java model-generation entry point and identifier handling; done means the schema produces valid Java while preserving the on property name, with a regression test covering this case.
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
- 35/100