diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java index 7d20b31e8f..008bc03404 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java @@ -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 diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java index be90e87253..37a46f1abe 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java @@ -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() {