Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Springfox Swagger: Could not resolve pointer: /definitions/Instant

We have a SpringBoot project, and we're using Springfox Swagger for generating the API documentation.

There's a response class that contains:

private Collection<Instant> quartzScheduledDates;

When I run SwaggerUI, I receive this message:

Errors Resolver error at paths./subscriptions/{subscriptionIdStr}.get.responses.200.schema.properties.quartzScheduledDates.items.$ref Could not resolve reference because of: Could not resolve pointer: /definitions/Instant does not exist in document

We're using Springfox Swagger 2.9.2, SpringBoot 2.1.2-RELEASE.

I've also tried using the Docket trick in springfox, as seen in Springfox Documentation:

    docket.directModelSubstitute(Instant.class, java.util.Date.class);

With no success - same error message.

What am I doing wrong?

like image 695
Vlad Dinulescu Avatar asked Dec 24 '22 00:12

Vlad Dinulescu


1 Answers

I was able to replicate this issue. enter image description here

This can be resolved by defining new AlternateTypeRules while creating Docket for your SWAGGER.

Below is the snippet.

Docket docket= new Docket(DocumentationType.SWAGGER_2)
            .alternateTypeRules( AlternateTypeRules.newRule(
                    typeResolver.resolve(Collection.class, Instant.class),
                    typeResolver.resolve(Collection.class, Date.class), Ordered.HIGHEST_PRECEDENCE))
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.test"))
            .paths(PathSelectors.any())
            .build();
like image 198
Naveenkumar K Avatar answered Dec 31 '22 09:12

Naveenkumar K