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
This commit is contained in:
Akihito Nakano 2019-01-11 20:16:45 +09:00 committed by William Cheng
parent 00a9cfdbc9
commit 4652023b7c
2 changed files with 49 additions and 4 deletions

View File

@ -536,22 +536,22 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
@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

View File

@ -27,6 +27,8 @@ import org.openapitools.codegen.languages.AbstractJavaCodegen;
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 class AbstractJavaCodegenTest {
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() {