forked from loafle/openapi-generator-original
This reverts commit 7cc995ab10ca607fa113650e311e50bd84d893fc.
This commit is contained in:
parent
7cc995ab10
commit
db53fdffb2
@ -32,7 +32,6 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.capitalize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen {
|
||||
@ -190,7 +189,7 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen
|
||||
if (!im.equals(cm.classname)) {
|
||||
HashMap<String, String> tsImport = new HashMap<>();
|
||||
tsImport.put("classname", im);
|
||||
tsImport.put("filename", toModelFilename(removeModelPrefixSuffix(im)));
|
||||
tsImport.put("filename", toModelFilename(im));
|
||||
tsImports.add(tsImport);
|
||||
}
|
||||
}
|
||||
@ -310,20 +309,6 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen
|
||||
return toApiFilename(name);
|
||||
}
|
||||
|
||||
private String removeModelPrefixSuffix(String name) {
|
||||
String result = name;
|
||||
final String prefix = capitalize(this.modelNamePrefix);
|
||||
final String suffix = capitalize(this.modelNameSuffix);
|
||||
|
||||
if (prefix.length() > 0 && result.startsWith(prefix)) {
|
||||
result = result.substring(prefix.length());
|
||||
}
|
||||
if (suffix.length() > 0 && result.endsWith(suffix)) {
|
||||
result = result.substring(0, result.length() - suffix.length());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) {
|
||||
super.addAdditionPropertiesToCodeGenModel(codegenModel, schema);
|
||||
|
@ -1,10 +1,6 @@
|
||||
package org.openapitools.codegen.typescript.typescriptnode;
|
||||
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.media.ObjectSchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.media.StringSchema;
|
||||
import org.openapitools.codegen.CodegenModel;
|
||||
import org.openapitools.codegen.TestUtils;
|
||||
import org.openapitools.codegen.languages.TypeScriptNodeClientCodegen;
|
||||
import org.testng.Assert;
|
||||
@ -161,64 +157,6 @@ public class TypeScriptNodeClientCodegenTest {
|
||||
Assert.assertEquals(extractedImports.get(0).get("filename"), importName);
|
||||
}
|
||||
|
||||
@Test(description = "correctly produces imports with model name suffix")
|
||||
public void postProcessOperationsWithModelsTestWithModelNameSuffix() {
|
||||
final OpenAPI openAPI = TestUtils.createOpenAPI();
|
||||
final Schema rootSchema = new ObjectSchema()
|
||||
.addProperties("child", new Schema().$ref("Child"));
|
||||
final Schema childSchema = new ObjectSchema()
|
||||
.addProperties("key", new StringSchema());
|
||||
|
||||
openAPI.getComponents()
|
||||
.addSchemas("Root", rootSchema)
|
||||
.addSchemas("Child", childSchema);
|
||||
|
||||
final TypeScriptNodeClientCodegen codegen = new TypeScriptNodeClientCodegen();
|
||||
codegen.setModelNameSuffix("Suffix");
|
||||
|
||||
final HashMap<String, Object> allModels = createParameterForPostProcessAllModels(
|
||||
codegen.fromModel("Root", rootSchema),
|
||||
codegen.fromModel("Child", childSchema)
|
||||
);
|
||||
final Map<String, Object> results = codegen.postProcessAllModels(allModels);
|
||||
final Map<String, Object> root = (Map<String, Object>) results.get("Root");
|
||||
final List<Map<String, Object>> modelsOfRoot = (List<Map<String, Object>>) root.get("models");
|
||||
final List<HashMap<String, String>> tsImports = (List<HashMap<String, String>>) modelsOfRoot.get(0)
|
||||
.get("tsImports");
|
||||
|
||||
Assert.assertEquals(tsImports.size(), 1);
|
||||
Assert.assertEquals(tsImports.get(0).get("filename"), "./childSuffix");
|
||||
}
|
||||
|
||||
@Test(description = "correctly produces imports with model name prefix")
|
||||
public void postProcessOperationsWithModelsTestWithModelNamePrefix() {
|
||||
final OpenAPI openAPI = TestUtils.createOpenAPI();
|
||||
final Schema rootSchema = new ObjectSchema()
|
||||
.addProperties("child", new Schema().$ref("Child"));
|
||||
final Schema childSchema = new ObjectSchema()
|
||||
.addProperties("key", new StringSchema());
|
||||
|
||||
openAPI.getComponents()
|
||||
.addSchemas("Root", rootSchema)
|
||||
.addSchemas("Child", childSchema);
|
||||
|
||||
final TypeScriptNodeClientCodegen codegen = new TypeScriptNodeClientCodegen();
|
||||
codegen.setModelNamePrefix("Prefix");
|
||||
|
||||
final HashMap<String, Object> allModels = createParameterForPostProcessAllModels(
|
||||
codegen.fromModel("Root", rootSchema),
|
||||
codegen.fromModel("Child", childSchema)
|
||||
);
|
||||
final Map<String, Object> results = codegen.postProcessAllModels(allModels);
|
||||
final Map<String, Object> root = (Map<String, Object>) results.get("Root");
|
||||
final List<Map<String, Object>> modelsOfRoot = (List<Map<String, Object>>) root.get("models");
|
||||
final List<HashMap<String, String>> tsImports = (List<HashMap<String, String>>) modelsOfRoot.get(0)
|
||||
.get("tsImports");
|
||||
|
||||
Assert.assertEquals(tsImports.size(), 1);
|
||||
Assert.assertEquals(tsImports.get(0).get("filename"), "./prefixChild");
|
||||
}
|
||||
|
||||
private Map<String, Object> createPostProcessOperationsMapWithImportName(String importName) {
|
||||
Map<String, Object> operations = new HashMap<String, Object>() {{
|
||||
put("operation", Collections.emptyList());
|
||||
@ -236,30 +174,4 @@ public class TypeScriptNodeClientCodegenTest {
|
||||
put("imports", imports);
|
||||
}};
|
||||
}
|
||||
|
||||
private HashMap<String, Object> createParameterForPostProcessAllModels(CodegenModel root, CodegenModel child) {
|
||||
return new HashMap<String, Object>() {{
|
||||
put("Child", new HashMap<String, Object>() {{
|
||||
put("models", Collections.singletonList(
|
||||
new HashMap<String, Object>() {{
|
||||
put("importPath", "../model/child");
|
||||
put("model", child);
|
||||
}}
|
||||
));
|
||||
}});
|
||||
put("Root", new HashMap<String, Object>() {{
|
||||
put("models", Collections.singletonList(
|
||||
new HashMap<String, Object>() {{
|
||||
put("importPath", "../model/root");
|
||||
put("model", root);
|
||||
}}
|
||||
));
|
||||
put("imports", Collections.singletonList(
|
||||
new HashMap<String, Object>() {{
|
||||
put("import", "../model/child");
|
||||
}}
|
||||
));
|
||||
}});
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user