Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [java] non-required arrays fail validation #13774

Closed
5 of 6 tasks
ashatch opened this issue Oct 20, 2022 · 1 comment
Closed
5 of 6 tasks

[BUG] [java] non-required arrays fail validation #13774

ashatch opened this issue Oct 20, 2022 · 1 comment

Comments

@ashatch
Copy link
Contributor

ashatch commented Oct 20, 2022

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Optional array properties in JSON responses fail validation when an optional array property is null:

      // ensure the json data is an array
      if (!jsonObj.get("anotherThing").isJsonArray()) {
        throw new IllegalArgumentException(String.format("Expected the field `linkedContent` to be an array in the JSON string but got `%s`", jsonObj.get("linkedContent").toString()));
      }

A null check is required.

java.lang.NullPointerException: Cannot invoke "com.google.gson.JsonElement.isJsonArray()" because the return value of "com.google.gson.JsonObject.get(String)" is null

Expected to check null and validate successfully.

openapi-generator version

Current master (0d56ebc).

OpenAPI declaration file content or url

Declaration of an array property:

components:
  schemas:
    SomeObject:
      properties:
        something:
          $ref: '#/components/schemas/Something'
        anotherThing:
          items:
            $ref: '#/components/schemas/OtherThingItem'
          type: array
Suggest a fix

Looks like it was introduced in 3ae37e2, pojo.moustache line 500. I'll work on a PR.

@Zomzog
Copy link
Contributor

Zomzog commented Oct 26, 2022

@wing328 I think this one can be closed with the merge of #13777 :)

@ashatch ashatch closed this as completed Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants