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

Circular reference seems to break validation #62

Open
jkoscialkowski opened this issue Apr 21, 2021 · 0 comments
Open

Circular reference seems to break validation #62

jkoscialkowski opened this issue Apr 21, 2021 · 0 comments

Comments

@jkoscialkowski
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant