I'm using the swagger-editor and the swagger-codegen tools to generate a client API. I have defined Person model in my yaml as follows:
Person:
properties:
firstname:
type: string
description: First Name
lastname:
type: string
pattern: "^zz"
description: Last Name
email:
type: string
description: Email of the person
additionalProperties: {"type":"object"}
When I generate the java code I get something like the following:
public class Person extends HashMap <String, Object> {
private String firstname = null;
private String lastname = null;
private String email = null;
//get and setters etc
}
When I use the the generated code to call my api all of the properties in my json are getting copied into the 'catch-all' map of the Person object; this is to say that something like {"lastname":"someLastname"} gets stored into the map instead of setting 'someLastname' on the private lastname variable. I was hoping that additionalProperties would only be used for items not specified in my model object - this is to say I was hoping if firstname, lastname etc were present in my json the parser would populate these as opposed to the map. I am manually able to get something like this to work by using @JsonAnySetter annotation and adding my own 'map,' however I was wondering if there is a way to get the swagger codegen to do something similar or if perhaps I am misunderstanding the expected behavior of the 'additionalProperties' attribute. I did look at some other threads and could not find anything directly, but feel free to simply point me to existing resources.
TIA