2
votes

I have the following controller code:

    public abstract class BaseController<TClientModel extents BaseClientModel> {
       @Operation
       @GetMapping
       Page<TClientModel> get()
    }

    @Data
    public abstract class BaseClientModel {
       int id;
    }

    @RestController
    public class SpecificController extends BaseController<SpecificClientModel> {}

    @Data
    public class SpecificClientModel extends BaseClientModel {
        String name;
    }

Problem: When open-api markup is generated for SpecificController in Swagger, client model in the response is BaseClientModel, not SpecificClientModel and only has id field, and not id+name.

Actual:

{
  "id": 0,
}

Expected:

{
  "id": 0,
  "name": "string",
}

Given I have 40+ specific controllers, is there any way I can make springdoc open-api generate correct markup based on specific generic parameters?

1
It looks like It isn't supported yet. In the official repository there are related issues github.com/swagger-api/swagger-core/…JuanMoreno
Could you provide a reproducable example on github? Something isn't right in your example. What @Operation and @GetMapping annotations (from which package). extents instead of extends. What is Page object? I don't see it here. Page<TClientModel> get() it doesn't have a ";" in the end and neither body or abstract word. What is TClientModel? I don't see it here I guess it's SpecificClientModel? With example it would be way more easy to get some answerEugene Kortov

1 Answers

2
votes

The support is now part of v1.2.33 of springdoc-openapi. For example, if you are using spring-mvc, you can declare:

   <dependency>
      <groupId>org.springdoc</groupId>
      <artifactId>springdoc-openapi-ui</artifactId>
      <version>1.2.33</version>
   </dependency>