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

Example and schema of response is empty while using abstract generic #829

Closed
baxol opened this issue Aug 18, 2020 · 1 comment
Closed

Example and schema of response is empty while using abstract generic #829

baxol opened this issue Aug 18, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@baxol
Copy link

baxol commented Aug 18, 2020

Describe the bug
While defining the controller as an abstraction and using generic as a response, the example and schema in the swagger are empty.

To Reproduce
I have generic controller to provide crud methods as follows:

abstract class BaseCrudController<T, E : BaseEntityModel>(private val baseCrudService: BaseCrudService<T, E>) {
    ...
    @GetMapping("/{sid}")
    open fun read(@PathVariable sid: String): Mono<ResponseEntity<T>> =
            baseCrudService.read(sid)
                    .map { ResponseEntity.ok().body(it) }
                    .defaultIfEmpty(ResponseEntity.notFound().build())
    ...
}

and this is used in User controller implementation:

@RestController
@RequestMapping("api/import/user")
class UsrController(userService: UserService) :
        BaseCrudController<User, UserEntity>(userService)

User class contains the definition of swagger schema:

data class User(
        @get:Schema(
                title = "Speaking Id of User",
                pattern = Pattern.speakingId,
                example = "newUser"
        )
        val sid: String
)

Expected behavior
I should see the example and schema. In version 1.4.4 it still not works.

Additional context
I found if I define result differently then it works:
Mono<ResponseEntity<T>> -> Mono<T>
but in this case, I am losing the possibility to control response, I mean I have to control it differently (by exception handler).

Also if this controller is not defined as abstract the definition of endpoints are under a class with @RestController the
Mono<ResponseEntity<User>> works like a charm.

@baxol baxol changed the title Empty response example and schema using abstract generic Example and schema is empty while using abstract generic Aug 18, 2020
@baxol baxol changed the title Example and schema is empty while using abstract generic Example and schema of response is empty while using abstract generic Aug 18, 2020
@bnasslahsen
Copy link
Contributor

@baxol,

Not sure that there is any standard spring API that can achieve your goal: GenericTypeResolver.resolveType, doesn't seem to handle your case of nested generics.

I have added a fix to to handle this case. You can please validate this fix with the latest SNAPSHOT?
Here is the link to configure the snapshots:

I have you any proposal to improve the management of this case, please feel free to propose.

@bnasslahsen bnasslahsen added the enhancement New feature or request label Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants