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
  • #13670
Closed
Open
Issue created Oct 11, 2022 by Administrator@rootContributor5 of 5 checklist items completed5/5 checklist items

[BUG] [java] Additional Properties unable to handle JSON arrays

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?
Description

pojo.moustache doesn't handle additionalProperties in the case where a property value is a JSON array. It fails with e.g:

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at path $[0]

The generated model object should support deserialization.

OpenAPI declaration file content or url

Example fragment from a specification:

components:
  schemas:
    SomeModel:
      type: object
      additionalProperties: true
Steps to reproduce

Using the above YAML specification, generate a java client, then test with an API that produces a property with an array value:

{
  "foo": ["value1"]
}

This yields a runtime failure:

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at path $[0]
Suggest a fix

I'm happy to raise a PR for a fix, which adds support for JSON arrays in pojo.moustache. The problem is the assumption that all properties that are not primitive are always objects:

} else { // non-primitive type
   instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), HashMap.class));
Assignee
Assign to
Time tracking