Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Circular reference seems to break validation #62

Open

Description

@jkoscialkowski

Hi! It seems I might have been using the OpenAPI spec the wrong way - putting definitions field in schemas which is not supported by the spec. However, I haven't got any errors using swagger-cli validate due to the issue I describe below.

Assume the main spec is:

openapi: "3.0.3"
info:
  version: 0.0.1
  title: API
  description: Some description
paths:
  /route:
    get:
      operationId: route
      requestBody:
        content:
          application/json:
            schema:
              $ref: ./schema.yaml
      responses:
        '200':
          description: Successful
          content:
            application/json:
              schema:
                type: object

Then there are 3 scenarios depending on the contents of schema.yaml.

1. WORKS

type: object
properties:
  prop1:
    type: string

2. FAILS

type: object
properties:
  prop1:
    type: string
definitions:
  somedef:
    type: string

The error message is

Swagger schema validation failed. 
  Data does not match any schemas from 'oneOf' at #/paths//route/get/requestBody
    Data does not match any schemas from 'oneOf' at #/paths//route/get/requestBody/content/application/json/schema
      Additional properties not allowed: definitions at #/content/application/json/schema
      Missing required property: $ref at #/content/application/json/schema
    Missing required property: $ref at #/paths//route/get/requestBody
 
JSON_OBJECT_VALIDATION_FAILED

3. WORKS

type: object
properties:
  prop1:
    type: string
definitions:
  somedef:
    $ref: '#/definitions/somedef'

While I have found some info that OpenAPI doesn't forbid circular references, this seems to be an error, because the definitions field should not be accepted at all.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions