ste
ste

Reputation: 3259

swagger editor: can't add local reference with $ref

I'm creating some API through swagger.

I can't understand how I can use $ref with a reference on the same file... Here's my current swagger file:

openapi: 3.0.0
info:
  title: test API
  version: "1.0.0"
  description: This is a sample API.

servers:
  - url: http://api.internal.com/api
paths:
  /sources/:
    get:
      summary: returns all sources given a page and a size
      parameters:
        - name: page
          required: true
          in: query
          description: Limits the number of items on a page
          schema:
            type: integer
        - name: size
          required: true
          in: query
          description: Specifies a page size
          schema:
            type: integer
      responses:
        '200':
          $ref: '#/definitions/myElement'


definitions:
  myElement:
    "data": {
        "sources": [
          {
            "id": "fw5pQ08wMnFfbEE",
            "fileName": "test.csv",
            "size": 1000000,
            "annotatedDate": "2018-10-01 12:00:00",
            "metadataContact": "[email protected]",
            "canBeIngested": true 
          }
        ],
        "stats": {
            "total": 4000,
            "page": 1,
            "size": 20
        }
    }

Now, the problem is that the editor is throwing me this error:

Errors
Schema error should NOT have additional properties
additionalProperty: definitions
Jump to line 0

in the documentation of $ref I can't really find anything helpful...

How can I fix this?

Upvotes: 0

Views: 1598

Answers (1)

Helen
Helen

Reputation: 97540

In OpenAPI 3.0, definitions were replaced with components/schemas. This means you need to use:

      responses:
        '200':
          $ref: '#/components/schemas/myElement'

and

components:
  schemas:
    myElement:
      ...

Also, your model definition for myElement is not valid. See this guide to learn how to describe objects, properties, etc.

Upvotes: 2

Related Questions