0

我正在尝试大摇大摆地生成一个客户。我有一个引用另一个 yaml 文件的 yaml 文件。所有这些文件都在同一个目录中。问题是部分引用已解决,但部分未解决。

例如,在我的 yaml 文件中有 2 个具有相同引用的对象:

$ref: TS29571_CommonData.yaml#/components/schemas/Snssai

在 TS29571_CommonData.yaml 中,它看起来像:

Snssai:
  type: object
  properties:
    sst:
      type: integer
      minimum: 0
      maximum: 255
    sd:
      type: string
      pattern: '^[A-Fa-f0-9]{6}$'
  required:
    - sst

在一个生成的文件中,它已被解析,import generated.model.Snssai;该对象的导入和使用正确。但在另一个文件中,它看起来像import generated.model.TS29571CommonDataYamlcomponentsschemasSnssai;红色。

这是我的 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.5.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>SwaggerMultipleYaml</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>SwaggerMultipleYaml</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.swagger.core.v3</groupId>
            <artifactId>swagger-annotations</artifactId>
            <version>2.1.4</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>6.0.10.Final</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
        </dependency>
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>4.9.1</version>
        </dependency>
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>logging-interceptor</artifactId>
            <version>4.9.1</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.1</version>
        </dependency>
        <dependency>
            <groupId>io.gsonfire</groupId>
            <artifactId>gson-fire</artifactId>
            <version>1.8.3</version>
        </dependency>

        <dependency>
            <groupId>org.threeten</groupId>
            <artifactId>threetenbp</artifactId>
            <version>0.7.2</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${project.parent.version}</version>
            </plugin>

            <plugin>
                <groupId>io.swagger.codegen.v3</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <version>3.0.25</version>
                <executions>
                    <execution>
                        <id>c</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.basedir}/src/main/resources/specs/TS29508_Nsmf_EventExposure.yaml</inputSpec>
                            <language>java</language>
                            <modelPackage>generated.model</modelPackage>
                            <apiPackage>generated.api</apiPackage>
                            <invokerPackage>generated.invoker</invokerPackage>
                            <configOptions>
                                <groupId>${project.groupId}</groupId>
                                <artifactId>${project.artifactId}</artifactId>
                                <artifactVersion>${project.version}</artifactVersion>
                                <library>okhttp-gson</library>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

可能是什么原因?

4

1 回答 1

0

有2个问题。

  1. 问题出在 okhttp 中。Swagger 使用 okhttp 生成客户端,并在 pom.xml 文件中添加了 okhttp3 的依赖项。所以在生成的文件中编译器无法解析import com.squareup.okhttp.OkHttpClient;,这给了我在构建过程中的错误。我变了

     <dependency>
         <groupId>com.squareup.okhttp3</groupId>
         <artifactId>okhttp</artifactId>
         <version>4.9.1</version>
     </dependency>
     <dependency>
         <groupId>com.squareup.okhttp3</groupId>
         <artifactId>logging-interceptor</artifactId>
         <version>4.9.1</version>
     </dependency>
    

    <dependency>
        <groupId>com.squareup.okhttp</groupId>
        <artifactId>okhttp</artifactId>
        <version>2.7.5</version>
    </dependency>
    <dependency>
        <groupId>com.squareup.okhttp</groupId>
        <artifactId>logging-interceptor</artifactId>
        <version>2.7.5</version>
    </dependency>
  1. 一些 yaml 文件引用了另一个文件,另一个文件引用了更多文件,依此类推。所以我加载了所有的 yaml 文件,甚至那些我不需要的文件。
于 2021-06-23T15:42:37.317 回答