当前位置: 首页 > 知识库问答 >
问题:

Open Api 3生成器不为$ref引用的路径生成类

孔驰
2023-03-14

我有以下说明。yaml文件:

openapi: 3.0.2
info:
  title: Employee api
  version: 0.0.0
  description: Employee api specification
  contact:
    name: Lorem Ipsum
    email: lorem@ipsum.com

tags:
  - name: "Employee"
  - name: "EmployeeDisability"

paths:
  /employees:
    $ref: 'paths/employees.yaml'

和/路径/员工。亚马尔

/employees:
    get:
      summary: This is summary
      tags:
        - 'Employee'
      description: This is description
      operationId: getEmployees
      responses:
        "200":
          description: The request has succeeded - OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '../dtos/employee.yaml'

当我从 /paths/employees.yaml复制代码并粘贴到employee.yaml路径时,一切都会正确生成。我不认为这是文件路径的问题employees.yaml.有人有类似的问题吗?

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>employees-service-spec</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <java.version>11</java.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <swagger-annotations-version>1.5.22</swagger-annotations-version>
        <jersey-version>2.27</jersey-version>
        <jackson-version>2.10.2</jackson-version>
        <jodatime-version>2.7</jodatime-version>
        <maven-plugin-version>1.0.0</maven-plugin-version>
        <junit-version>4.8.1</junit-version>
        <springfox-version>2.9.2</springfox-version>
        <threetenbp-version>1.3.8</threetenbp-version>
        <datatype-threetenbp-version>2.6.4</datatype-threetenbp-version>
        <spring-boot-starter-test-version>2.1.1.RELEASE</spring-boot-starter-test-version>
        <spring-boot-starter-web-version>2.1.0.RELEASE</spring-boot-starter-web-version>
        <junit-version>4.12</junit-version>
        <migbase64-version>2.2</migbase64-version>
        <jackson-databind-nullable>0.2.1</jackson-databind-nullable>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-annotations</artifactId>
            <version>${swagger-annotations-version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-client</artifactId>
            <version>${jersey-version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-multipart</artifactId>
            <version>${jersey-version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-jackson</artifactId>
            <version>${jersey-version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.jaxrs</groupId>
            <artifactId>jackson-jaxrs-base</artifactId>
            <version>${jackson-version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${jackson-version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>${jackson-version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson-version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.jaxrs</groupId>
            <artifactId>jackson-jaxrs-json-provider</artifactId>
            <version>${jackson-version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-joda</artifactId>
            <version>${jackson-version}</version>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>${jodatime-version}</version>
        </dependency>
        <dependency>
            <groupId>com.brsanthu</groupId>
            <artifactId>migbase64</artifactId>
            <version>${migbase64-version}</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit-version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>${spring-boot-starter-test-version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>${spring-boot-starter-web-version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${springfox-version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${springfox-version}</version>
        </dependency>
        <dependency>
            <groupId>org.threeten</groupId>
            <artifactId>threetenbp</artifactId>
            <version>${threetenbp-version}</version>
        </dependency>
        <dependency>
            <groupId>com.github.joschi.jackson</groupId>
            <artifactId>jackson-datatype-threetenbp</artifactId>
            <version>${datatype-threetenbp-version}</version>
        </dependency>
        <dependency>
            <groupId>org.openapitools</groupId>
            <artifactId>jackson-databind-nullable</artifactId>
            <version>${jackson-databind-nullable}</version>
        </dependency>


        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
            <version>3.0.2</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>5.1.0</version>
                <executions>
                    <execution>
                        <id>generate-java</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <configOptions>
                                <apiPackage>com.example.demotest.api1</apiPackage>
                                <dateLibrary>java8</dateLibrary>
                                <examples>false</examples>
                                <implicitHeaders>false</implicitHeaders>
                                <interfaceOnly>false</interfaceOnly>
                                <library>spring-cloud</library>
                                <modelPackage>com.example.demotest.model1</modelPackage>
                                <returnSuccessCode>true</returnSuccessCode>
                                <swaggerDocketConfig>true</swaggerDocketConfig>
                                <unhandledException>true</unhandledException>
                                <useOptional>false</useOptional>
                                <useTags>true</useTags>
                            </configOptions>
                            <generatorName>spring</generatorName>
                            <typeMappings>
                                <typeMapping>OffsetDateTime=Instant</typeMapping>
                            </typeMappings>
                            <importMappings>Problem=org.zalando.problem.Problem,java.time.OffsetDateTime=java.time.Instant</importMappings>
                            <inputSpec>${project.basedir}/src/main/resources/employees-service-spec/employee/employee.yaml</inputSpec>
                            <modelNameSuffix>DTO</modelNameSuffix>
                            <skipValidateSpec>true</skipValidateSpec>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>
</project>

也许我还没有发现其他的限制?

共有1个答案

子车桐
2023-03-14

我在文件/路径/员工中找到了问题的原因。yaml不应存在路径,而且模型的路径不正确:

/employees: <-- remove this
get:
  summary: This is summary
  tags:
    - 'Employee'
  description: This is description
  operationId: getEmployees
  responses:
    "200":
      description: The request has succeeded - OK
      content:
        application/json:
          schema:
            type: array
            items:
              $ref: '../dtos/employee.yaml'  <-- here path sould be: '../dtos/employee.yaml#/Employee'

当员工模型为:

Employee:
  description: Employee
  type: object
  properties:
    number:
      description: The number of employee
      type: string
    unemployedStatus:
      description: The unemployed status of employee
      type: boolean
 类似资料:
  • 我的API定义如下: 我们使用生成代码。 生成的API参数:

  • 我正在获取javax.net.ssl.sslHandShakeException:Sun.Security.Validator.ValidatorException:PKIX路径构建失败:Sun.Security.Provider.CertPath.SunCertPathBuilderException:找不到请求目标的有效认证路径异常,如何解决?这是我的密钥库

  • 我有一个android应用程序,它在数组列表中绘制点的路径(名为“test”)。一种算法每次都会更新数组列表以使路径更短(它使用旅行推销员问题算法)。我目前面临的问题是以前的路径不清除,而是新的路径会覆盖以前的路径。

  • 我正在尝试生成完整的路径列表,而不是优化的。使用下面的示例可以更好地解释。 上面代码创建了一个带有边的图和和 我想要的只是从中提取所有路径。 我试过: 我想要的只是: 是否有任何来自的预先存在的方法可以使用?如果没有,有什么方法可以编写一个最优的方法来完成这项工作? 注意:我的问题仅限于给出的例子。再也不可能有拐角案件了。 注2:为简化起见,生成数据。在我的例子中,edges列表来自数据集。假设给

  • 我下载并反编译了minecraft插件的jar文件,并通过创建一个新的java项目Import将其添加到eclipse中 这导致了: 之后,我更改了一行代码,然后尝试导出它。 我不知道我该怎么做来解决这个问题。请帮忙。

  • 我一直在尝试调试这个错误,但没有成功。 本质上,我是通过我的应用程序联系外部应用程序的。连接建立良好,应用程序通过回调URL联系回我的应用程序,然后我需要向外部应用程序发送最终验证。最后一步由于SSLhandshajee异常而失败。 javax。网ssl。例外:太阳。安全验证器。ValidatorException:PKIX路径生成失败:sun。安全供应商。certpath。SunCertPath