Skip to content

[BUG] Values of instantiationTypes not considered #3718

Closed
@Marvin1912

Description

@Marvin1912

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
openApiGenerate {
    generatorName = 'spring'
    outputDir = "${buildDir}/..."
    inputSpec = "${projectDir}/..."
    apiPackage = "com..."
    invokerPackage = "com..."
    modelPackage = "com..."
    instantiationTypes = [array: "java.util.HashSet"]    
    configOptions = [
            dateLibrary  : "java8",
            interfaceOnly: "true"
    ]
}
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
    4.0.1 (org.openapitools:openapi-generator-gradle-plugin:4.0.1)
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
    Given instantiationTypes = [array: "java.util.HashSet"]
    Actual: ArrayLists are generated
    Expected: Generated HashSets
Description

Wanted to generate HashSets instead of ArrayLists for arrays and set value for instantiationTypes to [array: "java.util.HashSet"]. According to answer of Slack:

Jeremie Bresson vor 16 Stunden
@Marvin please create an issue for that, it seems to me that the default value is hard-coded and not using this instantiationTypes parameter.
See:

public String toDefaultValue(Schema p) {
p = ModelUtils.getReferencedSchema(this.openAPI, p);
if (ModelUtils.isArraySchema(p)) {
final ArraySchema ap = (ArraySchema) p;
final String pattern;
if (fullJavaUtil) {
pattern = "new java.util.ArrayList<%s>()";
} else {
pattern = "new ArrayList<%s>()";
}

openapi-generator version

4.0.1, not a regression

OpenAPI declaration file content or url
openApiGenerate {
    generatorName = 'spring'
    outputDir = "${buildDir}/..."
    inputSpec = "${projectDir}/..."
    apiPackage = "com..."
    invokerPackage = "com..."
    modelPackage = "com..."
    instantiationTypes = [array: "java.util.HashSet"]    
    configOptions = [
            dateLibrary  : "java8",
            interfaceOnly: "true"
    ]
}
Command line used for generation

gradle clean openApiGenerate

Steps to reproduce

Just set instantiationTypes according to example above.

Related issues/PRs
Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions