Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All above changes are minor cleanup. The assertions weren't in (actual, expected) format, which could lead to confusion on build failures.

}

@Test
Expand Down Expand Up @@ -602,6 +602,20 @@ public void maplikeDefaultValueForModelWithStringToModelMapping() {
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"))
Expand Down