问题描述:

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?

网友答案:

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: ""
相关阅读:
Top