Permalink
Browse files

Fix a problem that points to a folder that doesn't exist (#1863)

* Add test case that reproduce issues

* Fix a problem that points to a folder that doesn't exist

* Improves for windows

* Run ensure-up-to-date script

./bin/utils/ensure-up-to-date
  • Loading branch information...
ackintosh authored and wing328 committed Jan 11, 2019
1 parent 00a9cfd commit 4652023b7cd25d03b1ab23986d913d2e72d4e1f6
@@ -536,22 +536,22 @@ public String escapeReservedWord(String name) {

@Override
public String apiFileFolder() {
return (outputFolder + "/" + sourceFolder + "/" + apiPackage()).replace('.', File.separatorChar);
return (outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar)).replace('/', File.separatorChar);
}

@Override
public String apiTestFileFolder() {
return (outputFolder + "/" + testFolder + "/" + apiPackage()).replace('.', File.separatorChar);
return (outputFolder + "/" + testFolder + "/" + apiPackage().replace('.', File.separatorChar)).replace('/', File.separatorChar);
}

@Override
public String modelTestFileFolder() {
return (outputFolder + "/" + testFolder + "/" + modelPackage()).replace('.', File.separatorChar);
return (outputFolder + "/" + testFolder + "/" + modelPackage().replace('.', File.separatorChar)).replace('/', File.separatorChar);
}

@Override
public String modelFileFolder() {
return (outputFolder + "/" + sourceFolder + "/" + modelPackage()).replace('.', File.separatorChar);
return (outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar)).replace('/', File.separatorChar);
}

@Override
@@ -27,6 +27,8 @@
import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.File;

public class AbstractJavaCodegenTest {

private final AbstractJavaCodegen fakeJavaCodegen = new P_AbstractJavaCodegen();
@@ -156,6 +158,49 @@ public void toEnumValue(){
Assert.assertEquals(codegen.toEnumValue("3.14", "Float"), "3.14f");
}

@Test
public void apiFileFolder() {
final AbstractJavaCodegen codegen = new P_AbstractJavaCodegen();
codegen.setOutputDir("/User/open.api.tools");
codegen.setSourceFolder("source.folder");
codegen.setApiPackage("org.openapitools.codegen.api");
Assert.assertEquals(codegen.apiFileFolder(), "/User/open.api.tools/source.folder/org/openapitools/codegen/api".replace('/', File.separatorChar));
}

@Test
public void apiTestFileFolder() {
final AbstractJavaCodegen codegen = new P_AbstractJavaCodegen();
codegen.setOutputDir("/User/open.api.tools");
codegen.setTestFolder("test.folder");
codegen.setApiPackage("org.openapitools.codegen.api");
Assert.assertEquals(codegen.apiTestFileFolder(), "/User/open.api.tools/test.folder/org/openapitools/codegen/api".replace('/', File.separatorChar));
}

@Test
public void modelTestFileFolder() {
final AbstractJavaCodegen codegen = new P_AbstractJavaCodegen();
codegen.setOutputDir("/User/open.api.tools");
codegen.setTestFolder("test.folder");
codegen.setModelPackage("org.openapitools.codegen.model");
Assert.assertEquals(codegen.modelTestFileFolder(), "/User/open.api.tools/test.folder/org/openapitools/codegen/model".replace('/', File.separatorChar));
}

@Test
public void modelFileFolder() {
final AbstractJavaCodegen codegen = new P_AbstractJavaCodegen();
codegen.setOutputDir("/User/open.api.tools");
codegen.setSourceFolder("source.folder");
codegen.setModelPackage("org.openapitools.codegen.model");
Assert.assertEquals(codegen.modelFileFolder(), "/User/open.api.tools/source.folder/org/openapitools/codegen/model".replace('/', File.separatorChar));
}

@Test
public void apiDocFileFolder() {
final AbstractJavaCodegen codegen = new P_AbstractJavaCodegen();
codegen.setOutputDir("/User/open.api.tools");
Assert.assertEquals(codegen.apiDocFileFolder(), "/User/open.api.tools/docs/".replace('/', File.separatorChar));
}

private static class P_AbstractJavaCodegen extends AbstractJavaCodegen {
@Override
public CodegenType getTag() {

0 comments on commit 4652023

Please sign in to comment.