From 993a21ed5f0c768d6c54d68eafe0f222b67d35ed Mon Sep 17 00:00:00 2001 From: Jim Schubert Date: Thu, 12 May 2016 22:06:30 -0400 Subject: [PATCH] [csharp] Add interface for API config aspects This allows developers to gain access to each API's Configuration and GetBasePath without need for reflection. --- .../languages/CSharpClientCodegen.java | 2 ++ .../resources/csharp/IApiAccessor.mustache | 26 +++++++++++++++++++ .../src/main/resources/csharp/api.mustache | 2 +- 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 modules/swagger-codegen/src/main/resources/csharp/IApiAccessor.mustache diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java index 2fc8738f067..d9f9ff3a477 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java @@ -218,6 +218,8 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen { binRelativePath += "vendor"; additionalProperties.put("binRelativePath", binRelativePath); + supportingFiles.add(new SupportingFile("IApiAccessor.mustache", + clientPackageDir, "IApiAccessor.cs")); supportingFiles.add(new SupportingFile("Configuration.mustache", clientPackageDir, "Configuration.cs")); supportingFiles.add(new SupportingFile("ApiClient.mustache", diff --git a/modules/swagger-codegen/src/main/resources/csharp/IApiAccessor.mustache b/modules/swagger-codegen/src/main/resources/csharp/IApiAccessor.mustache new file mode 100644 index 00000000000..eecd5284493 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/csharp/IApiAccessor.mustache @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using RestSharp; + +namespace {{packageName}}.Client +{ + /// + /// Represents configuration aspects required to interact with the API endpoints. + /// + public interface IApiAccessor + { + /// + /// Gets or sets the configuration object + /// + /// An instance of the Configuration + Configuration Configuration {get; set;} + + /// + /// Gets the base path of the API client. + /// + /// The base path + String GetBasePath(); + } +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/csharp/api.mustache b/modules/swagger-codegen/src/main/resources/csharp/api.mustache index 9c0c08fe8ed..a96f4ced1ef 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/api.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/api.mustache @@ -13,7 +13,7 @@ namespace {{packageName}}.Api /// /// Represents a collection of functions to interact with the API endpoints /// - public interface I{{classname}} + public interface I{{classname}} : IApiAccessor { #region Synchronous Operations {{#operation}}