This module allows you to define the routes for your Spring MVC application using an OpenAPI definition. It parses the OpenAPI documentation and uses the operationId to map to a controller operation. This provides a centralized way to manage your routes and makes it easier to refactor URLs.
First, you need to add the dependency to your project. If you're using Gradle, add the following to your build.gradle file:
repositories {
...
maven { url "https://jitpack.io" }
}
dependencies {
implementation 'com.github.avolpe:openapi-springmvc-router:2.2.3'
}If you're using Maven, add this to your pom.xml:
<dependencies>
<dependency>
<groupId>com.github.avolpe</groupId>
<artifactId>openapi-springmvc-router</artifactId>
<version>2.2.3</version>
</dependency>
</dependencies>To configure this module, import the config in your main class
@Configuration
@EnableOpenApiRouter(config="classpath:openapi.yml")
public class MyApplication {
}Here's an example of how you can use this module in your Spring MVC application:
paths:
/pets:
get:
operationId: myController.listPets
responses:
'200':
content:
application/json:
schema:
type: object@Controller
public class MyController {
public List<Pet> listPets() {
// Your code here
}
}The following properties can be used to configure the module:
openapi.router.routeFiles=classpath:openapi.yml
openapi.router.specRoute=/v3/api-docs