Home Ask Login Register

Developers Planet

Your answer is one click away!

Rob McFeely February 2016

Swagger Custom Model

Im using swagger and spring boot to automatically generate API docs for my objects. However I'm dynamically adding fields to my json reponse using @jsonAnyGetter @jsonAnySetter. Such as

public class SomeResponse {

    //Standard part picked up by swagger
    public String field1;
    public String field2;

    //Dynamic Part not picked up by Swagger
    private HashMap dynamicFields = new HashMap();

    public final void putDynamicField(String key, Object value){
        dynamicFields.put(key, value);

    public final HashMap getDynamicFields(){
        return dynamicFields;



NB when the dynamic fields appear the magic of jackson make them appear at the same level at field1/2 :) HOwever Swagger doesnt pick them up cause they appear at run-time obvioulsy

Can anyone tell me how I can update the generated Swagger Model or Model Schema description to add custom fields description of sorts of my own naming? Something like:


   "dynamicField1": {}
   "dynamicFieldN": {}



fehguy February 2016

The @JsonAnyGetter and @JsonAnySetter are not supported by Swagger. You'll have to have concrete model definitions, or configure a custom model converter to add run-time fields to your models.

Post Status

Asked in February 2016
Viewed 1,710 times
Voted 14
Answered 1 times


Leave an answer

Quote of the day: live life