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.

Rendering of generics as response

See original GitHub issue

Hi! Using Springfox 2.0.0 Having this rest operation

 @RequestMapping(
            value = "/pop/{referenceId}",
            method = RequestMethod.DELETE,
            produces = ContentTypes.LIST
    )
    @ApiOperation(value = "Pop operation",
    notes = "Pops it")
    public DeferredResult<ResponseEntity<StateList>> pop_1_0(
            @PathVariable(value="referenceId") final String referenceId, @ApiIgnore final HttpEntity<String> request) {
        ...
    }}

Here is part of my config

/**
     * Swagger Spring MVC configuration
     */
    @Bean
    public Docket swaggerSpringMvcPlugin() {
        return new Docket(DocumentationType.SWAGGER_2)
                .genericModelSubstitutes(ResponseEntity.class, DeferredResult.class)
                .select()
                        .paths(paths()) // and by paths
                                .build()
                                .apiInfo(apiInfo());
    }

How would I configure springfox to render StateList as the response type correctly?

Now it renders this to ResponseEntity<StateList> in swagger-ui and nothing more is shown. Do I need to add add a alternaterule and if that is the case how would that rule be implemented.

Thanks in advance.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
cwstenbergcommented, May 13, 2015

Ok thanks!

Resolved it like this.


    @Autowired
    TypeResolver typeResolver;

/**
     * Swagger Spring MVC configuration
     */
    @Bean
    public Docket swaggerSpringMvcPlugin() {
        return new Docket(DocumentationType.SWAGGER_2)
                .alternateTypeRules(newRule(typeResolver.resolve(DeferredResult.class, typeResolver.resolve(ResponseEntity.class, WildcardType.class)),
                        typeResolver.resolve(WildcardType.class)))
                .select()
                        .paths(paths()) // and by paths
                                .build()
                                .apiInfo(apiInfo());
    }
0reactions
dilipkrishcommented, Feb 16, 2018

@emanuelbatista Without really testing I would have to say no.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generic View for Rendering JSON and HTML - Stack Overflow
Generic View for Rendering JSON and HTML ... In ListAPIView, I try to overload the class for rendering HTML and JSON as below....
Read more >
Renderers - Django REST framework
This renderer is used for rendering HTML multipart form data. It is not suitable as a response renderer, but is instead used for...
Read more >
Typescript generics for React developers - Developer way
Looking into why we need generics in Typescript, and how to use them to develop re-usable React components. And as a bonus: the...
Read more >
Example Using Generic (JSON) Resource Objects - Bloomreach
Resource is the primary object representation to solve all the complex integration problems in a generic way. So, the interface was designed to...
Read more >
OpenAPI generation couldn't infer response type for generic ...
When I inherit a resource from a generic base resource, and the response type is the generic type argument, then it will not...
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