'How to generate swagger models with empty collection in getters when the collection is null?
I have went through some stack overflow posts and online and can see that the swagger has changed the default from initializing empty collection to null when generating swagger models using maven swagger codegen plugin. So for example if I generate a collection using the maven plugin, the getter will look something like this:
public List<Phone> phone = null;
and its getters like:
/**
* Get phone
* @return phone
**/
@Schema(description = "")
public List<Phone> getPhone() {
return phone;
}
so is there any config option to generate the getters like below in maven swagger code gen plugin
/**
* Get phone
* @return phone
**/
@Schema(description = "")
public List<Phone> getPhone() {
if(phone ==null) {
return new ArrayList<Phone>();
}
return phone;
}
the reason I wanted to do like this is because I am migrating some legacy code and it is in soap and the classes generated using xsd initialize the list inside getters when the list is null. So I had to do it the same way so not to break any existing code.
Any hack or help is appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
