首页 > 解决方案 > Open API -> 如何在请求或响应正文 YAML 规范中引用类路径/jar 的 Java 对象的外部属性名称/类型

问题描述

我的要求是使用类路径 java 对象中包含的类的属性名称和类型。

基本上, $ref 将允许我们使用包含在类路径中的类,如下所示

1) **YML File** 
paths:
  /users/{id}:
    parameters:
    - name: id
      in: path
      required: true
      description: the user identifier, as userId 
      schema:
        type: string
    get:
      responses:
        '200':
          description: the user being returned
          content:
            application/json:
              schema:
                $ref: "**TESTCALSSOFCLASSPATHORJAR**"
                properties:
                  uuid: # the unique user id
                    type: string
                    format: uuid

2) <plugin>
  <groupId>org.openapitools</groupId>
  <artifactId>openapi-generator-maven-plugin</artifactId>
  <version>${openapi-generator-maven-plugin.version}</version>
  <configuration>
      ... excluded for simplicity
      <importMappings>
          <importMapping>TESTCALSSOFCLASSPATHORJAR=path.to.your.TESTCALSSOFCLASSPATHORJAR</importMapping>        
      </importMappings>
  </configuration>
</plugin>

有什么办法可以从我的类路径/jar java 对象中引用 id 属性名称吗?

paths:
  /users/{id}:
    parameters:
    - name: **id** -> I want to get this prop from TESTCALSSOFCLASSPATHORJAR class 
                      i.e.TESTCALSSOFCLASSPATHORJAR.id
      in: path
      required: true
      description: the user identifier, as userId 
      schema:
        type: string
    get:
      responses:
        '200':
          description: the user being returned
          content:
            application/json:
              schema:
                $ref: "**TESTCALSSOFCLASSPATHORJAR**"
                properties:
                  uuid: # the unique user id
                    type: string
                    format: uuid

参考了下面的文档并进行了很多搜索,但没有找到任何解决方案。

https://github.com/OAI/OpenAPI- 规范 https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-maven-plugin

任何建议将不胜感激。

标签: yamlopenapi-generator

解决方案


推荐阅读