Skip to content

Generics in lists will not handelt correctly #537

Closed
@GreenRover

Description

@GreenRover

Describe the bug

  • If you extends your controller and use generics. In Lists there the type will not be resolved corectly.

To Reproduce
Having 2 sping controllers like:

@Controller
@SuppressWarnings("rawtypes")
@AllArgsConstructor
public abstract class CrudController<T extends HavingPK> {
	private final JpaRepository<T, Integer> repository;

	@GetMapping(path = "{id}")
	@ResponseBody
	@Operation(description = "Get single object")
	public T get( //
			@Parameter(description = "The id to get.", required = true) @PathVariable("id") int id) {
		return repository.findById(id).get();
	}

	@GetMapping(path = "")
	@ResponseBody
	@Operation(description = "Receive a list of objects")
	public List<T> list() {
		return repository.findAll();
	}
}

@Tag(name = "design")
@Controller
@RequestMapping("/design")
public class DesignController extends CrudController<Design> {
	
	public DesignController(DesignRepository repository) {
		super(repository);
	}
	
}

You get as result:

{
   "/design/{id}":{
      "get":{
         "tags":[
            "design"
         ],
         "description":"Get single object",
         "operationId":"get_1",
         "parameters":[
            {
               "name":"id",
               "in":"path",
               "description":"The id to get.",
               "required":true,
               "schema":{
                  "type":"integer",
                  "format":"int32"
               }
            }
         ],
         "responses":{
            "200":{
               "description":"default response",
               "content":{
                  "*/*":{
                     "schema":{
                        "$ref":"#/components/schemas/Design"
                     }
                  }
               }
            }
         }
      }
   },
   "/design":{
      "get":{
         "tags":[
            "design"
         ],
         "description":"Receive a list of objects",
         "operationId":"list_1",
         "responses":{
            "200":{
               "description":"default response",
               "content":{
                  "*/*":{
                     "schema":{
                        "type":"array",
                        "items":{
                           "$ref":"#/components/schemas/HavingPK"
                        }
                     }
                  }
               }
            }
         }
      }
   }
}

Expected behavior
That the wrong:

                     "schema":{
                        "type":"array",
                        "items":{
                           "$ref":"#/components/schemas/HavingPK"
                        }
                     }

will be to the correct:

                     "schema":{
                        "type":"array",
                        "items":{
                           "$ref":"#/components/schemas/Design"
                        }
                     }

Here the full expected response

{
   "/design/{id}":{
      "get":{
         "tags":[
            "design"
         ],
         "description":"Get single object",
         "operationId":"get_1",
         "parameters":[
            {
               "name":"id",
               "in":"path",
               "description":"The id to get.",
               "required":true,
               "schema":{
                  "type":"integer",
                  "format":"int32"
               }
            }
         ],
         "responses":{
            "200":{
               "description":"default response",
               "content":{
                  "*/*":{
                     "schema":{
                        "$ref":"#/components/schemas/Design"
                     }
                  }
               }
            }
         }
      }
   },
   "/design":{
      "get":{
         "tags":[
            "design"
         ],
         "description":"Receive a list of objects",
         "operationId":"list_1",
         "responses":{
            "200":{
               "description":"default response",
               "content":{
                  "*/*":{
                     "schema":{
                        "type":"array",
                        "items":{
                           "$ref":"#/components/schemas/Design"
                        }
                     }
                  }
               }
            }
         }
      }
   }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions