configuring openapi-processor-maven
Tags: openapi, maven, springboot, java
Published: 2020-07-27 20:41:03

# what is openapi-processor?

openapi-processor is a small framework to process OpenAPI yaml files. Currently, openapi-processor provides java code generation for Spring Boot and conversion to json.

It does support gradle and maven to run any openapi-processor as part of the build process.

See the [documentation][oap-docs] for more. There is also a [playground][oap-play] to preview the processors.

The **maven plugin** is the newest member of the openapi-processor family, and the following sections provide a short introduction into its configuration.


# introduction

I will just show the configuration of the maven plugin for integrating an OpenAPI yaml file. I don't describe the creation of a Spring Boot application.

Integrating it in a new Spring Boot starter project created by [Spring Initializr][spring-init] (maven & web-mvc) should work without issues.

To see a working demo project take a look at the [openapi-processor samples][oap-samples]. The available samples have a `pom.xml`, and a `build.gradle` file, so you can build them using maven or gradle.


## what to expect

Assuming a (simple) OpenAPI yaml file:

```yaml
openapi: 3.0.2
    info:
      title: ping api
      version: 1.0.0

    paths:
      /ping:
        get:
          tags:
            - ping
          summary: returns a single "pong" string.
          description: super simple endpoint.
          responses:
            '200':
              description: pong
              content:
                text/plain:
                  schema:
                    type: string
```

the [openapi-processor-maven plugin][oap-maven] will generate a java interface by running the [openapi-processor-spring][oap-spring] (in short oap-spring).

The interface generated for the simple api will look like this (the package name `io.openapiprocessor.simple` is configurable):


```java
package io.openapiprocessor.simple.api;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;

public interface PingApi {

    @GetMapping(path = "/ping", produces = {"text/plain"})
    String getPing();

}
```

You can now implement the interface to provide a working endpoint in your Spring Boot application.

The sample implements the interface with a hardcoded result like this:


```java
package io.openapiprocessor.simple;

import  io.openapiprocessor.simple.api.PingApi;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;

@RestController
public class PingController implements PingApi {

    @Override
    public String getPing () {
        return "pong";
    }

}
```

Now let's look at the necessary configuration to generate the interface from maven.

Continue reading [here][blog].

*Originally published at [https://hauner.github.io][blog] on July 18, 2020.*

[blog]: https://hauner.github.io/blog/2020/openapi-processor-maven
[oap-maven]: https://docs.openapiprocessor.io/maven
[oap-spring]: https://docs.openapiprocessor.io/spring
[oap-docs]: https://docs.openapiprocessor.io
[oap-play]: https://playground.openapiprocessor.io
[oap-samples]: https://docs.openapiprocessor.io/samples
[spring-init]: https://start.spring.io/