Search code examples
javamavenopenapi-generatoropenapi-generator-maven-plugin

OpenAPI Generator does not generate api interfaces openapi-generator-maven-plugin


I'm trying to test out the openapi-generator by using a sample api. I was able to download the plugin but had to install a few additional dependencies that weren't included in the core dependency file. I'm able to generate the classes with the http client but the interfaces are not being generated. Therefore looking for help in understanding why I'm unable to generate the interfaces.

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>demo</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.openapitools</groupId>
            <artifactId>openapi-generator-maven-plugin</artifactId>
            <version>5.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>5.3.15</version>
        </dependency>

        <dependency>
            <groupId>org.openapitools</groupId>
            <artifactId>jackson-databind-nullable</artifactId>
            <version>0.2.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>5.1.0</version>
                <executions>
                    <execution>
                        <id>generate-client</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <phase>process-resources</phase>
                        <configuration>
                            <inputSpec>${project.basedir}/src/main/openapi/api.json</inputSpec>
                            <generatorName>java</generatorName>
                            <generateApiDocumentation>false</generateApiDocumentation>
                            <generateApiTests>false</generateApiTests>
                            <generateSupportingFiles>true</generateSupportingFiles>
                            <configOptions>
                                <sourceFolder>/</sourceFolder>
                                <dateLibrary>java8</dateLibrary>
                            </configOptions>
                            <library>resttemplate</library>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

api.json

{
  "swagger": "2.0",
  "info": {
    "title": "Test"
  },
  "host": "localhost:8080",
  "basePath": "/",
  "tags": [
    {
      "name": "test-controller"
    }
  ],
  "paths": {
    "/test": {
      "get": {
        "tags": [
          "test-controller"
        ],
        "operationId": "test",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  }
}

main folder is empty main folder (no generated interfaces)


Solution

  • It's under org. Not under src. You didn't specify the api package so it's generated under the default package.

    enter image description here