Update C# client structure using common standards

Aligns C# project outputs more with community accepted standards and
leverges Nuget for package management.

This also moves the generated C# sample code out of the test project's
Lib folder. The output structure here was causing some issues with
maintainability (e.g. had to update test project with generated code).

(see: https://gist.github.com/davidfowl/ed7564297c61fe9ab814)
Output for a project, IO.Swagger will now look like:

    .
    ├── IO.Swagger.sln
    ├── README.md
    ├── bin
    ├── build.bat
    ├── build.sh
    ├── docs
    ├── packages
    └── src
        ├── IO.Swagger
        │   └── packages.config
        └── IO.Swagger.Test
            └── packages.config

This is a change from the Java-like src/main/csharp/IO/Swagger/etc
structure and will be a breaking change for some.
This commit is contained in:
Jim Schubert
2016-04-26 22:37:40 -04:00
parent 07d2374320
commit 7b578a4c4e
97 changed files with 1086 additions and 905 deletions

View File

@@ -21,7 +21,12 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
protected String packageVersion = "1.0.0";
protected String packageName = "IO.Swagger";
protected String sourceFolder = "src" + File.separator + packageName;
protected String sourceFolder = "src";
// TODO: Add option for test folder output location. Nice to allow e.g. ./test instead of ./src.
// This would require updating relative paths (e.g. path to main project file in test project file)
protected String testFolder = sourceFolder;
protected Set<String> collectionTypes;
protected Set<String> mapTypes;
@@ -277,12 +282,12 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
@Override
public String apiFileFolder() {
return outputFolder + File.separator + sourceFolder + File.separator + apiPackage().replace('.', File.separatorChar);
return outputFolder + File.separator + sourceFolder + File.separator + packageName + File.separator + apiPackage();
}
@Override
public String modelFileFolder() {
return outputFolder + File.separator + sourceFolder + File.separator + modelPackage().replace('.', File.separatorChar);
return outputFolder + File.separator + sourceFolder + File.separator + packageName + File.separator + modelPackage();
}
@Override
@@ -532,7 +537,6 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
return toModelName(name) + "Tests";
}
public void setPackageName(String packageName) {
this.packageName = packageName;
}
@@ -544,4 +548,8 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
public void setSourceFolder(String sourceFolder) {
this.sourceFolder = sourceFolder;
}
public String testPackageName() {
return this.packageName + ".Test";
}
}

View File

@@ -68,9 +68,6 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
modelDocTemplateFiles.put("model_doc.mustache", ".md");
apiDocTemplateFiles.put("api_doc.mustache", ".md");
// C# client default
setSourceFolder("src" + File.separator + "main" + File.separator + "csharp");
cliOptions.clear();
// CLI options
@@ -141,9 +138,9 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
public void processOpts() {
super.processOpts();
apiPackage = packageName + ".Api";
modelPackage = packageName + ".Model";
clientPackage = packageName + ".Client";
apiPackage = "Api";
modelPackage = "Model";
clientPackage = "Client";
additionalProperties.put("clientPackage", clientPackage);
@@ -157,6 +154,10 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
if (additionalProperties.containsKey(CodegenConstants.DOTNET_FRAMEWORK)) {
setTargetFramework((String) additionalProperties.get(CodegenConstants.DOTNET_FRAMEWORK));
} else {
// Ensure default is set.
setTargetFramework(NET45);
additionalProperties.put("targetFramework", this.targetFramework);
}
if (NET35.equals(this.targetFramework)) {
@@ -201,8 +202,12 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
.get(CodegenConstants.OPTIONAL_ASSEMBLY_INFO).toString()));
}
String packageFolder = sourceFolder + File.separator + packageName.replace(".", java.io.File.separator);
String clientPackageDir = sourceFolder + File.separator + clientPackage.replace(".", java.io.File.separator);
final String testPackageName = testPackageName();
String packageFolder = sourceFolder + File.separator + packageName;
String clientPackageDir = packageFolder + File.separator + clientPackage;
String testPackageFolder = testFolder + File.separator + testPackageName;
additionalProperties.put("testPackageName", testPackageName);
//Compute the relative path to the bin directory where the external assemblies live
//This is necessary to properly generate the project file
@@ -210,7 +215,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
String binRelativePath = "..\\";
for (int i = 0; i < packageDepth; i = i + 1)
binRelativePath += "..\\";
binRelativePath += "vendor\\";
binRelativePath += "vendor";
additionalProperties.put("binRelativePath", binRelativePath);
supportingFiles.add(new SupportingFile("Configuration.mustache",
@@ -222,9 +227,13 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
supportingFiles.add(new SupportingFile("ApiResponse.mustache",
clientPackageDir, "ApiResponse.cs"));
supportingFiles.add(new SupportingFile("compile.mustache", "", "compile.bat"));
supportingFiles.add(new SupportingFile("compile-mono.sh.mustache", "", "compile-mono.sh"));
supportingFiles.add(new SupportingFile("packages.config.mustache", "vendor" + java.io.File.separator, "packages.config"));
supportingFiles.add(new SupportingFile("compile.mustache", "", "build.bat"));
supportingFiles.add(new SupportingFile("compile-mono.sh.mustache", "", "build.sh"));
// copy package.config to nuget's standard location for project-level installs
supportingFiles.add(new SupportingFile("packages.config.mustache", packageFolder + File.separator, "packages.config"));
supportingFiles.add(new SupportingFile("packages_test.config.mustache", testPackageFolder + File.separator, "packages.config"));
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
@@ -233,7 +242,14 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
supportingFiles.add(new SupportingFile("AssemblyInfo.mustache", packageFolder + File.separator + "Properties", "AssemblyInfo.cs"));
}
if (optionalProjectFileFlag) {
supportingFiles.add(new SupportingFile("Project.mustache", packageFolder, clientPackage + ".csproj"));
supportingFiles.add(new SupportingFile("Solution.mustache", "", packageName + ".sln"));
supportingFiles.add(new SupportingFile("Project.mustache", packageFolder, packageName + ".csproj"));
// TODO: Check if test project output is enabled, partially related to #2506. Should have options for:
// 1) No test project
// 2) No model tests
// 3) No api tests
supportingFiles.add(new SupportingFile("TestProject.mustache", testPackageFolder, testPackageName + ".csproj"));
}
additionalProperties.put("apiDocPath", apiDocPath);
@@ -491,4 +507,13 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
return (outputFolder + "/" + modelDocPath).replace('/', File.separatorChar);
}
@Override
public String apiTestFileFolder() {
return outputFolder + File.separator + testFolder + File.separator + testPackageName() + File.separator + apiPackage();
}
@Override
public String modelTestFileFolder() {
return outputFolder + File.separator + testFolder + File.separator + testPackageName() + File.separator + modelPackage();
}
}