Skip to content

Decoding swagger codegen errors

Bert Kleewein edited this page Nov 21, 2019 · 1 revision

Decoding swagger codegen errors

The error spew you get when you run a codegen script sucks. There's a ton of useless info. Here's how to get what you need.

Note: in my experience, swagger errors fall into a few buckets. Among them:

  1. Missing comma between JSON elements in an object or array
  2. Extra comma at end of JSON object or array
Generating wrappers for yaml using swagger-yaml generator
[main] INFO io.swagger.parser.Swagger20Parser - reading from /local/v2/swagger.json
Exception in thread "main" java.lang.RuntimeException: An exception was thrown while trying to deserialize the contents of net.json into a JsonNode tree
        at io.swagger.parser.util.DeserializationUtils.deserializeIntoTree(DeserializationUtils.java:88)
        at io.swagger.parser.ResolverCache.deserialize(ResolverCache.java:160)
        at io.swagger.parser.ResolverCache.loadRef(ResolverCache.java:133)
        at io.swagger.parser.processors.PathsProcessor.processPaths(PathsProcessor.java:79)
        at io.swagger.parser.SwaggerResolver.resolve(SwaggerResolver.java:50)
        at io.swagger.parser.SwaggerParser.read(SwaggerParser.java:71)
        at io.swagger.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:431)
        at io.swagger.codegen.cmd.Generate.run(Generate.java:283)
        at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('}' (code 125)): was expecting double-quote to start field name
 at [Source: (String)"{
  "setDestination": {
    "put": {
      "tags": [
        "net"
      ],
      "summary": "Set destination for net disconnect ops",
      "operationId": "netSetDestination",
      "parameters": [
        {
          "name": "ip",
          "in": "path",
          "required": true,
          "type": "string"
        },
        {
          "$ref": "parameters.json#/transport"
        }
      ],
      "responses": {
        "200": {
          "description": "OK"
        }
      }
    }
  },
  "d"[truncated 1429 chars]; line: 98, column: 2]
        at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1804)
        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:693)
        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:591)
        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddName(ReaderBasedJsonParser.java:1767)
        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextFieldName(ReaderBasedJsonParser.java:917)
        at com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeObject(JsonNodeDeserializer.java:247)
        at com.fasterxml.jackson.databind.deser.std.JsonNodeDeserializer.deserialize(JsonNodeDeserializer.java:68)
        at com.fasterxml.jackson.databind.deser.std.JsonNodeDeserializer.deserialize(JsonNodeDeserializer.java:15)
        at com.fasterxml.jackson.databind.ObjectMapper._readTreeAndClose(ObjectMapper.java:4056)
        at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2551)
        at io.swagger.parser.util.DeserializationUtils.deserializeIntoTree(DeserializationUtils.java:83)
        ... 8 more
docker run returned failure
generate.sh failed
(Python-3.7.5) (base) bertk@bertk-newvm-1:~/repos/e2e-fx/swagger$

First clue: what file?

Exception in thread "main" java.lang.RuntimeException: An exception was thrown while trying to deserialize the contents of net.json into a JsonNode tree

This error is in net.json

Second clue: what line:

  "d"[truncated 1429 chars]; line: 98, column: 2]

This error is somewhere around line 98 in net.json. Not exactly on that line, but near that line.

Third clue: what error?

Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('}' (code 125)): was expecting double-quote to start field name

This error has something to do with quoting strings.

Surprise: not a quote problem after all

at line 98 in net.py, we find this:

    }
  },
}

The real problem is an extra comma. The reason we got this error was because the parser saw the comma, then expected a new object name. It got a closing quote and said "that's not a valid field name, I need to see a quote."

Thanks, parser, that was a really useful error message.

Clone this wiki locally