4

我创建了一个名为Product和另一个名为的定义Text(参见代码)。

我不能使用定义中创建的parameters类型。在定义上,我有一个名为的属性,我希望该属性也是类型。pathsTextProductmessageText

(...)

paths:
  /products:
    get:
      summary: Product Types
      description: |
        Description text
      parameters:
        - name: latitude
          in: query
          description: Latitude component of location.
          required: true
          ### The type Text was not found here
          type: Text ### The type Text was not found here
(...)

definitions:

  Product:
    properties:
      message:
        ### The type Text was not found here
        type: Text ### Compilation Error in this line ####
      name:
        type: string
        description: Data description.


  Text:
    properties:
      code:
        type: string

但是会出现这个错误:

Swagger 错误:数据与“anyOf”中的任何模式都不匹配。

如何在类型Text上引用类型Product

4

1 回答 1

3

$ref改用。这是一个例子

type: object
required:
- name
properties:
  name:
    type: string
  address:
    $ref: '#/definitions/Address'
  age:
    type: integer
    format: int32
    minimum: 0

参考:https ://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#simple-model

于 2015-09-11T02:51:35.760 回答