[java][groovy] Fix mangled src paths in outputs on Windows (#7487)

This commit is contained in:
Jim Schubert 2020-09-23 00:03:37 -04:00 committed by GitHub
parent d2aabc5f80
commit 1716ee3154
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 10 deletions

View File

@ -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.

View File

@ -60,7 +60,8 @@ public class GroovyClientCodegen extends AbstractJavaCodegen {
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");

View File

@ -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 class AbstractJavaCodegenTest {
Assert.assertEquals(defaultValue, "new HashMap<String, ComplexModel>()", "Expected string-ref map aliased model to default to new HashMap<String, ComplexModel>()");
}
@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"))