Forum Discussion

jagan123's avatar
jagan123
Frequent Visitor
3 years ago

Restricting to extend hashmap using additionalProperties with allOf in swagger 2.0

Hi,

  We are trying generate a models in swagger 2.0 with additionalProperties and allOf using org.openapitools(openapi-generator-maven-plugin) version 5.2.1, models are generating but the below Profile model is not extending the Hashmap<String,Object>, it's only using allOf (i.e ProfileAttributes) and not using additionalProperties.

Please find below declared in swagger 2.0. 

Profile:
allOf:
- $ref: '#/definitions/ProfileAttributes'
- type: object
type: object
additionalProperties:
   type: object

 

ProfileAttributes:
type: object
required:
  - profileList
properties:
  profileList:
      $ref: "#/definitions/ProfileList"
   profileInfo: 
     $ref: "#/definitions/ProfileInfo"


The generated models like below :

 

@ApiModel(description = "Profile")
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2021-10-07T16:43:30.378+05:30[Asia/Calcutta]")
public class Profile {
@JsonProperty("profileList")
@Valid
private List<Profiles> profileList = new ArrayList<>();

@JsonProperty("profileInfo")
private ProfileInfo profileInfo;

@ApiModel(description = "ProfileAttributes")
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2021-10-07T16:43:30.378+05:30[Asia/Calcutta]")
public class ProfileAttributes {
@JsonProperty("profileList")
@Valid
private List<Profiles> profileList = new ArrayList<>();

@JsonProperty("profileInfo")
private ProfileInfo profileInfo;

 

Actually the below Profile model needs to be generated and extends HashMap<String, Object> along with the allOf reference model (ProfileAttributes) like below. But is not generating java models as expected but in the Swagger editor(https://editor.swagger.io/) it is properly showing,

@ApiModel(description = "Profile")
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2021-10-07T16:43:30.378+05:30[Asia/Calcutta]")
public class Profile extends HashMap<String, Object>{
@JsonProperty("profileList")
@Valid
private List<Profiles> profileList = new ArrayList<>();

@JsonProperty("profileInfo")
private ProfileInfo profileInfo;

 

Please find below are in the Swagger editor UI(https://editor.swagger.io/).

Profile{
    profileList* Profiles[...]
    ProfileInfo profileInfo{...}
    < * >: {...}
}

ProfileAttributes {
   profileList* Profiles[...]
   ProfileInfo profileInfo{...}
}

 

Please some one can help us here.

 

In pom.xml:

<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.2.1</version>

</plugin>

No RepliesBe the first to reply