Swagger编辑器总是在json上给出错误

时间:2015-09-15 11:43:10

标签: json swagger

对我来说,没有一个json字符串可以使用swagger编辑器。

以下是我从页面中获取的一个示例:

{
"swaggerVersion": "2.0",
"basePath": "http://localhost:8000/greetings",
"apis": [
{
  "path": "/hello/{subject}",
  "operations": [
    {
      "method": "GET",
      "summary": "Greet our subject with hello!",
      "type": "string",
      "nickname": "helloSubject",
      "parameters": [
        {
          "name": "subject",
          "description": "The subject to be greeted.",
          "required": true,
          "type": "string",
          "paramType": "path"
        }
      ]
    }
  ]
}
],
"models": {}
}

因此,目前的错误是:

✖ YAML Syntax Error
Missed comma between flow collection entries at line 2, column 14: "swagger: "2.0", ^

2 个答案:

答案 0 :(得分:0)

我不知道你在哪里获取基本代码但是语法似乎完全错误(至少对于招摇2),我建议你去看看the official specification

关于你粘贴的代码,我重构了它,试试这个:

{
    "swagger": "2.0",
    "host": "localhost:8000",
    "basePath": "/greetings",
    "info": {
        "title": "Some title",
        "version": "0.0.1"
    },
    "paths": {
        "/hello/{subject}": {
            "get": {
                "summary": "Greet our subject with hello!",
                "parameters": [{
                    "name": "subject",
                    "description": "The subject to be greeted.",
                    "required": true,
                    "type": "string",
                    "in": "path"
                }],
                "responses": {
                    "default": {
                        "description": "Some description",
                        "schema": {
                            "type": "string"
                        }
                    }
                }
            }
        }
    }
}

答案 1 :(得分:0)

即使OP的语法错误,这也适用于正在寻找答案且其语法正确的其他人。

如果您是从浏览器中获取JSON数据,并且您具有一个浏览器扩展程序,可以很好地格式化和显示JSON数据,则在Swagger Editor中粘贴时可能会引起麻烦(由于格式问题)

在这种情况下,请尝试禁用该扩展名或隐身。