joffrey-bion / livedoc

A not-so-annotation-based documentation generator for REST and websocket services
MIT License
4 stars 2 forks source link

Bad template for field of type Object #83

Closed ST-DDT closed 6 years ago

ST-DDT commented 6 years ago

In one of my DTOs I have a field that is of type Object because its some kind of generic filter param. However in the generated template it looks like it was a really complex data object (because it exposes the stuff inside Object#getClass()).

It would be nice if you could replace the template for Object with some kind of "any" or null.

public class SelectDTO {

    public List<Filter> filters;
    public int limit = 25;

}
public class Filter {

    @NotNull public String key;
    @NotNull public String op = "eq";
    public Object value;

}

In the generated JsonDoc the template is displayed like this:

[...]
   "template":{
      "filters":[
         {
            "key":null,
            "op":null,
            "value":{ // <-- Field of type Object
               "class":{
                  "annotatedInterfaces":[
                     {
                        "annotatedOwnerType":null,
                        "annotations":[
                           {}
                        ],
                        "declaredAnnotations":[
                           {}
                        ],
                        "type":{
                           "typeName":null
                        }
                     }
                  ],
                  "annotatedSuperclass":{
                     "annotatedOwnerType":null,
                     "annotations":[
                        {}
                     ],
                     "declaredAnnotations":[
                        {}
                     ],
                     "type":{
                        "typeName":null
                     }
                  },
                  // Plenty of more lines...
[...]

I'm using livedoc-springmvc-4.3.0.

joffrey-bion commented 6 years ago

I'm surprised because this case is already taken into account, and I have some tests using Object ensuring that the template is {}. I'll try to reproduce with your exact class shapes, maybe I missed something.

joffrey-bion commented 6 years ago

I have tested with the same classes as yours, and the template provider gives me the correct output:

{"filters":[{"key":"","op":"","value":{}}],"limit":0}

Do you confirm you are using livedoc 4.3.0? The default for strings has changed to "" since 4.2.0, so I'm surprised you're even getting nulls for the key and op fields.

joffrey-bion commented 6 years ago

Ok, I managed to reproduce using the sample webapp and your classes. It looks like the template provider in itself is correct, but somehow, when integrated in the app, the resulting template is the complicated JSON you sent. I'll look into it ASAP, but currently I'm at work, so please hold on ;)