swagger-api / swagger-api/swagger-codegen

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

Open
#10,246 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the generated Java client's failure with a response where snag_items is an array, using the schema and JSON examples in the issue. Compare the generated parser's expected object handling with the valid array value; done requires an agreed behavior for arbitrary values, since the issue proposes multiple possible fixes.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.