Skip to content

Spring boot async Callable support #297

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

Closed
darc1 opened this issue Dec 24, 2019 · 0 comments
Closed

Spring boot async Callable support #297

darc1 opened this issue Dec 24, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@darc1
Copy link

darc1 commented Dec 24, 2019

Hi,

Springdoc fails to generate the response schema for spring boot controller methods with Callable. (spring boot async support using Callable docs)

For example the controller method:

    @RequestMapping(value = "/tasks", method = RequestMethod.GET)
    private Callable<ResponseEntity<Page<TaskDTO>>> getTasks(
                                                             @RequestParam(required = false) Predicate predicate,
                                                             Pageable pageable) {

        return () -> {

            Page<TaskDTO> fetchResult = fetchService.getTasks(pageable, predicate);
            return new ResponseEntity<>(fetchResult);

        };
    }

I was able to work around it by overriding the calculateSchemaFromParameterizedType method in the ResponseBuilder class, like this:

@ComponentScan(basePackages = {"org.springdoc.core"})
@Configuration
public class SpringDocConfig {

    private final OperationBuilder builder;

    public SpringDocConfig(OperationBuilder builder) {
        this.builder = builder;
    }

    @Bean
    public ResponseBuilder responseBuilder(){
        return new ResponseBuilderWithCallableHandling(builder);
    }


    public class ResponseBuilderWithCallableHandling extends ResponseBuilder{

        ResponseBuilderWithCallableHandling(OperationBuilder operationBuilder) {
            super(operationBuilder);
        }

        @Override
        protected Schema calculateSchemaFromParameterizedType(Components components, ParameterizedType parameterizedType, JsonView jsonView) {
            Schema<?> schemaN = null;

            if (Callable.class.getName().contentEquals(parameterizedType.getRawType().getTypeName())) {
                Type type = parameterizedType.getActualTypeArguments()[0];
                if(type instanceof ParameterizedType){
                    schemaN = super.calculateSchemaFromParameterizedType(components, (ParameterizedType)type, jsonView);
                }else {
                    schemaN = this.calculateSchemaParameterizedType(components, parameterizedType, jsonView);
                }
            }else {
                schemaN = super.calculateSchemaFromParameterizedType(components, parameterizedType, jsonView);
            }

            return schemaN;
        }
    }
}

It would be great if you could add support for Callable in future releases.

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