Skip to content

Commit

Permalink
Merge pull request #2310 from wing328/better_model_name2
Browse files Browse the repository at this point in the history
[C#][Perl][PHP] Better model name
  • Loading branch information
wing328 committed Mar 4, 2016
2 parents ecef1c6 + 8cf0fcf commit b73c368
Show file tree
Hide file tree
Showing 54 changed files with 2,554 additions and 397 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,22 @@ public String toParamName(String name) {

@Override
public String toModelName(String name) {
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.

// model name cannot use reserved keyword
if (isReservedWord(name)) {
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("object_" + name));
name = "object_" + name;
}

// add prefix/suffic to model name
name = modelNamePrefix + name + modelNameSuffix;
if (!StringUtils.isEmpty(modelNamePrefix)) {
name = modelNamePrefix + "_" + name;
}

if (!StringUtils.isEmpty(modelNameSuffix)) {
name = name + "_" + modelNameSuffix;
}

// camelize the model name
// phone_number => PhoneNumber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ public String toParamName(String name) {

@Override
public String toModelName(String name) {
// remove [
name = name.replaceAll("\\]", "");

// Note: backslash ("\\") is allowed for e.g. "\\DateTime"
name = name.replaceAll("[^\\w\\\\]+", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1352,19 +1352,19 @@ public ApiResponse< Pet > GetPetByIdWithHttpInfo (long? petId)



// authentication (api_key) required

if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key")))
{
localVarHeaderParams["api_key"] = Configuration.GetApiKeyWithPrefix("api_key");
}
// authentication (petstore_auth) required

// oauth required
if (!String.IsNullOrEmpty(Configuration.AccessToken))
{
localVarHeaderParams["Authorization"] = "Bearer " + Configuration.AccessToken;
}
// authentication (api_key) required

if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key")))
{
localVarHeaderParams["api_key"] = Configuration.GetApiKeyWithPrefix("api_key");
}


// make the HTTP request
Expand Down Expand Up @@ -1445,19 +1445,19 @@ public async System.Threading.Tasks.Task<ApiResponse<Pet>> GetPetByIdAsyncWithHt



// authentication (petstore_auth) required
// authentication (api_key) required

// oauth required
if (!String.IsNullOrEmpty(Configuration.AccessToken))
if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key")))
{
localVarHeaderParams["Authorization"] = "Bearer " + Configuration.AccessToken;
localVarHeaderParams["api_key"] = Configuration.GetApiKeyWithPrefix("api_key");
}

// authentication (api_key) required
// authentication (petstore_auth) required

if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key")))
// oauth required
if (!String.IsNullOrEmpty(Configuration.AccessToken))
{
localVarHeaderParams["api_key"] = Configuration.GetApiKeyWithPrefix("api_key");
localVarHeaderParams["Authorization"] = "Bearer " + Configuration.AccessToken;
}


Expand Down Expand Up @@ -2267,19 +2267,19 @@ public ApiResponse< byte[] > PetPetIdtestingByteArraytrueGetWithHttpInfo (long?



// authentication (api_key) required

if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key")))
{
localVarHeaderParams["api_key"] = Configuration.GetApiKeyWithPrefix("api_key");
}
// authentication (petstore_auth) required

// oauth required
if (!String.IsNullOrEmpty(Configuration.AccessToken))
{
localVarHeaderParams["Authorization"] = "Bearer " + Configuration.AccessToken;
}
// authentication (api_key) required

if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key")))
{
localVarHeaderParams["api_key"] = Configuration.GetApiKeyWithPrefix("api_key");
}


// make the HTTP request
Expand Down Expand Up @@ -2360,19 +2360,19 @@ public async System.Threading.Tasks.Task<ApiResponse<byte[]>> PetPetIdtestingByt



// authentication (petstore_auth) required
// authentication (api_key) required

// oauth required
if (!String.IsNullOrEmpty(Configuration.AccessToken))
if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key")))
{
localVarHeaderParams["Authorization"] = "Bearer " + Configuration.AccessToken;
localVarHeaderParams["api_key"] = Configuration.GetApiKeyWithPrefix("api_key");
}

// authentication (api_key) required
// authentication (petstore_auth) required

if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key")))
// oauth required
if (!String.IsNullOrEmpty(Configuration.AccessToken))
{
localVarHeaderParams["api_key"] = Configuration.GetApiKeyWithPrefix("api_key");
localVarHeaderParams["Authorization"] = "Bearer " + Configuration.AccessToken;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1102,18 +1102,18 @@ public ApiResponse< Order > GetOrderByIdWithHttpInfo (string orderId)



// authentication (test_api_key_query) required

if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("test_api_key_query")))
{
localVarQueryParams["test_api_key_query"] = Configuration.GetApiKeyWithPrefix("test_api_key_query");
}
// authentication (test_api_key_header) required

if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("test_api_key_header")))
{
localVarHeaderParams["test_api_key_header"] = Configuration.GetApiKeyWithPrefix("test_api_key_header");
}
// authentication (test_api_key_query) required

if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("test_api_key_query")))
{
localVarQueryParams["test_api_key_query"] = Configuration.GetApiKeyWithPrefix("test_api_key_query");
}


