Hi I made an Sprongbootapplication with OpenAPI. I Documented my API @Operation and so. If I call my "springdoc.api-docs.path" I get the correct answer but if i call my "springdoc.swagger-ui.path" I get only "No API definition provided." or the default petstore. I looked through many posts here and other sites, maybe someone can help me here.
My Setup
My dependency for swagger:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.3.0</version>
</dependency>
My application.properties:
springdoc.api-docs.path =/v3/doc/api-docs
springdoc.api-docs.enabled =true
springdoc.swagger-ui.csrf.enabled =false
springdoc.swagger-ui.with-credentials =false
springdoc.swagger-ui.filter =false
springdoc.swagger-ui.syntax-highlight.activated =true
springdoc.swagger-ui.enabled =true
springdoc.swagger-ui.disable-swagger-default-url=true
springdoc.swagger-ui.path =/v3/doc/swagger/swagger-ui.html
springdoc.packages-to-scan =de.my.rootPackage
My Controller:
@RestController
@RequestMapping("/root")
@Validated
public class MyController{
private MyService myService;
public MyController(final MyService myService) {
this.myService= myService;
}
@Operation(summary = "Saving data", description = "This endpoint saves a new data.")
@Parameter(content = @Content(schema = @Schema(implementation = DataDto.class), mediaType = "application/json"))
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "My description", content = @Content),
@ApiResponse(responseCode = "201", description = "My description", content = @Content),
@ApiResponse(responseCode = "400", description = "An invalid request was received.", content = @Content),
@ApiResponse(responseCode = "500", description = "An internal error occurred.", content = @Content),
})
@PostMapping(value = "/save", consumes = TYPE_JSON)
public ResponseEntity saveClinic(@NotNull @Valid @RequestBody final DataDto dataDto){
//some code
}
}
Behavior:
Calling localhost:8080/v3/doc/api-docs --> provides json with description I defined at @ Operation and so
Calling localhost:8080/v3/doc/swagger/swagger-ui.html --> redirects to http://localhost:8080/v3/doc/swagger/swagger-ui/index.html and only displaying "No API definition provided.". If i click "explore" I get "Unable to render this definition
The provided definition does not specify a valid version field.
Please indicate a valid Swagger or OpenAPI version field. Supported version fields are swagger: "2.0" and those that match openapi: 3.0.n (for example, openapi: 3.0.0).".
Has anyone any Ideas?
I have the same configuration for swagger in another projects and that works fine.
I tried:
- chaning the dependency version
- adding/playing with the properties
- mvn clean and rebuild
- invalidating ide caches
Edit Notes
Edit 1: 25.03.2024, 07:31
I already read the post from suggested by @Mohamedaminebenhassen. The app was newly set up with spring initializr and did not have the "springdoc-openapi-ui" before. I tried the "springdoc-openapi-starter-webmvc-ui" 2.4.0 (currently newest) aswell without success. I updated the dependency and run maven clean and then build it new. The outcome is still the same. I do not use springfox.