Express 如何在Swagger中定义包含复杂对象数组的示例请求主体?

Express 如何在Swagger中定义包含复杂对象数组的示例请求主体?,express,yaml,swagger,openapi,Express,Yaml,Swagger,Openapi,我正试图为一个服务编写一个招摇过市的规范,该服务将一组对象发布为请求主体。我希望用户能够使用数组中多个不同复杂对象的特定集合作为默认样本输入来测试服务 到目前为止,我有以下定义服务和复杂对象的代码: paths: /myService post: summary: test 123 description: test 123 parameters: - name: bo

我正试图为一个服务编写一个招摇过市的规范,该服务将一组对象发布为请求主体。我希望用户能够使用数组中多个不同复杂对象的特定集合作为默认样本输入来测试服务

到目前为止,我有以下定义服务和复杂对象的代码:

paths:
    /myService
        post:
            summary: test 123
            description: test 123
            parameters:
                - name: bodyParamsObject
                  description: 'Object containing any / all params in the body'
                  in: body
                  required: true
                  schema:
                    properties:
                        data:
                            $ref: '#/definitions/myInputArray'
            responses:
                200:
                    description: OK
                    schema: myOutputArray

definitions:
    myInputArray:
        type: array
        items:
            $ref: '#/definitions/myComplexObject'

    myOutputArray:
        type: array
        items:
            $ref: '#/definitions/myComplexObject'

    myComplexObject:
        type: object
        properties:
            description:
            type: string
            example: 'Example Item'     
        size:
            example: 552
            type: integer
            format: int32
        hasAdditionalProperties:
            type: boolean
            example: true
输出数组正在正确返回,但模型架构中只有一项


如何使示例请求正文在数组中包含多个不同的项?

我可以通过使用对象定义上的example属性并用json中的数组填充来解决这个问题

definitions:
    myInputArray:
        type: array
        items:
            $ref: '#/definitions/myComplexObject'
        example: [
                    {
                        "description": "Example Item 1",
                        "hasAdditionalProperties": true,
                        "size": 750,
                    },
                    {
                        "description": "Another example",
                        "hasAdditionalProperties": false,
                        "size": -22,
                    },                                
                    {
                        "description": "Last one",
                        "hasAdditionalProperties": true,
                        "size": 0,
                    }
                ]

    myComplexObject:
        type: object
        properties:
            description:
            type: string
            example: 'Example Item'     
        size:
            example: 552
            type: integer
            format: int32
        hasAdditionalProperties:
            type: boolean
            example: true

可能重复的Nope。这是关于POST请求体中的输入参数,而不是GET操作的输出。这基本上是一样的,因为这里和那里真正的问题是“如何指定包含多个项的数组示例?”我不同意,我认为这个问题专门针对POST操作的请求体,它应该在一个数组中包含多个不同的项。在任何情况下,我认为这个问题都会增加价值,因为它还说明了除了作为输入的不同项数组之外,如何创建默认的请求主体。