mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-04 06:30:52 +00:00
add cli support to csharp
This commit is contained in:
parent
6ad3a717fe
commit
df72188bc0
@ -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
|
||||||
|
@ -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>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace {{invokerPackage}} {
|
namespace {{packageName}}.Client {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// API Exception
|
/// API Exception
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -4,9 +4,8 @@ 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>
|
||||||
|
@ -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}} {
|
||||||
|
@ -7,7 +7,7 @@ using Newtonsoft.Json;
|
|||||||
|
|
||||||
{{#models}}
|
{{#models}}
|
||||||
{{#model}}
|
{{#model}}
|
||||||
namespace {{package}} {
|
namespace {{packageName}}.Model {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// {{description}}
|
/// {{description}}
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user