简体   繁体   中英

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)

good evening, This works for me

<plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>6.0.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.basedir}/src/main/resources/static/openapi.yaml</inputSpec>
                            <generatorName>spring</generatorName>
                            <library>spring-boot</library>
                            <modelNameSuffix>Dto</modelNameSuffix>
                            <generateApiTests>false</generateApiTests>
                            <generateModelTests>false</generateModelTests>
                            <configOptions>
                                <basePackage>se.disabledsecurity.locations</basePackage>
                                <modelPackage>se.disabledsecurity.locations.model</modelPackage>
                                <apiPackage>se.disabledsecurity.locations.api</apiPackage>
                                <configPackage>se.disabledsecurity.locations.config</configPackage>
                                <dateLibrary>java8</dateLibrary>
                                <delegatePattern>true</delegatePattern>
                                <interfaceOnly>true</interfaceOnly>
                                <additionalModelTypeAnnotations>
                                    @lombok.Builder
                                    @lombok.Getter
                                    @lombok.extern.jackson.Jacksonized
                                </additionalModelTypeAnnotations>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Found a good tutorial at https://blog.mimacom.com/using-the-openapi-generator-for-spring-boot/ this cfg puts all generated cde at target/generated-sources/openapi/src/main/java/se/disabledsecurity/locations Hope it helps, have a good evening

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM