question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ApiOperation support dynamically Generic

See original GitHub issue

#consult#

When developing management system, basically all are CRUD operations , e.g.

GET /foos
GET /foos/{id}
POST /foos
PUT /foos
DELETE /foos/{id}

so for reducing development work, I put common logic in BaseController and concrete Controller extend BaseController e.g.

public abstract class BaseController<V, F extends BaseForm> {
    @GetMapping("/{id}")
    protected ApiResult detail(@PathVariable String id) {
        V v = getService().getById(id);
        return ApiResult.success(v);
    }
}

but in this case I have to override detail to add @ApiOperation respectively

    @Override
    @ApiOperation(value = "Detail info",  response = BarVO.class)
    public ApiResult detail(@PathVariable String id) {
        return super.detail(id);
    }

Because ApiOperation annotation cannot support generic

@ApiOperation(value = "Detail info",  response = V.class)

even below manner also not support

@ApiOperation(value = "Detail info",  response = getClazz())

public abstract Class<V> getClazz();

So any idea could help ?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dilipkrishcommented, Jul 22, 2020

It might be easier if ApiResult would be generic and ApiResult<V> could make it very easy to inform the types without having you do so many things to get that to work, what do you think?

0reactions
stale[bot]commented, Nov 4, 2020

This issue has been automatically closed because it has not had recent activity. Please re-open a new issue if this is still an issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to let generic T type in java annotation? - Stack Overflow
Annotation values must be constants so the response values can not be generic because the actual is not known at compile time and...
Read more >
Springfox Reference Documentation - GitHub Pages
Allows globally configuration of default path-/request-/headerparameters which are common for every rest operation of the api, but aren`t needed ...
Read more >
Operations - OpenAPI - A progressive Node.js framework
With the ability to provide Raw Definitions, we can define Generic schema for Swagger UI. ... It can grow thanks to the support...
Read more >
Customizing your auto-generated Swagger Definitions in 1.5.x
The extension annotation allows you to add extension properties to a Swagger definition. It is currently supported within the @ApiOperation, @ ...
Read more >
Chapter 54. Extending JAX-RS Endpoints with OpenAPI Support
Copied! import io.swagger.annotations.*. where * = Api , ApiOperation , ApiParam , ApiResponse , ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found