Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swagger 招摇过市与相关对象进行响应_Swagger_Swagger Ui_Api Design_Openapi - Fatal编程技术网

Swagger 招摇过市与相关对象进行响应

Swagger 招摇过市与相关对象进行响应,swagger,swagger-ui,api-design,openapi,Swagger,Swagger Ui,Api Design,Openapi,我正在使用SwiggerHub和OpenAPI3来定义一个API。一个路由GET/foo/{id]应该返回给定id的foo对象及其关联的bar对象。API将返回类似以下内容:{id:4,name:'test',bar:[{id:53,name:'barName1'},{id:87,name:'barName2'}。即foo和bar之间存在多对多关系 我如何用OpenAPI 3语法描述它?我已经尝试使用该属性。到目前为止,我已经: paths: /foo/{id}: get:

我正在使用SwiggerHub和OpenAPI3来定义一个API。一个路由
GET/foo/{id]
应该返回给定
id
foo
对象及其关联的
bar
对象。API将返回类似以下内容:
{id:4,name:'test',bar:[{id:53,name:'barName1'},{id:87,name:'barName2'}
。即
foo
bar
之间存在多对多关系

我如何用OpenAPI 3语法描述它?我已经尝试使用该属性。到目前为止,我已经:

paths:
  /foo/{id}:
    get:
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          content:
            application/json:
              schema:
                type: array
                items: 
                  $ref: '#/components/schemas/Foo'
                anyOf:
                  - $ref: '#/components/schemas/Bar'

但这似乎并没有在UI中显示正确的模式(UI中没有提到
Bar

您不需要
anyOf
anyOf
表示替代(“Foo或Bar”),而您有一个常见的嵌套结构-一个具有属性
Bar
的对象
Foo
,它是一个
Bar
s数组。这可以描述为:

响应:
'200':
描述:好的
内容:
应用程序/json:
模式:
$ref:“#/components/schemas/Foo”
组件:
模式:
傅:
类型:对象
特性:
酒吧:
类型:数组
项目:
$ref:“#/components/schemas/Bar”
必修的:
-栅栏
酒吧:
...