swagger-api / swagger-api/swagger-codegen
[Python] Model gets generated with error when parent type is a list of another model
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
PythonClientCodegen.java doesnt instantiate the map "instantiationTypes" with key "array" and overridden toInstantiationType() has no code block for instace of "ArrayProperty".
Generated model looks like this:
class TopEventOutput(null<TopEventOutputInner>):
Here TopEventOutput is supposed to inherit list of TopEventOutputInner
@Override
public String toInstantiationType(Property p) {
if (p instanceof MapProperty) {
return instantiationTypes.get("map");
}
return null;
}
Swagger-codegen version
I have checked in 3.0.4. I guess this is common across all versions.
Swagger declaration file content or url
Steps to reproduce
Take any yaml file and make a model which inherits a list of another model.
Although I am not posting the yaml files and code to reproduce it. I have done an RCA and found out the code which causes this issue. i have mentioned the same in description.
Suggest a fix/enhancement
instantiationTypes.put("array", <Appropriate_type>);
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
Start in PythonClientCodegen.java at instantiationTypes and the overridden toInstantiationType(Property p), then reproduce with a model inheriting a list of another model. Compare the existing map handling with ArrayProperty handling. Done means the generated model uses the appropriate list parent type instead of null.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100