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 fa2dc09669df..872d954d3fa7 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 @@ -85,7 +85,8 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code protected String licenseUrl = "http://unlicense.org"; protected String projectFolder = "src/main"; protected String projectTestFolder = "src/test"; - protected String sourceFolder = projectFolder + File.separator + "java"; + // this must not be OS-specific + protected String sourceFolder = projectFolder + "/java"; protected String testFolder = projectTestFolder + "/java"; protected boolean fullJavaUtil; protected boolean discriminatorCaseSensitive = true; // True if the discriminator value lookup should be case-sensitive. diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GroovyClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GroovyClientCodegen.java index 95b11793cdf5..c512607cf7db 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GroovyClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GroovyClientCodegen.java @@ -60,7 +60,8 @@ public GroovyClientCodegen() { languageSpecificPrimitives.add("File"); languageSpecificPrimitives.add("Map"); - sourceFolder = projectFolder + File.separator +"groovy"; + // this must not be OS-specific + sourceFolder = projectFolder + "/groovy"; outputFolder = "generated-code/groovy"; modelTemplateFiles.put("model.mustache", ".groovy"); apiTemplateFiles.put("api.mustache", ".groovy"); 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 6ba9e4b67f83..800eb90a3ee0 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 @@ -42,27 +42,27 @@ public class AbstractJavaCodegenTest { @Test public void toEnumVarNameShouldNotShortenUnderScore() throws Exception { - Assert.assertEquals("UNDERSCORE", fakeJavaCodegen.toEnumVarName("_", "String")); - Assert.assertEquals("__", fakeJavaCodegen.toEnumVarName("__", "String")); - Assert.assertEquals("__", fakeJavaCodegen.toEnumVarName("_,.", "String")); + Assert.assertEquals(fakeJavaCodegen.toEnumVarName("_", "String"), "UNDERSCORE"); + Assert.assertEquals(fakeJavaCodegen.toEnumVarName("__", "String"), "__"); + Assert.assertEquals(fakeJavaCodegen.toEnumVarName("_,.", "String"), "__"); } @Test public void toVarNameShouldAvoidOverloadingGetClassMethod() throws Exception { - Assert.assertEquals("propertyClass", fakeJavaCodegen.toVarName("class")); - Assert.assertEquals("propertyClass", fakeJavaCodegen.toVarName("_class")); - Assert.assertEquals("propertyClass", fakeJavaCodegen.toVarName("__class")); + Assert.assertEquals(fakeJavaCodegen.toVarName("class"), "propertyClass"); + Assert.assertEquals(fakeJavaCodegen.toVarName("_class"), "propertyClass"); + Assert.assertEquals(fakeJavaCodegen.toVarName("__class"), "propertyClass"); } @Test public void toModelNameShouldUseProvidedMapping() throws Exception { fakeJavaCodegen.importMapping().put("json_myclass", "com.test.MyClass"); - Assert.assertEquals("com.test.MyClass", fakeJavaCodegen.toModelName("json_myclass")); + Assert.assertEquals(fakeJavaCodegen.toModelName("json_myclass"), "com.test.MyClass"); } @Test public void toModelNameUsesPascalCase() throws Exception { - Assert.assertEquals("JsonAnotherclass", fakeJavaCodegen.toModelName("json_anotherclass")); + Assert.assertEquals(fakeJavaCodegen.toModelName("json_anotherclass"), "JsonAnotherclass"); } @Test @@ -602,6 +602,20 @@ public void maplikeDefaultValueForModelWithStringToModelMapping() { Assert.assertEquals(defaultValue, "new HashMap()", "Expected string-ref map aliased model to default to new HashMap()"); } + @Test + public void srcMainFolderShouldNotBeOperatingSystemSpecificPaths() { + // it's not responsibility of the generator to fix OS-specific paths. This is left to template manager. + // This path must be non-OS-specific for expectations in source outputs (e.g. gradle build files) + Assert.assertEquals(fakeJavaCodegen.getSourceFolder(), "src/main/java"); + } + + @Test + public void srcTestFolderShouldNotBeOperatingSystemSpecificPaths() { + // it's not responsibility of the generator to fix OS-specific paths. This is left to template manager. + // This path must be non-OS-specific for expectations in source outputs (e.g. gradle build files) + Assert.assertEquals(fakeJavaCodegen.getTestFolder(), "src/test/java"); + } + private static Schema createObjectSchemaWithMinItems() { return new ObjectSchema() .addProperties("id", new IntegerSchema().format("int32"))