swagger-codegen:错误与\ d +模式和类型:"数组"

时间:2016-01-19 21:23:49

标签: html swagger

我是Swagger的新手。我已经使用swagger servlet从我们的REST API Java类生成我的swagger.json文件。 swagger.json文件显示了swagger 2.0(我假设这是2.0架构版本)。源文件中没有任何花哨的东西,只有@Api和一些@ApiOperation注释。

然后我尝试使用swagger-codegen-cli(版本2.1.4和2.1.6-SNAPSHOT,最新版本)从JSON文件生成HTML输出。我在两个方面得到了以下结果:

reading from dsm_swagger.json
[main] ERROR io.swagger.codegen.DefaultCodegen - unexpected missing property for name suppressed
[main] WARN io.swagger.codegen.DefaultCodegen - skipping invalid property {
    "type" : "array"
}
writing file /home/combs/dsm_swagger/./index.html

所以我得到了一个输出文件,但是任何标记为对象列表的类型都没有得到正确处理。这些似乎是有效的2.0结构。

我也因为它看到

而得到Jackson关于无效转义字符的错误
"pattern": "\d+"

在文件中。我可以使用[0-9]解决\ d,但是假设它应该按原样处理。

是否有人看到过这些特殊问题并知道他们是否已修复或者swagger-codegen或源文件中有解决方法? swagger-codegen实际上是否正确处理v2.0规范?任何指向最新信息或代码的指针都将不胜感激!

编辑: 如评论中所述,使用" @ JsonIgnore"和" @JsonProperty"在适当的地方升级到swagger-core的V1.5.6,我解决了无效属性和类型" array"消息。以下是\ d:

的问题示例
"/v1/admins/{adminId}": {
  "put": {
    "tags": [
      "admins"
    ],
    "summary": "Update information about a particular admin, given its ID. The update information is passed in the POST body.",
    "description": "Longer notes about what this does",
    "operationId": "updateUser",
    "consumes": [
      "application/json"
    ],
    "produces": [
      "application/json"
    ],
    "parameters": [
      {
        "name": "adminId",
        "in": "path",
        "required": true,
        "type": "integer",
        "pattern": "\d+",
        "format": "int64"
      },
      {
        "in": "body",
        "name": "body",
        "required": false,
        "schema": {
          "$ref": "#/definitions/UserUpdateInfo"
        }
      }
    ],
    "responses": {
      "200": {
        "description": "successful operation",
        "schema": {
          "$ref": "#/definitions/UserInfo"
        }
      }
    }
  }
},

这是swagger-core的确切输出,但是swagger-codegen失败了以下内容:

 combs@dcombs-lap:~/dsm_swagger$ gen_file
 reading from dsm_swagger.json
 reading from dsm_swagger.json
 com.fasterxml.jackson.core.JsonParseException: Unrecognized character escape 'd' (code 100)
   at [Source: dsm_swagger.json; line: 411, column: 27]
   at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1419)
   at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:508)
   at com.fasterxml.jackson.core.base.ParserMinimalBase._handleUnrecognizedCharacterEscape(ParserMinimalBase.java:485)
   at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._decodeEscaped(UTF8StreamJsonParser.java:2924)
   at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._finishString2(UTF8StreamJsonParser.java:2209)
   at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._finishString(UTF8StreamJsonParser.java:2165)
   at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.getText(UTF8StreamJsonParser.java:279)
   at com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeObject(JsonNodeDeserializer.java:224)
   at com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeArray(JsonNodeDeserializer.java:262)
   at com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeObject(JsonNodeDeserializer.java:221)
   at com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeObject(JsonNodeDeserializer.java:218)
   at com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeObject(JsonNodeDeserializer.java:218)
   at com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeObject(JsonNodeDeserializer.java:218)
   at com.fasterxml.jackson.databind.deser.std.JsonNodeDeserializer.deserialize(JsonNodeDeserializer.java:62)
   at com.fasterxml.jackson.databind.deser.std.JsonNodeDeserializer.deserialize(JsonNodeDeserializer.java:14)
   at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3066)
   at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:1861)
   at io.swagger.parser.SwaggerCompatConverter.readResourceListing(SwaggerCompatConverter.java:139)
   at io.swagger.parser.SwaggerCompatConverter.read(SwaggerCompatConverter.java:74)
   at io.swagger.parser.SwaggerParser.read(SwaggerParser.java:73)
   at io.swagger.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:317)
   at io.swagger.codegen.cmd.Generate.run(Generate.java:186)
   at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
Exception in thread "main" java.lang.RuntimeException: missing swagger input or config!
   at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:89)
   at io.swagger.codegen.cmd.Generate.run(Generate.java:188)
   at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
combs@dcombs-lap:~/dsm_swagger$ 

0 个答案:

没有答案