openapi 3.0schema 是否可以实现java中泛型generic type功能。

4,265 阅读1分钟

openapi可以用allof实现, 例如下面写法。但是将oas的ymal通过代码生成工具生成对应的java代码,代码生成工具到到现在为止不支持这种情况。代码生成工具org.openapitools:openapi-generator-maven-plugin:4.3.1不支持。

responses:
    200:
        description: success
        content:
        application/json:
            schema:
                allOf:
                - $ref: '#/components/schemas/RespPageInfo'
                - type: object
                    properties:
                    list:
                        type: array
                        items:
                        $ref: '#/components/schemas/NeuhiveVo'

通过swagger editor可以解析成功看到具体example value:

{
  "pageNum": 0,
  "pageSize": 0,
  "size": 0,
  "total": 0,
  "hasNextPage": true,
  "list": [
    {
      "id": 0,
      "code": "string",
      "name": "string",
      "owner": "string",
      "version": "string",
      "address": "string",
      "status": "string"
    }
  ]
}