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
  • #4362
Closed
Open
Issue created Nov 04, 2019 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][Java][Go-experimental] Referenced schema for `array` type badly generated

Created by: zippolyte

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Defining a schema for an array type, and referencing it as the items type in another array doesn't generate valid code. It happened for me in Java and go-experimental that I'm using, but might be the case for other languages as well.

openapi-generator version

4.1.3

OpenAPI declaration file content or url

The following schemas definition exhibit the behavior

NestedArray:
  type: array
  items:
    type: string
MainSchema:
  type: object
  properties:
    nested_array:
      type: array
      items:
        $ref: '#/components/schemas/NestedArray'

In go, the generated output looks like this, which doesn't even compile since Array is undefined:

type MainSchema struct {
	NestedArray *[]Array `json:"nested_array,omitempty"`
}

instead of the expected output of either

type MainSchema struct {
	NestedArray *[]NestedArray `json:"nested_array,omitempty"`
}

if we generated a model for the NestedArray schema, or simply

type MainSchema struct {
	NestedArray *[][]string `json:"nested_array,omitempty"`
}

if we don't generate a model (which it seems is what is supposed to happen when we create a schema for a primitive type).

In java, the output is

public class MainSchema {
  public static final String JSON_PROPERTY_NESTED_ARRAY = "nested_array";
  private List<List> nestedArray = null;
}

instead of

public class MainSchema {
  public static final String JSON_PROPERTY_NESTED_ARRAY = "nested_array";
  private List<List<String>> nestedArray = null;
}

Please note that the correct output is generated when inlining the NestedArray definition instead of referencing it in the MainSchema, like so:

MainSchema:
  type: object
  properties:
    nested_array:
      type: array
      items:
        type: array
        items:
          type: string
Command line used for generation

openapi-generator generate --http-user-agent DataDog/1.0.0/java -g java -c config/languages/java_v1.json -i spec/v1/full_spec.yaml -o generated/datadog-api-client-java/v1 -t templates/java'

Steps to reproduce

Make a spec with the above schema definitions, and inspect the generated model for MainSchema

Related issues/PRs
Suggest a fix
Assignee
Assign to
Time tracking