Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[typescript-angular] Fix importMapping;
  • Loading branch information
SAnDAnGE committed Oct 31, 2019
commit a7de7df222916518a20c877a21c124029aa8e574
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
private static String CLASS_NAME_SUFFIX_PATTERN = "^[a-zA-Z0-9]*$";
private static String FILE_NAME_SUFFIX_PATTERN = "^[a-zA-Z0-9.-]*$";

private static final String DEFAULT_IMPORT_PREFIX = "./";

public static final String NPM_REPOSITORY = "npmRepository";
public static final String WITH_INTERFACES = "withInterfaces";
public static final String TAGGED_UNIONS = "taggedUnions";
Expand Down Expand Up @@ -330,36 +332,13 @@ public String getTypeDeclaration(Schema p) {
}


@Override
public String getSchemaType(Schema p) {
String openAPIType = super.getSchemaType(p);
if (isLanguagePrimitive(openAPIType) || isLanguageGenericType(openAPIType)) {
return openAPIType;
}
applyLocalTypeMapping(openAPIType);
return openAPIType;
}

private String applyLocalTypeMapping(String type) {
if (typeMapping.containsKey(type)) {
type = typeMapping.get(type);
}
return type;
}

private boolean isLanguagePrimitive(String type) {
return languageSpecificPrimitives.contains(type);
}

private boolean isLanguageGenericType(String type) {
for (String genericType : languageGenericTypes) {
if (type.startsWith(genericType + "<")) {
return true;
}
}
return false;
}

@Override
public void postProcessParameter(CodegenParameter parameter) {
super.postProcessParameter(parameter);
Expand Down Expand Up @@ -562,22 +541,34 @@ public String toApiFilename(String name) {
if (name.length() == 0) {
return "default.service";
}
if (importMapping.containsKey(name)) {
return importMapping.get(name);
}
return this.convertUsingFileNamingConvention(name) + serviceFileSuffix;
}

@Override
public String toApiImport(String name) {
if (importMapping.containsKey(name)) {
return importMapping.get(name);
}
return apiPackage() + "/" + toApiFilename(name);
}

@Override
public String toModelFilename(String name) {
return this.convertUsingFileNamingConvention(this.sanitizeName(name)) + modelFileSuffix;
if (importMapping.containsKey(name)) {
return importMapping.get(name);
}
return DEFAULT_IMPORT_PREFIX + this.convertUsingFileNamingConvention(this.sanitizeName(name)) + modelFileSuffix;
}

@Override
public String toModelImport(String name) {
return modelPackage() + "/" + toModelFilename(name);
if (importMapping.containsKey(name)) {
return importMapping.get(name);
}
return DEFAULT_IMPORT_PREFIX + modelPackage() + "/" + toModelFilename(name);
}

public String getNpmRepository() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{#models}}
{{#model}}
{{#tsImports}}
import { {{classname}} } from './{{filename}}';
import { {{classname}} } from '{{filename}}';
{{/tsImports}}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void testModelFileSuffix() {
codegen.additionalProperties().put("modelSuffix", "MySuffix");
codegen.processOpts();

Assert.assertEquals("testNameMySuffix", codegen.toModelFilename("testName"));
Assert.assertEquals("./testNameMySuffix", codegen.toModelFilename("testName"));
}

@Test
Expand Down