Swagger Error 预期类型字符串但找到类型整数

Swagger Error Expected type string but found type integer

我最近开始使用 swagger 为我们的 RESTful api 生成文档。我使用 yamlbeans-1.09.jar 将我的 Java DTO 转换为 yaml 文件。 一切正常,yaml 甚至在 http://www.yamllint.com/ 上得到了正确验证,但仍然在使用 Swagger 界面对其进行测试时,它给出了一个错误 "Expected type string but found type integer""No enum match for: 2" 我在文件中提到 swagger : 2.0 的任何地方。

我的示例 yml 文件是:

basePath: /employment
host: api.xxxx.com
schemes: 
    - https
swagger: 2.0
info: 
    title: API Doc
    description: Description for the info goes here
    version: 1.0.0

它总是倾向于在 swagger 版本之前只给出一个行号的错误。任何帮助将不胜感激。

编辑: 我在 java 代码中将 swagger 版本定义为字符串,并按如下所述编写:

HashMap<String, Object> rootElementsForYml = new HashMap<String, Object>();
rootElementsForYml.put(SWAGGER, "2.0");
rootElementsForYml.put(HOST, "api.xxxx.com");
rootElementsForYml.put(BASEPATH, basePath);
rootElementsForYml.put(SCHEMES, new String[]{"https"});

但还是没有结果,还是同样的错误。

那是因为版本值是字符串而不是数字。仅指定 2.0 被解释为数字。用 "2.0" 之类的引号将其包裹起来,这样就可以正常工作。