OpenApi couldn't resolve reference

Viewed 1322

I'm learning about OpenApi. I'm getting this error from Swagger:

TypeError: O is undefined value parameter-row.jsx:149 render root-injects.jsx:93 React 8 _renderValidatedComponentWithoutOwnerOrContext _renderValidatedComponent performInitialMount mountComponent mountComponent mountChildren _createInitialChildren mountComponent root-injects.jsx:95:14

My json data is:

{
    "components": {
        "parameters": {
          "q": {
            "in": "query", 
            "name": "q", 
            "style": "form"
          }
        }
    }, 
    "info": {
        "title": "OpenWeatherMap API"
    }, 
    "openapi": "3.0.2", 
    "paths": {
        "/weather": {
          "get": {
              "parameters": [
                {
                  "$ref": "#/components/parameters/q"
                }
              ]
          }
       }
   }
}

screenshot

1 Answers

Your API definition is missing some required keywords. If you paste it into https://editor.swagger.io it will show where the errors are.

Specifically, the q parameter is missing the schema (data type definition).

Here's the correct version:

{
  "components": {
    "parameters": {
      "q": {
        "in": "query",
        "name": "q",
        "style": "form",
        "schema": {
          "type": "string"
        }
      }
    }
  },
  "info": {
    "title": "OpenWeatherMap API",
    "version": "1.0.0"
  },
  "openapi": "3.0.2",
  "paths": {
    "/weather": {
      "get": {
        "parameters": [
          {
            "$ref": "#/components/parameters/q"
          }
        ],
        "responses": {
          "200": {
            "description": "ok"
          }
        }
      }
    }
  }
}
Related