Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #13774
Closed
Open
Issue created Oct 20, 2022 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

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

Created by: ashatch

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 3ae37e27, pojo.moustache line 500. I'll work on a PR.

Assignee
Assign to
Time tracking