OpenAPI PHP客户端使用anyOf给出致命错误

nan*_*ocv 10 php polymorphism swagger openapi openapi-generator

我正在尝试使用anyOfallOf属性创建OpenAPI自动生成的PHP客户端。

目标是能够返回其中具有多态性的数组:不同类型的对象。
这些对象也具有一个公共的基础对象。

在我的示例模式中,Items是一个数组,其中各项可以是类型ItemOneItemTwo
这两种类型的项目有一个自己的财产(itemOnePropertyitemTwoProperty,分别地),和一个共同的属性baseItemProperty(从继承BaseItemallOf关键字)。

这里有API规范yaml:

openapi: 3.0.0
info:
  title: Test API
  version: 1.0.0
servers:
  - url: https://api.myjson.com/bins

paths:
  /roxgd:
    get:
      operationId: getItems
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Items'
components:
  schemas:

    Items:
      type: array
      items:
        anyOf:
          - $ref: '#/components/schemas/ItemOne'
          - $ref: '#/components/schemas/ItemTwo'

    BaseItem:
      type: object
      properties:
        baseItemProperty:
          type: string

    ItemOne:
      allOf:
        - $ref: '#/components/schemas/BaseItem'
        - type: object
          properties:
            itemOneProperty:
              type: string

    ItemTwo:
      allOf:
        - $ref: '#/components/schemas/BaseItem'
        - type: object
          properties:
            itemTwoProperty:
              type: string
Run Code Online (Sandbox Code Playgroud)

这是我正在发送请求的端点:https : //api.myjson.com/bins/roxgd

然后返回此示例json:

[
    {
        type: "ItemOne",
        baseItemProperty: "foo1",
        itemOneProperty: "bar1"
    },
    {
        type: "ItemTwo",
        baseItemProperty: "foo2",
        itemTwoProperty: "bar2"
    }
]
Run Code Online (Sandbox Code Playgroud)

PHP客户端的生成没有错误,但是在调用该getItems方法时,出现了致命错误:

PHP Fatal error:  Uncaught Error: Class 'AnyOfItemOneItemTwo' not found in /home/user/projects/openapi-test/lib/ObjectSerializer.php:309
Stack trace:
#0 /home/user/projects/openapi-test/lib/ObjectSerializer.php(261): MyRepo\OpenApiTest\ObjectSerializer::deserialize(Object(stdClass), 'AnyOfItemOneIte...', NULL)
#1 /home/user/projects/openapi-test/lib/Api/DefaultApi.php(182): MyRepo\OpenApiTest\ObjectSerializer::deserialize(Array, 'AnyOfItemOneIte...', Array)
#2 /home/user/projects/openapi-test/lib/Api/DefaultApi.php(128): MyRepo\OpenApiTest\Api\DefaultApi->getItemsWithHttpInfo()
#3 /home/user/projects/tests-for-openapi-test/test.php(10): MyRepo\OpenApiTest\Api\DefaultApi->getItems()
#4 {main}
  thrown in /home/user/projects/openapi-test/lib/ObjectSerializer.php on line 309
Run Code Online (Sandbox Code Playgroud)

如果使用该oneOf属性,也会发生相同的情况,但出现的错误是:Uncaught Error: Class 'OneOfItemOneItemTwo' not found...


当我使用任何其他有效的Yaml(不包含多态性)时,我的设置正常。

另外,我已经检查了这个相关的问题,但这是关于UI的,我根本没有使用过。

您知道错误可能出在哪里吗?我的Yaml文件有误?PHP客户端生成器中的错误?

编辑:我正在使用openapi-generator v4.0.3(此时最新版本)。

nan*_*ocv 3

经过更多研究,我发现从 4.0.0 版本开始,openapi-generator 中的继承存在一个未解决的问题。

https://github.com/OpenAPITools/openapi-generator/issues/2845