为什么定义无法在此架构中显示?

时间:2015-02-20 01:33:35

标签: swagger swagger-ui

我正在尝试开发符合swagger规范的架构。见下文。参数和响应的定义(模型/模式)不会显示在swagger-ui界面中,所以我的问题是为什么。架构传递了swagger验证器。

{
  "swagger": "2.0",
  "info": {
    "version": "1.0.0",
    "title": "example",
    "description": "provides  various stuff",
    "termsOfService": "none",
    "contact": {
      "name": "admin",
      "url": "http://www.example.co.uk",
      "email": "hostmaster@example.com"
    },
    "license": {
      "name": "All Rights Reserved.",
      "url": "http://example.com"
    }
  },
  "host": "ofexample.co.uk",
  "basePath": "/",
  "schemes": [
    "https"
  ],
  "paths": {
    "/list": {
      "post": {
        "parameters": [
          {
            "name": "no_name",
            "in": "body",
            "required": false,
            "schema": {
              "$ref": "#definitions/APIName"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "",
            "schema": {
              "$ref": "#definitions/Versions"
            }
          }
        }
      }
    },
    "/ver/setdefault": {
      "post": {
        "parameters": [
          {
            "name": "no_name",
            "in": "body",
            "required": false,
            "schema": {
              "$ref": "#definitions/App"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "",
            "schema": {
              "$ref": "#definitions/App"
            }
          }
        }
      }
    }
  },
  "definitions": {
    "APIName": {
      "type": "string"
    },
    "App": {
      "properties": {
        "name": {
          "type": "object",
          "$ref": "#/definitions/APIName",
          "description": "\n The name"
        },
        "id": {
          "type": "string",
          "description": "important field"
        },
        "version": {
          "type": "string"
        }
      }
    },
    "Versions": {
      "type": "string",
      "additionalProperties": {
        "type": "array",
        "items": {
          "type": "string"
        }
      }
    }
  }
}

1 个答案:

答案 0 :(得分:0)

规范本身几乎是正确的,只有部分关闭的是$ref。例如,/#之间需要definitions/APIName

      {
        "name": "no_name",
        "in": "body",
        "required": false,
        "schema": {
          "$ref": "#/definitions/APIName"
        }
      }

请注意,由于错误,UI不会显示任何引用的基元。将其内联为参数定义将正确显示,但对于响应,它将赢得

另一个注意事项,虽然现在没有明确定义,如果没有consumes / produces,将使用的mime类型为application/json。如果要使用文本,可能需要将其设置为text/plain以传递字符串。