swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

[JAVA] Error parsing response when array is returned instead of (empty) object

Open kaplin opened this issue 6 years ago • 0 comments

Description

Schema defines a property which expects arbitrary object:

...
"RawMessage": {
  "title": "Any JSON value"
}
...
"snag_items": {
  "$ref": "#/definitions/RawMessage"
},
...

Server returns array as a value of snag_items property:

...
"snag_items":[{"summary":"bla blab bla", ...}, ...]
...

According to JSON Schema, this is valid value for snag_items. However, trying to parse it with generated code leads to:

java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 941 path $.prime_config.snags.snag_items
Swagger-codegen version

3.0.19

Suggest a fix/enhancement

There are two ways of dealing with this — one is to ignore array whatsoever during parsing, and another is to treat types without properties as plain Objects (and let parser put List there, say).

As a side note, would be nice to have ability to ignore particular property in codegen.

kaplin avatar May 13 '20 22:05 kaplin