Creating complex types (definitions) in Swagger

I created a definition called Product, and another - Text(see code).

In parameters pathsI can not use the type Textcreated in the definitions. In the definition Product, I have a property called message, and I want this property to be a type too Text.

(...)

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

But this error occurs:

Swagger Error: Data does not match any schemas from "anyOf".

How can I refer from type Textto type Product?

+4
source share
1 answer

Use instead $ref. Here is an example

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

+3

Source: https://habr.com/ru/post/1606777/


All Articles