Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Values of instantiationTypes not considered #3718

Closed
4 of 5 tasks
Marvin1912 opened this issue Aug 21, 2019 · 11 comments
Closed
4 of 5 tasks

[BUG] Values of instantiationTypes not considered #3718

Marvin1912 opened this issue Aug 21, 2019 · 11 comments

Comments

@Marvin1912
Copy link
Contributor

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
@Marvin1912 Marvin1912 changed the title [BUG] Description [BUG] Values of instantiationTypes not considered Aug 21, 2019
@jmini
Copy link
Member

jmini commented Aug 22, 2019

I am not sure if the instantiationTypes were ever used for default value, but this would be a great addition (more a feature than a bug).


I think it is safe to replace:

final String pattern;
if (fullJavaUtil) {
pattern = "new java.util.ArrayList<%s>()";
} else {
pattern = "new ArrayList<%s>()";
}

With:
final String pattern = "new " + instantiationTypes().get("array") + "<%s>()";


And:

final String pattern;
if (fullJavaUtil) {
pattern = "new java.util.HashMap<%s>()";
} else {
pattern = "new HashMap<%s>()";
}

With:
final String pattern = "new " + instantiationTypes().get("map") + "<%s>()";


Optional: A unit test for this could also be added in AbstractJavaCodegenTest


@Marvin1912: Can you file a pull request for that?

@Marvin1912
Copy link
Contributor Author

Hi @jmini,
seems like I'm not able to push to created feature branch from my current workstation. I'll try it once more when I've switched places.

@ala85
Copy link

ala85 commented Dec 13, 2019

Hi @Marvin1912, any update on the above? instantiationTypes field is not really helpful at current state for collections other than plain ArrayList.

@Marvin1912
Copy link
Contributor Author

Hi @ala85
unfortunately I'm not able to push any changes on a feature branch. Unless someone grant me the rights, there's nothing I can do.

@AlexanderUldall
Copy link

Hello @wing328 is this something you or another core contributor could assist with?

@wing328
Copy link
Member

wing328 commented Jan 2, 2020

@Marvin1912
Copy link
Contributor Author

PR created.

@rgavriel
Copy link

Can you please share a link to the PR.
Was it merge? if so, from which version is it available?

@Marvin1912
Copy link
Contributor Author

#4982

@tiffmaelite
Copy link
Contributor

tiffmaelite commented Apr 28, 2023

@Marvin1912 #4982 was merged. Can this issue be closed?

@Marvin1912
Copy link
Contributor Author

@tiffmaelite Yes, can be closed.

@wing328 wing328 closed this as completed Apr 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants