swagger-api / swagger-api/swagger-codegen
[ANDROID] Codegen - extended model contains duplicated properties from base model
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
com.android.volley.VolleyError: io.swagger.client.ApiException: class io.swagger.client.model.MyRequest declares multiple JSON fields named XXCustom01
If you have two definitions, where the second one extends the first one, the fields from the first definition are also declared in the model of the second definition. This will throw the above error message.
Also the properties of the first model should be declared protected instead of private.
Swagger-codegen version
Swagger Editor
Version 2.10.3
Swagger declaration file content or url
swagger: '2.0'
info:
version: 1.0.0
title: Test
description: ''
schemes: []
consumes: []
produces: []
tags:
- name: CommonService
description: ''
definitions:
AbstractEntity:
type: object
title: AbstractEntity
properties:
XXCustom01:
description: ''
type: string
XXCustom02:
description: ''
type: string
description: Base entity
MyRequest :
type: object
title: MyRequest
allOf:
- $ref: '#/definitions/AbstractEntity'
- properties:
Property01:
description: A special property.
type: string
description: ''
Command line used for generation
editor.swgger.io
Generated models
first model
@ApiModel(description = "Base entity")
public class AbstractEntity {
@SerializedName("XXCustom01")
private String xXCustom01 = null;
@SerializedName("XXCustom02")
private String xXCustom02 = null;
//...
}
second model
@ApiModel(description = "")
public class MyRequest extends AbstractEntity {
@SerializedName("XXCustom01")
private String xXCustom01 = null;
@SerializedName("XXCustom02")
private String xXCustom02 = null;
@SerializedName("Property01")
private String property01= null;
//...
}
Suggest a Fix
Fields defined in the first model should not be defined in the second model that extends the first one.
Declare the properties of the models protected instead of private.
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 by reproducing the Swagger 2.0 example with the Android generator and compare the generated AbstractEntity and MyRequest models. Trace the model-generation handling for allOf inheritance; done means inherited properties are not redeclared in MyRequest and base-model properties have protected visibility.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile-dev, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100