swagger-api / swagger-api/swagger-codegen
Generated compile error: discriminator field is set but not declared
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
This is the type definition in the json specification file:
{
"swagger": "2.0",
...,
"definitions":{
...,
"Message":{
"type":"object",
"discriminator":"msg_type",
"title":"Message"
},
...
}
}
This is the java class that gets generated:
public class Message {
public Message() {
this.msgType = this.getClass().getSimpleName();
}
...
The correct generated code would be:
public class Message {
String msgType;
public Message() {
this.msgType = this.getClass().getSimpleName();
}
...
Feels like it would be a simple fix, I'd do it myself but I don't know how. If anyone wants to point me in the right direction I can try and put in a PR.
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
Inspect the Java generator template responsible for discriminator fields and compare it with the generated Message class shown in the issue. Confirm that the discriminator assignment has a corresponding field declaration, then verify that the generated class compiles without the reported error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100