// make the HTTP request
Expand Down Expand Up @@ -1194,18 +1194,18 @@ public async System.Threading.Tasks.Task<ApiResponse<Order>> GetOrderByIdAsyncWi



// authentication (test_api_key_query) required
// authentication (test_api_key_header) required

if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("test_api_key_query")))
if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("test_api_key_header")))
{
localVarQueryParams["test_api_key_query"] = Configuration.GetApiKeyWithPrefix("test_api_key_query");
localVarHeaderParams["test_api_key_header"] = Configuration.GetApiKeyWithPrefix("test_api_key_header");
}

// authentication (test_api_key_header) required
// authentication (test_api_key_query) required

if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("test_api_key_header")))
if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("test_api_key_query")))
{
localVarHeaderParams["test_api_key_header"] = Configuration.GetApiKeyWithPrefix("test_api_key_header");
localVarQueryParams["test_api_key_query"] = Configuration.GetApiKeyWithPrefix("test_api_key_query");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace IO.Swagger.Model
{

/// <summary>
///
/// </summary>
[DataContract]
public partial class InlineResponse200 : IEquatable<InlineResponse200>
{
{

/// <summary>
/// Initializes a new instance of the <see cref="InlineResponse200" /> class.
/// Initializes a new instance of the <see cref="InlineResponse200" />class.
/// </summary>
/// <param name="Id">Id (required).</param>
Expand All @@ -39,30 +41,26 @@ public InlineResponse200(long? Id = null, Object Category = null, string Name =
this.Name = Name;

}



/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
public long? Id { get; set; }



/// <summary>
/// Gets or Sets Category
/// </summary>
[DataMember(Name="category", EmitDefaultValue=false)]
public Object Category { get; set; }



/// <summary>
/// Gets or Sets Name
/// </summary>
[DataMember(Name="name", EmitDefaultValue=false)]
public string Name { get; set; }




/// <summary>
/// Returns the string presentation of the object
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace IO.Swagger.Model
{
/// <summary>
///
/// </summary>
[DataContract]
public partial class ObjectReturn : IEquatable<ObjectReturn>
{

/// <summary>
/// Initializes a new instance of the <see cref="ObjectReturn" /> class.
/// Initializes a new instance of the <see cref="ObjectReturn" />class.
/// </summary>
/// <param name="_Return">_Return.</param>

public ObjectReturn(int? _Return = null)
{
this._Return = _Return;

}


/// <summary>
/// Gets or Sets _Return
/// </summary>
[DataMember(Name="return", EmitDefaultValue=false)]
public int? _Return { get; set; }

/// <summary>
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString()
{
var sb = new StringBuilder();
sb.Append("class ObjectReturn {\n");
sb.Append(" _Return: ").Append(_Return).Append("\n");

sb.Append("}\n");
return sb.ToString();
}

/// <summary>
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
}

/// <summary>
/// Returns true if objects are equal
/// </summary>
/// <param name="obj">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object obj)
{
// credit: http://stackoverflow.com/a/10454552/677735
return this.Equals(obj as ObjectReturn);
}

/// <summary>
/// Returns true if ObjectReturn instances are equal
/// </summary>
/// <param name="other">Instance of ObjectReturn to be compared</param>
/// <returns>Boolean</returns>
public bool Equals(ObjectReturn other)
{
// credit: http://stackoverflow.com/a/10454552/677735
if (other == null)
return false;

return
(
this._Return == other._Return ||
this._Return != null &&
this._Return.Equals(other._Return)
);
}

/// <summary>
/// Gets the hash code
/// </summary>
/// <returns>Hash code</returns>
public override int GetHashCode()
{
// credit: http://stackoverflow.com/a/263416/677735
unchecked // Overflow is fine, just wrap
{
int hash = 41;
// Suitable nullity checks etc, of course :)

if (this._Return != null)
hash = hash * 59 + this._Return.GetHashCode();

return hash;
}
}

}
}
Loading

0 comments on commit b73c368

Please sign in to comment.