4

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

On parameters of paths I can not use the type Text created in definitions. On the definition Product I have a property called message and I want that property to be the type Text too.

(...)

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 reference the type Text on the type Product?

Computered
  • 440
  • 1
  • 7
  • 21

1 Answers1

3

Please use $ref instead. Here is an example

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

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

William Cheng
  • 10,137
  • 5
  • 54
  • 79
  • Hi, thank you for your answer... It works for this example, but now I cant using $ref inside of paths parameters. I put the example above. Do you know how to reference this type inside parameters of paths? Regards. – Computered Sep 11 '15 at 16:39
  • For path parameter, you cannot use `model`. Path parameter should be of primitive type, e.g. string, number, etc. – William Cheng Sep 12 '15 at 14:28