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

[Typescript] update addImport method (fix oneOf) #11689

Merged
merged 9 commits into from
May 30, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -5148,13 +5148,13 @@ protected void addImport(CodegenModel m, String type) {
addImport(m.imports, type);
}

private void addImport(Set<String> importsToBeAddedTo, String type) {
protected void addImport(Set<String> importsToBeAddedTo, String type) {
if (shouldAddImport(type)) {
importsToBeAddedTo.add(type);
}
}

private boolean shouldAddImport(String type) {
protected boolean shouldAddImport(String type) {
return type != null && needToImport(type);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1569,14 +1569,37 @@ protected void addImport(CodegenModel m, String type) {
return;
}

String[] parts = type.split("( [|&] )|[<>]");
String[] parts = splitComposedType(type);
for (String s : parts) {
if (needToImport(s)) {
m.imports.add(s);
}
}
}

@Override
protected void addImport(Set<String> importsToBeAddedTo, String type) {
ksvirkou-hubspot marked this conversation as resolved.
Show resolved Hide resolved
if (type == null) {
return;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add tests that are directly related to your code change? i.e. tests that would fail without your change.

Copy link
Contributor Author

@ksvirkou-hubspot ksvirkou-hubspot Feb 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok
I ll try to do something
but maybe it would be an example of this in the petstore and test there
I ll think over it

String[] parts = splitComposedType(type);
for (String s : parts) {
super.addImport(importsToBeAddedTo, s);
}
}

/**
* Split composed types
* e.g. TheFirstType | TheSecondType to TheFirstType and TheSecondType
*
* @param type String with composed types
* @return list of types
*/
protected String[] splitComposedType(String type) {
return type.replace(" ","").split("[|&<>]");
}

@Override
public GeneratorLanguage generatorLanguage() { return GeneratorLanguage.TYPESCRIPT; }
}