Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refrence files in SpringDoc OpenAPI3?

I have Springboot project where i want to documentate my API:

Here the exemple of the Webservice am working on:

    @ApiResponses(
        value = {
                @ApiResponse(responseCode = "200", content =  @Content(
                        mediaType = "*/*",
                        schema = @Schema(implementation = Object.class),
                        examples = {
                                @ExampleObject(name = "boo",
                                summary = "example of boo",
                                ref = "#/swagger/Planner/semi_planif_200_response.json")
                        }

                ))
        }
)
@PostMapping(value = "/startSemiPlanification", produces = "application/json")
private ResponseEntity<Object> startSemiPlanner( @RequestBody PlanificationDto planificationData,
                                                @RequestParam(name = "groupByUserCode", required = false) Optional<Boolean> groupByUserCode,
                                            @RequestParam(name = "range", defaultValue = "18") Integer range

My Problem is that Swagger cannot resolve this reference ref = "#/swagger/Planner/semi_planif_200_response.json" i have even tried with the absolute path and it didn't work: The Error Message from swagger

Here is files path:

File path

like image 627
bacemkratos Avatar asked Oct 16 '22 05:10

bacemkratos


1 Answers

References are not resolved in compile time instead after running the project the swagger engine will resolve the references as they were static resources within the server:

 $ref= resources/swagger/user.json 

if we are running our instance in localhost then the resource will be fetched from this url: localhost:8080/resources/swagger/user.json

Tip: make sure that spring resources handler is placing the targeted resources on the specified location!

like image 78
bacemkratos Avatar answered Oct 29 '22 03:10

bacemkratos