Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api doc generation throws MappingException when Generic reference is used in entity class #2531

Closed
xuxiaojing2004 opened this issue Mar 15, 2024 · 2 comments

Comments

@xuxiaojing2004
Copy link

Describe the bug

When an entity has Generic references, such as class Privilege implements ElasticSearchEntity<String, AuditInfo>, in springdoc's SpringRepositoryRestResourceProvider's
entity = this.persistentEntities.getRequiredPersistentEntity(domainType);
It throws exception:
org.springframework.data.mapping.MappingException: Cannot get or create PersistentEntity for type com.apple.ist.idms.ramp.es.audit.IndexerInfo; PersistentEntities knows about 2 MappingContext instances and therefore cannot identify a single responsible one; Please configure the initialEntitySet through an entity scan using the base package in your configuration to pre initialize contexts
at org.springframework.data.mapping.context.PersistentEntities.lambda$getRequiredPersistentEntity$0(PersistentEntities.java:120)
at java.base/java.util.Optional.orElseThrow(Optional.java:403)
at org.springframework.data.mapping.context.PersistentEntities.getRequiredPersistentEntity(PersistentEntities.java:119)
at org.springdoc.core.utils.SpringDocDataRestUtils.customise(SpringDocDataRestUtils.java:126)
at org.springdoc.core.providers.SpringRepositoryRestResourceProvider.customize(SpringRepositoryRestResourceProvider.java:314)

The issue is caused by AuditInfo which is defined as a Generic for Privilege, in persistentEntities, AuditInfo has type TypeDiscoverer, the regular class has type ClassTypeInformation.

Because of this exception, the swagger api doc is not getting loaded when I try to access /v3/api-docs endpoint.

  • If you are reporting a bug, please help to speed up problem diagnosis by providing as
    much information as possible:
  • A clear and concise description of what the bug is: the title of an issue is not enough

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using? 3.2.1
  • What modules and versions of springdoc-openapi are you using? 2.4.1
  • What is the actual and the expected result using OpenAPI Description (yml or json)?
  • Provide with a sample code (HelloController) or Test that reproduces the problem

Expected behavior

  • A clear and concise description of what you expected to happen.
  • What is the expected result using OpenAPI Description (yml or json)?

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

@codespearhead
Copy link
Contributor

We need an MRE, like this one.

@xuxiaojing2004
Copy link
Author

this is caused by spring-data-rest, I get it resolved by setting sprngdoc.enable-data-rest: false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants