Merge branch 'csharp_add_cli_support' of ssh://github.com/wing328/swagger-codegen into wing328-csharp_add_cli_support

This commit is contained in:
Tony Tam 2015-06-25 11:54:30 -07:00
commit 31efefe0b9
13 changed files with 67 additions and 43 deletions

View File

@ -7,6 +7,7 @@ import io.swagger.codegen.SupportingFile;
import io.swagger.models.properties.ArrayProperty; import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.MapProperty; import io.swagger.models.properties.MapProperty;
import io.swagger.models.properties.Property; import io.swagger.models.properties.Property;
import io.swagger.codegen.CliOption;
import java.io.File; import java.io.File;
import java.util.Arrays; import java.util.Arrays;
@ -14,15 +15,14 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig { public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig {
protected String invokerPackage = "IO.Swagger.Client"; protected String packageName = "IO.Swagger";
protected String groupId = "io.swagger"; protected String packageVersion = "1.0.0";
protected String artifactId = "swagger-csharp-client"; protected String clientPackage = "IO.Swagger.Client";
protected String artifactVersion = "1.0.0"; protected String sourceFolder = "src" + File.separator + "main" + File.separator + "csharp";
protected String sourceFolder = "src/main/csharp";
public CSharpClientCodegen() { public CSharpClientCodegen() {
super(); super();
outputFolder = "generated-code/csharp"; outputFolder = "generated-code" + File.separator + "csharp";
modelTemplateFiles.put("model.mustache", ".cs"); modelTemplateFiles.put("model.mustache", ".cs");
apiTemplateFiles.put("api.mustache", ".cs"); apiTemplateFiles.put("api.mustache", ".cs");
templateDir = "csharp"; templateDir = "csharp";
@ -34,17 +34,6 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
"abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char", "checked", "class", "const", "continue", "decimal", "default", "delegate", "do", "double", "else", "enum", "event", "explicit", "extern", "false", "finally", "fixed", "float", "for", "foreach", "goto", "if", "implicit", "in", "int", "interface", "internal", "is", "lock", "long", "namespace", "new", "null", "object", "operator", "out", "override", "params", "private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed", "short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using", "virtual", "void", "volatile", "while") "abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char", "checked", "class", "const", "continue", "decimal", "default", "delegate", "do", "double", "else", "enum", "event", "explicit", "extern", "false", "finally", "fixed", "float", "for", "foreach", "goto", "if", "implicit", "in", "int", "interface", "internal", "is", "lock", "long", "namespace", "new", "null", "object", "operator", "out", "override", "params", "private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed", "short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using", "virtual", "void", "volatile", "while")
); );
additionalProperties.put("invokerPackage", invokerPackage);
supportingFiles.add(new SupportingFile("Configuration.mustache",
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "Configuration.cs"));
supportingFiles.add(new SupportingFile("ApiClient.mustache",
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "ApiClient.cs"));
supportingFiles.add(new SupportingFile("ApiException.mustache",
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "ApiException.cs"));
supportingFiles.add(new SupportingFile("Newtonsoft.Json.dll", "bin", "Newtonsoft.Json.dll"));
supportingFiles.add(new SupportingFile("RestSharp.dll", "bin", "RestSharp.dll"));
supportingFiles.add(new SupportingFile("compile.mustache", "", "compile.bat"));
languageSpecificPrimitives = new HashSet<String>( languageSpecificPrimitives = new HashSet<String>(
Arrays.asList( Arrays.asList(
@ -85,6 +74,43 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
typeMapping.put("map", "Dictionary"); typeMapping.put("map", "Dictionary");
typeMapping.put("object", "Object"); typeMapping.put("object", "Object");
cliOptions.clear();
cliOptions.add(new CliOption("packageName", "C# package name (convention: Camel.Case), default: IO.Swagger"));
cliOptions.add(new CliOption("packageVersion", "C# package version, default: 1.0.0"));
}
@Override
public void processOpts() {
super.processOpts();
if (additionalProperties.containsKey("packageVersion")) {
packageVersion = (String) additionalProperties.get("packageVersion");
} else {
additionalProperties.put("packageVersion", packageVersion);
}
if (additionalProperties.containsKey("packageName")) {
packageName = (String) additionalProperties.get("packageName");
apiPackage = packageName + ".Api";
modelPackage = packageName + ".Model";
clientPackage = packageName + ".Client";
} else {
additionalProperties.put("packageName", packageName);
}
additionalProperties.put("clientPackage", clientPackage);
supportingFiles.add(new SupportingFile("Configuration.mustache",
(sourceFolder + File.separator + clientPackage).replace(".", java.io.File.separator), "Configuration.cs"));
supportingFiles.add(new SupportingFile("ApiClient.mustache",
(sourceFolder + File.separator + clientPackage).replace(".", java.io.File.separator), "ApiClient.cs"));
supportingFiles.add(new SupportingFile("ApiException.mustache",
(sourceFolder + File.separator + clientPackage).replace(".", java.io.File.separator), "ApiException.cs"));
supportingFiles.add(new SupportingFile("Newtonsoft.Json.dll", "bin", "Newtonsoft.Json.dll"));
supportingFiles.add(new SupportingFile("RestSharp.dll", "bin", "RestSharp.dll"));
supportingFiles.add(new SupportingFile("compile.mustache", "", "compile.bat"));
} }
public CodegenType getTag() { public CodegenType getTag() {
@ -106,11 +132,11 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
@Override @Override
public String apiFileFolder() { public String apiFileFolder() {
return (outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', '/')).replace('.', File.separatorChar); return (outputFolder + File.separator + sourceFolder + File.separator + apiPackage()).replace('.', File.separatorChar);
} }
public String modelFileFolder() { public String modelFileFolder() {
return (outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', '/')).replace('.', File.separatorChar); return (outputFolder + File.separator + sourceFolder + File.separator + modelPackage()).replace('.', File.separatorChar);
} }
@Override @Override

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
using Newtonsoft.Json; using Newtonsoft.Json;
using RestSharp; using RestSharp;
namespace {{invokerPackage}} { namespace {{packageName}}.Client {
/// <summary> /// <summary>
/// API client is mainly responible for making the HTTP call to the API backend /// API client is mainly responible for making the HTTP call to the API backend
/// </summary> /// </summary>

View File

@ -1,6 +1,6 @@
using System; using System;
namespace {{invokerPackage}} { namespace {{packageName}}.Client {
/// <summary> /// <summary>
/// API Exception /// API Exception
/// </summary> /// </summary>

View File

@ -4,14 +4,18 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Text; using System.Text;
using {{invokerPackage}};
namespace {{invokerPackage}} { namespace {{packageName}}.Client {
/// <summary> /// <summary>
/// Represents a set of configuration settings /// Represents a set of configuration settings
/// </summary> /// </summary>
public class Configuration{ public class Configuration{
/// <summary>
/// Version of the package
/// </summary>
public const string Version = "{{packageVersion}}";
/// <summary> /// <summary>
/// Gets or sets the API client. This is the default API client for making HTTP calls. /// Gets or sets the API client. This is the default API client for making HTTP calls.
/// </summary> /// </summary>

View File

@ -2,12 +2,12 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using RestSharp; using RestSharp;
using {{invokerPackage}}; using {{packageName}}.Client;
using {{modelPackage}}; using {{packageName}}.Model;
{{#imports}} {{#imports}}
{{/imports}} {{/imports}}
namespace {{package}} { namespace {{packageName}}.Api {
{{#operations}} {{#operations}}
public interface I{{classname}} { public interface I{{classname}} {

View File

@ -7,13 +7,13 @@ using Newtonsoft.Json;
{{#models}} {{#models}}
{{#model}} {{#model}}
namespace {{package}} { namespace {{packageName}}.Model {
/// <summary> /// <summary>
/// {{description}} /// {{description}}
/// </summary> /// </summary>
[DataContract] [DataContract]
public class {{classname}} { public class {{classname}}{{#parent}} : {{{parent}}}{{/parent}} {
{{#vars}} {{#vars}}
{{#description}}/* {{{description}}} */{{/description}} {{#description}}/* {{{description}}} */{{/description}}
[DataMember(Name="{{baseName}}", EmitDefaultValue=false)] [DataMember(Name="{{baseName}}", EmitDefaultValue=false)]
@ -39,11 +39,11 @@ namespace {{package}} {
/// Get the JSON string presentation of the object /// Get the JSON string presentation of the object
/// </summary> /// </summary>
/// <returns>JSON string presentation of the object</returns> /// <returns>JSON string presentation of the object</returns>
public string ToJson() { public {{#parent}} new {{/parent}}string ToJson() {
return JsonConvert.SerializeObject(this, Formatting.Indented); return JsonConvert.SerializeObject(this, Formatting.Indented);
} }
} }
{{/model}} {{/model}}
{{/models}} {{/models}}
} }

View File

@ -1,3 +1,3 @@
SET CSCPATH=%SYSTEMROOT%\Microsoft.NET\Framework\v4.0.30319 SET CSCPATH=%SYSTEMROOT%\Microsoft.NET\Framework\v4.0.30319
%CSCPATH%\csc /reference:bin/Newtonsoft.Json.dll;bin/RestSharp.dll /target:library /out:bin/IO.Swagger.Client.dll /recurse:src\*.cs /doc:bin/IO.Swagger.Client.xml %CSCPATH%\csc /reference:bin/Newtonsoft.Json.dll;bin/RestSharp.dll /target:library /out:bin/.dll /recurse:src\*.cs /doc:bin/.xml

View File

@ -4,7 +4,6 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Text; using System.Text;
using IO.Swagger.Client;
namespace IO.Swagger.Client { namespace IO.Swagger.Client {
/// <summary> /// <summary>
@ -12,6 +11,11 @@ namespace IO.Swagger.Client {
/// </summary> /// </summary>
public class Configuration{ public class Configuration{
/// <summary>
/// Version of the package
/// </summary>
public const string Version = "1.0.0";
/// <summary> /// <summary>
/// Gets or sets the API client. This is the default API client for making HTTP calls. /// Gets or sets the API client. This is the default API client for making HTTP calls.
/// </summary> /// </summary>

View File

@ -77,6 +77,4 @@ namespace IO.Swagger.Model {
} }
} }
} }

View File

@ -77,6 +77,4 @@ namespace IO.Swagger.Model {
} }
} }
} }

View File

@ -49,6 +49,4 @@ namespace IO.Swagger.Model {
} }
} }
} }

View File

@ -91,6 +91,4 @@ namespace IO.Swagger.Model {
} }
} }
} }