Skip to content

aVolpe/openapi-springmvc-router

 
 

Repository files navigation

OpenAPI Router for Spring MVC

Release

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.

Usage

Add the Dependency

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>

Configuration

To configure this module, import the config in your main class

@Configuration
@EnableOpenApiRouter(config="classpath:openapi.yml")
public class MyApplication {
}

Example Code

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
    }
}

Properties

The following properties can be used to configure the module:

openapi.router.routeFiles=classpath:openapi.yml
openapi.router.specRoute=/v3/api-docs

About

Adds routing based on an openAPI definition to a Spring MVC 6+ application.

Resources

License

Stars

Watchers

Forks

Languages

  • Java 85.1%
  • Gherkin 14.9%