diff --git a/conf/csharp/structure/SwaggerRuntime/Common/ApiBase.cs b/conf/csharp/structure/SwaggerRuntime/Common/ApiBase.cs index 163e702e313..86180355b41 100644 --- a/conf/csharp/structure/SwaggerRuntime/Common/ApiBase.cs +++ b/conf/csharp/structure/SwaggerRuntime/Common/ApiBase.cs @@ -12,151 +12,150 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -using System; -using System.Collections.Generic; -using System.IO; -using System.Net; -using System.Text; -using System.Web; -using Newtonsoft.Json; -using SwaggerRuntime.Exceptions; - -namespace SwaggerRuntime.Common -{ - public abstract class ApiBase - { - private readonly string _apiBaseUrl; - private readonly ISecurityHandler _securityHandler; - - protected ApiBase(string apiBaseUrl, ISecurityHandler securityHandler) - { - if (string.IsNullOrEmpty(apiBaseUrl)) - { - throw new ArgumentException("Argument can't be null nor empty.", "apiBaseUrl"); - } - - if (securityHandler == null) - { - throw new ArgumentNullException("securityHandler"); - } - - _apiBaseUrl = apiBaseUrl; - _securityHandler = securityHandler; - } - - protected string InvokeApi(string resourceUrl, string method, IDictionary queryParams, Object postData, IDictionary headerParams) - { - string absoluteResourceUrl = _apiBaseUrl + resourceUrl; - - if (queryParams.Count > 0) - { - bool isFirst = true; - - foreach (string queryParamName in queryParams.Keys) - { - absoluteResourceUrl += isFirst ? "?" : "&"; - isFirst = false; - - absoluteResourceUrl += queryParamName + "=" + EncodeUrl(queryParams[queryParamName]); - } - } - - var headers = new Dictionary(); - - _securityHandler.PopulateSecurityInfo(absoluteResourceUrl, headers); - - var request = (HttpWebRequest)WebRequest.Create(absoluteResourceUrl); - - request.Method = method; - - foreach (KeyValuePair headerKvp in headers) - { - request.Headers[headerKvp.Key] = headerKvp.Value; - } - - if (headerParams != null) - { - foreach (KeyValuePair headerKvp in headerParams) - { - request.Headers[headerKvp.Key] = headerKvp.Value; - } - } - - using (var response = (HttpWebResponse)request.GetResponse()) - using (Stream responseStream = response.GetResponseStream()) - { - if (responseStream == null) - { - throw new IOException("Couldn't get response stream."); - } - - if (response.StatusCode != HttpStatusCode.OK) - { - throw new ApiException((int)response.StatusCode); - } - - using (var sr = new StreamReader(responseStream)) - { - return sr.ReadToEnd(); - } - } - } - - protected T Deserialize(string response) - { - var jsonSerializer = new JsonSerializer(); - - using (var sr = new StringReader(response)) - using (var jtr = new JsonTextReader(sr)) - { - return jsonSerializer.Deserialize(jtr); - } - } - - protected string Serialize(object input) - { - var jsonSerializer = new JsonSerializer(); - var sb = new StringBuilder(); - - using (var sw = new StringWriter(sb)) - { - jsonSerializer.Serialize(sw, input); - } - - return sb.ToString(); - } - - protected string ToPathValue(string value) - { - return EncodeUrl(value ?? ""); - } - - protected string ToPathValue(IEnumerable objects) - { - StringBuilder outSb = new StringBuilder(); - - foreach (object obj in objects) - { - outSb.Append(obj.ToString()); - outSb.Append(","); - } - - string output = outSb.ToString(); - - if (output.IndexOf(",") != -1) - { - output = output.Substring(0, output.LastIndexOf(",")); - } - - return EncodeUrl(output); - } - - protected string EncodeUrl(string value) - { - // TODO IMM HI: do we need to replace: .replaceAll("\\+", "%20"); ???? - return HttpUtility.UrlEncode(value); - } - } -} + */ + +using System; +using System.Collections.Generic; +using System.IO; +using System.Net; +using System.Text; +using System.Web; +using Newtonsoft.Json; +using SwaggerRuntime.Exceptions; + +namespace SwaggerRuntime.Common +{ + public abstract class ApiBase + { + private readonly string _apiBaseUrl; + private readonly ISecurityHandler _securityHandler; + + protected ApiBase(string apiBaseUrl, ISecurityHandler securityHandler) + { + if (string.IsNullOrEmpty(apiBaseUrl)) + { + throw new ArgumentException("Argument can't be null nor empty.", "apiBaseUrl"); + } + + if (securityHandler == null) + { + throw new ArgumentNullException("securityHandler"); + } + + _apiBaseUrl = apiBaseUrl; + _securityHandler = securityHandler; + } + + protected string InvokeApi(string resourceUrl, string method, IDictionary queryParams, Object postData, IDictionary headerParams) + { + string absoluteResourceUrl = _apiBaseUrl + resourceUrl; + + if (queryParams.Count > 0) + { + bool isFirst = true; + + foreach (string queryParamName in queryParams.Keys) + { + absoluteResourceUrl += isFirst ? "?" : "&"; + isFirst = false; + + absoluteResourceUrl += queryParamName + "=" + EncodeUrl(queryParams[queryParamName]); + } + } + + var headers = new Dictionary(); + + _securityHandler.PopulateSecurityInfo(absoluteResourceUrl, headers); + + var request = (HttpWebRequest)WebRequest.Create(absoluteResourceUrl); + + request.Method = method; + + foreach (KeyValuePair headerKvp in headers) + { + request.Headers[headerKvp.Key] = headerKvp.Value; + } + + if (headerParams != null) + { + foreach (KeyValuePair headerKvp in headerParams) + { + request.Headers[headerKvp.Key] = headerKvp.Value; + } + } + + using (var response = (HttpWebResponse)request.GetResponse()) + using (Stream responseStream = response.GetResponseStream()) + { + if (responseStream == null) + { + throw new IOException("Couldn't get response stream."); + } + + if (response.StatusCode != HttpStatusCode.OK) + { + throw new ApiException((int)response.StatusCode); + } + + using (var sr = new StreamReader(responseStream)) + { + return sr.ReadToEnd(); + } + } + } + + protected T Deserialize(string response) + { + var jsonSerializer = new JsonSerializer(); + + using (var sr = new StringReader(response)) + using (var jtr = new JsonTextReader(sr)) + { + return jsonSerializer.Deserialize(jtr); + } + } + + protected string Serialize(object input) + { + var jsonSerializer = new JsonSerializer(); + var sb = new StringBuilder(); + + using (var sw = new StringWriter(sb)) + { + jsonSerializer.Serialize(sw, input); + } + + return sb.ToString(); + } + + protected string ToPathValue(string value) + { + return EncodeUrl(value ?? ""); + } + + protected string ToPathValue(IEnumerable objects) + { + StringBuilder outSb = new StringBuilder(); + + foreach (object obj in objects) + { + outSb.Append(obj.ToString()); + outSb.Append(","); + } + + string output = outSb.ToString(); + + if (output.IndexOf(",") != -1) + { + output = output.Substring(0, output.LastIndexOf(",")); + } + + return EncodeUrl(output); + } + + protected string EncodeUrl(string value) + { + return HttpUtility.UrlEncode(value); + } + } +} diff --git a/src/main/java/com/wordnik/swagger/codegen/config/csharp/CSharpDataTypeMappingProvider.java b/src/main/java/com/wordnik/swagger/codegen/config/csharp/CSharpDataTypeMappingProvider.java index ba240fd610b..cf9e7a4b759 100644 --- a/src/main/java/com/wordnik/swagger/codegen/config/csharp/CSharpDataTypeMappingProvider.java +++ b/src/main/java/com/wordnik/swagger/codegen/config/csharp/CSharpDataTypeMappingProvider.java @@ -34,7 +34,7 @@ public class CSharpDataTypeMappingProvider implements DataTypeMappingProvider { private static final Map _primitiveValueMap; private static final Map _primitiveObjectMap; - private NamingPolicyProvider _nameGenerator = new CamelCaseNamingPolicyProvider(); + private NamingPolicyProvider _nameGenerator = new CSharpNamingPolicyProvider(); static { _primitiveValueMap = new HashMap(); diff --git a/src/main/java/com/wordnik/swagger/codegen/config/csharp/CSharpNamingPolicyProvider.java b/src/main/java/com/wordnik/swagger/codegen/config/csharp/CSharpNamingPolicyProvider.java index 8e41578e547..a3d5c0c36c4 100644 --- a/src/main/java/com/wordnik/swagger/codegen/config/csharp/CSharpNamingPolicyProvider.java +++ b/src/main/java/com/wordnik/swagger/codegen/config/csharp/CSharpNamingPolicyProvider.java @@ -45,6 +45,10 @@ public class CSharpNamingPolicyProvider implements NamingPolicyProvider { @Override public String applyClassNamingPolicy(String input) { if (input != null && input.length() > 0) { + if ("string".equalsIgnoreCase(input)) { + return "string"; + } + String output = input.substring(0, 1).toUpperCase() + input.substring(1); // class name can't have . so if dot exists remove the same output = output.replace(".", "");