27

I'm getting the error Data does not match any schemas from 'oneOf' with the following spec:

{
  "info": {
    "version": "1.0.0",
    "title": "REST API"
  },
  "paths": {
    "/doit": {
      "post": {
        "responses": {
          "200": {
            "description": "Successful response"
          }
        },
        "parameters": [
          {
            "type": "object",
            "schema": {
              "$ref": "#/definitions/ResponseDefinition"
            },
            "required": "true",
            "name": "docs",
            "in": "body"
          }
        ]
      }
    }
  },
  "swagger": "2.0",
  "definitions": {
    "ResponseDefinition": {
      "type": "object",
      "properties": {
        "text": {
          "type": "string",
          "description": ""
        }
      }
    }
  }
}

This full errorfrom the swagger-tools validator:

#/paths/~1doit/post/parameters/0: Data does not match any schemas from 'oneOf'
#/paths/~1doit/post/parameters/0: Data does not match any schemas from 'oneOf'
  #/required: Expected type boolean but found type string
  #/: Missing required property: type
#/paths/~1doit/post/parameters/0: Additional properties not allowed: in,name,required,schema

I don't understand the error or how to resolve.

Tim
  • 508
  • 1
  • 4
  • 8

3 Answers3

21

You can't include type in a body parameter. That's why there's the schema. Try this:

{
  "info": {
    "version": "1.0.0",
    "title": "REST API"
  },
  "paths": {
    "/doit": {
      "post": {
        "responses": {
          "200": {
            "description": "Successful response"
          }
        },
        "parameters": [
          {
            "schema": {
              "$ref": "#/definitions/ResponseDefinition"
            },
            "required": "true",
            "name": "docs",
            "in": "body"
          }
        ]
      }
    }
  },
  "swagger": "2.0",
  "definitions": {
    "ResponseDefinition": {
      "type": "object",
      "properties": {
        "text": {
          "type": "string",
          "description": ""
        }
      }
    }
  }
}
Ron
  • 14,160
  • 3
  • 52
  • 39
0

For me it was incorrect apidoc that led to the error. This doc produced the error:

/**
 * @openapi
 * /init:
 *   get:
 *     description: Tells the app an environment it should use
 *     parameters:
 *       - name: version
 *         in: query
 *         description: app version, for example "4.0.0"
 *         required: true
 *         type: string
 *     responses:
 *       200:
 *         description: Description
 */

Please note there is a type right under parameters

When I put type under parameters -> schema it started to be valid:

/**
 * @openapi
 * /init:
 *   get:
 *     description: Tells the app an environment it should use
 *     parameters:
 *       - name: version
 *         in: query
 *         description: app version, for example "4.0.0"
 *         required: true
 *         schema:
 *           type: string
 *     responses:
 *       200:
 *         description: Description
 */
Kirill Oficerov
  • 2,152
  • 2
  • 15
  • 11
0

I realized I put wrong Model Bindings for my API.
I put FromQuery instead of FromBody

malisasmaz
  • 99
  • 1
  • 7