Skip to content

Generating doc for entities with map attribute does not work #1634

Closed
@tonithomsson

Description

@tonithomsson

Generating doc for entities with map attribute does not work

  1. Create a SpringBoot project with jdk17 at
    https://start.spring.io/#!type=gradle-project&language=java&platformVersion=2.6.7&packaging=jar&jvmVersion=17&groupId=com.example&artifactId=demo&name=demo&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.demo&dependencies=data-rest,data-mongodb,web

  2. Add dependencies:
    implementation 'org.springdoc:springdoc-openapi-ui:1.6.8'
    implementation 'org.springdoc:springdoc-openapi-data-rest:1.6.8'

  3. Create a interface and model:
    @RepositoryRestResource
    public interface PersonRepository extends MongoRepository<Person, String> {
    }

public class Person {
@id
public String id;
public String name;

@DocumentReference
public Map<String, Person> friends = new HashMap<>();

}

  1. Start app and open http://localhost:8080/swagger-ui/index.html
    causes the following error:
    2022-04-26 22:31:23.236 ERROR 93367 --- [nio-8080-exec-6] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: Mismatched number of generics specified for private static class org.springdoc.data.rest.core.DataRestResponseService$MapModel] with root cause

java.lang.IllegalArgumentException: Mismatched number of generics specified for private static class org.springdoc.data.rest.core.DataRestResponseService$MapModel
at org.springframework.util.Assert.isTrue(Assert.java:139) ~[spring-core-5.3.19.jar:5.3.19]
at org.springframework.core.ResolvableType.forClassWithGenerics(ResolvableType.java:1088) ~[spring-core-5.3.19.jar:5.3.19]
at org.springframework.core.ResolvableType.forClassWithGenerics(ResolvableType.java:1074) ~[spring-core-5.3.19.jar:5.3.19]
at org.springdoc.data.rest.core.DataRestResponseService.resolveGenericType(DataRestResponseService.java:361) ~[springdoc-openapi-data-rest-1.6.8.jar:1.6.8]

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