Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger error | Data does not match any schemas from 'oneOf'

Tags:

swagger

I'm designing an API using the Swagger specification. Unfournately, I'm facing an error that I can't solve.

Data does not match any schemas from 'oneOf'

Checking the inner property, I found a more descriptive error:

OBJECT_MISSING_REQUIRED_PROPERTY

Missing required property: $ref

Re-reading the spec, I see there is no need to add the $ref property in the parameters "section", so I'm confused and stuck.

The error is on line 34.

{
"swagger": "2.0",
"info": {
    "title": "###",
    "version": "0.1.0"
},
"host": "api.###",
"basePath": "/",
"schemes": [
    "https"
],
"produces": [
    "application/json"
],
"paths": {
    "/social-networks": {
        "get": {
            "summary": "Retrieves all social networks.",
            "description": "Retrieves all social networks supported by ### along with the constraints of each one.",
            "responses": {
                "200": {
                    "description": "",
                    "examples": {
                        "application/json": {}
                    }
                }
            }
        }
    },
    "/social-networks/{name}": {
        "get": {
            "summary": "Retrieves a social network.",
            "description": "Retrieves the social network whose name matches with the specified path parameter.",
            "parameters": [
                {
                    "name": "name",
                    "in": "path",
                    "description": "The name of the social network.",
                    "required": "true",
                    "type": "string"
                }
            ],
            "responses": {
                "200": {
                    "description": ""
                }
            }
        }
    }
}

What am I doing wrong?

like image 883
mongreldog Avatar asked Oct 20 '25 09:10

mongreldog


1 Answers

The required value for path parameters should be true. Yours is string "true".

Your JSON is also invalid, you're missing one } at the end. Here is fixed version of your Swagger in YAML:

---
  swagger: "2.0"
  info: 
    title: "###"
    version: "0.1.0"
  host: "api.###"
  basePath: "/"
  schemes: 
    - "https"
  produces: 
    - "application/json"
  paths: 
    /social-networks: 
      get: 
        summary: "Retrieves all social networks."
        description: "Retrieves all social networks supported by ### along with the constraints of each one."
        responses: 
          200: 
            description: ""
            examples: 
              application/json: {}
    /social-networks/{name}: 
      get: 
        summary: "Retrieves a social network."
        description: "Retrieves the social network whose name matches with the specified path parameter."
        parameters: 
          - 
            name: "name"
            in: "path"
            description: "The name of the social network."
            required: true
            type: "string"
        responses: 
          200: 
            description: ""
like image 165
Mohsen Avatar answered Oct 22 '25 05:10

Mohsen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!