Bug Report Checklist
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
Bug Report Checklist
Description
Defining a schema for an array type, and referencing it as the
itemstype 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
In go, the generated output looks like this, which doesn't even compile since
Arrayis undefined:instead of the expected output of either
if we generated a model for the
NestedArrayschema, or simplyif 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
instead of
Please note that the correct output is generated when inlining the
NestedArraydefinition instead of referencing it in theMainSchema, like so: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
MainSchemaRelated issues/PRs
Suggest a fix