diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java index 0091204a0ab..a7045738cc3 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java @@ -32,6 +32,7 @@ public class CodegenProperty { public Boolean exclusiveMinimum; public Boolean exclusiveMaximum; public Boolean hasMore, required, secondaryParam; + public Boolean hasMoreNonReadOnly; // for model constructor, true if next properyt is not readonly public Boolean isPrimitiveType, isContainer, isNotContainer; public Boolean isString, isInteger, isLong, isFloat, isDouble, isByteArray, isBinary, isBoolean, isDate, isDateTime; public Boolean isListContainer, isMapContainer; @@ -63,6 +64,7 @@ public class CodegenProperty { result = prime * result + ((exclusiveMinimum == null) ? 0 : exclusiveMinimum.hashCode()); result = prime * result + ((getter == null) ? 0 : getter.hashCode()); result = prime * result + ((hasMore == null) ? 0 : hasMore.hashCode()); + result = prime * result + ((hasMoreNonReadOnly == null) ? 0 : hasMoreNonReadOnly.hashCode()); result = prime * result + ((isContainer == null) ? 0 : isContainer.hashCode()); result = prime * result + (isEnum ? 1231 : 1237); result = prime * result + ((isNotContainer == null) ? 0 : isNotContainer.hashCode()); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index b2a28287471..9cd719dbe87 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -2220,9 +2220,12 @@ public class DefaultCodegen { } private void addVars(CodegenModel m, List vars, Map properties, Set mandatory) { - final int totalCount = properties.size(); - int count = 0; - for (Map.Entry entry : properties.entrySet()) { + // convert set to list so that we can access the next entry in the loop + List> propertyList = new ArrayList>(properties.entrySet()); + final int totalCount = propertyList.size(); + for (int i = 0; i < totalCount; i++) { + Map.Entry entry = propertyList.get(i); + final String key = entry.getKey(); final Property prop = entry.getValue(); @@ -2236,13 +2239,19 @@ public class DefaultCodegen { // m.hasEnums to be set incorrectly if allProperties has enumerations but properties does not. m.hasEnums = true; } - count++; - if (count != totalCount) { + + if (i+1 != totalCount) { cp.hasMore = true; + // check the next entry to see if it's read only + if (!Boolean.TRUE.equals(propertyList.get(i+1).getValue().getReadOnly())) { + cp.hasMoreNonReadOnly = true; // next entry is not ready only + } } + if (cp.isContainer != null) { addImport(m, typeMapping.get("array")); } + addImport(m, cp.baseType); addImport(m, cp.complexType); vars.add(cp); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractCSharpCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractCSharpCodegen.java index db5847d9672..76c0d1277b1 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractCSharpCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractCSharpCodegen.java @@ -101,6 +101,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co typeMapping = new HashMap(); typeMapping.put("string", "string"); typeMapping.put("binary", "byte[]"); + typeMapping.put("bytearray", "byte[]"); typeMapping.put("boolean", "bool?"); typeMapping.put("integer", "int?"); typeMapping.put("float", "float?"); diff --git a/modules/swagger-codegen/src/main/resources/csharp/model.mustache b/modules/swagger-codegen/src/main/resources/csharp/model.mustache index 347834f329a..4f33807f978 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/model.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/model.mustache @@ -41,7 +41,7 @@ namespace {{packageName}}.Model /// {{#vars}}{{^isReadOnly}} /// {{#description}}{{description}}{{/description}}{{^description}}{{name}}{{/description}}{{#required}} (required){{/required}}{{#defaultValue}} (default to {{defaultValue}}){{/defaultValue}}. {{/isReadOnly}}{{/vars}} - public {{classname}}({{#vars}}{{^isReadOnly}}{{{datatypeWithEnum}}} {{name}} = null{{#hasMore}}, {{/hasMore}}{{/isReadOnly}}{{/vars}}) + public {{classname}}({{#vars}}{{^isReadOnly}}{{{datatypeWithEnum}}} {{name}} = null{{#hasMoreNonReadOnly}}, {{/hasMoreNonReadOnly}}{{/isReadOnly}}{{/vars}}) { {{#vars}}{{^isReadOnly}}{{#required}}// to ensure "{{name}}" is required (not null) if ({{name}} == null) diff --git a/modules/swagger-codegen/src/test/resources/2_0/petstore.json b/modules/swagger-codegen/src/test/resources/2_0/petstore.json index dfd7937242e..64b56377393 100644 --- a/modules/swagger-codegen/src/test/resources/2_0/petstore.json +++ b/modules/swagger-codegen/src/test/resources/2_0/petstore.json @@ -1314,12 +1314,16 @@ }, "Name": { "description": "Model for testing model name same as property name", + "required": [ + "name" + ], "properties": { "name": { "type": "integer", "format": "int32" }, "snake_case": { + "readOnly": true, "type": "integer", "format": "int32" } @@ -1375,6 +1379,59 @@ "type" : "string" } } + }, + "format_test" : { + "type" : "object", + "required": [ + "number" + ], + "properties" : { + "integer" : { + "type": "integer" + }, + "int32" : { + "type": "integer", + "format": "int32" + }, + "int64" : { + "type": "integer", + "format": "int64" + }, + "number" : { + "type": "number" + }, + "float" : { + "type": "number", + "format": "float" + }, + "double" : { + "type": "number", + "format": "double" + }, + "string" : { + "type": "string" + }, + "byte" : { + "type": "string", + "format": "byte" + }, + "binary" : { + "type": "string", + "format": "binary" + }, + "date" : { + "type": "string", + "format": "date" + }, + "dateTime" : { + "type": "string", + "format": "date-time" + }, + "dateTime" : { + "type": "string", + "format": "password" + } + } } } } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/FormatTest.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/FormatTest.cs new file mode 100644 index 00000000000..bfcd371a1df --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/FormatTest.cs @@ -0,0 +1,291 @@ +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 +{ + /// + /// + /// + [DataContract] + public partial class FormatTest : IEquatable + { + + /// + /// Initializes a new instance of the class. + /// Initializes a new instance of the class. + /// + /// Integer. + /// Int32. + /// Int64. + /// Number (required). + /// _Float. + /// _Double. + /// _String. + /// _Byte. + /// Binary. + /// Date. + /// DateTime. + + public FormatTest(int? Integer = null, int? Int32 = null, long? Int64 = null, double? Number = null, float? _Float = null, double? _Double = null, string _String = null, byte[] _Byte = null, byte[] Binary = null, DateTime? Date = null, string DateTime = null) + { + // to ensure "Number" is required (not null) + if (Number == null) + { + throw new InvalidDataException("Number is a required property for FormatTest and cannot be null"); + } + else + { + this.Number = Number; + } + this.Integer = Integer; + this.Int32 = Int32; + this.Int64 = Int64; + this._Float = _Float; + this._Double = _Double; + this._String = _String; + this._Byte = _Byte; + this.Binary = Binary; + this.Date = Date; + this.DateTime = DateTime; + + } + + + /// + /// Gets or Sets Integer + /// + [DataMember(Name="integer", EmitDefaultValue=false)] + public int? Integer { get; set; } + + /// + /// Gets or Sets Int32 + /// + [DataMember(Name="int32", EmitDefaultValue=false)] + public int? Int32 { get; set; } + + /// + /// Gets or Sets Int64 + /// + [DataMember(Name="int64", EmitDefaultValue=false)] + public long? Int64 { get; set; } + + /// + /// Gets or Sets Number + /// + [DataMember(Name="number", EmitDefaultValue=false)] + public double? Number { get; set; } + + /// + /// Gets or Sets _Float + /// + [DataMember(Name="float", EmitDefaultValue=false)] + public float? _Float { get; set; } + + /// + /// Gets or Sets _Double + /// + [DataMember(Name="double", EmitDefaultValue=false)] + public double? _Double { get; set; } + + /// + /// Gets or Sets _String + /// + [DataMember(Name="string", EmitDefaultValue=false)] + public string _String { get; set; } + + /// + /// Gets or Sets _Byte + /// + [DataMember(Name="byte", EmitDefaultValue=false)] + public byte[] _Byte { get; set; } + + /// + /// Gets or Sets Binary + /// + [DataMember(Name="binary", EmitDefaultValue=false)] + public byte[] Binary { get; set; } + + /// + /// Gets or Sets Date + /// + [DataMember(Name="date", EmitDefaultValue=false)] + public DateTime? Date { get; set; } + + /// + /// Gets or Sets DateTime + /// + [DataMember(Name="dateTime", EmitDefaultValue=false)] + public string DateTime { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class FormatTest {\n"); + sb.Append(" Integer: ").Append(Integer).Append("\n"); + sb.Append(" Int32: ").Append(Int32).Append("\n"); + sb.Append(" Int64: ").Append(Int64).Append("\n"); + sb.Append(" Number: ").Append(Number).Append("\n"); + sb.Append(" _Float: ").Append(_Float).Append("\n"); + sb.Append(" _Double: ").Append(_Double).Append("\n"); + sb.Append(" _String: ").Append(_String).Append("\n"); + sb.Append(" _Byte: ").Append(_Byte).Append("\n"); + sb.Append(" Binary: ").Append(Binary).Append("\n"); + sb.Append(" Date: ").Append(Date).Append("\n"); + sb.Append(" DateTime: ").Append(DateTime).Append("\n"); + + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + // credit: http://stackoverflow.com/a/10454552/677735 + return this.Equals(obj as FormatTest); + } + + /// + /// Returns true if FormatTest instances are equal + /// + /// Instance of FormatTest to be compared + /// Boolean + public bool Equals(FormatTest other) + { + // credit: http://stackoverflow.com/a/10454552/677735 + if (other == null) + return false; + + return + ( + this.Integer == other.Integer || + this.Integer != null && + this.Integer.Equals(other.Integer) + ) && + ( + this.Int32 == other.Int32 || + this.Int32 != null && + this.Int32.Equals(other.Int32) + ) && + ( + this.Int64 == other.Int64 || + this.Int64 != null && + this.Int64.Equals(other.Int64) + ) && + ( + this.Number == other.Number || + this.Number != null && + this.Number.Equals(other.Number) + ) && + ( + this._Float == other._Float || + this._Float != null && + this._Float.Equals(other._Float) + ) && + ( + this._Double == other._Double || + this._Double != null && + this._Double.Equals(other._Double) + ) && + ( + this._String == other._String || + this._String != null && + this._String.Equals(other._String) + ) && + ( + this._Byte == other._Byte || + this._Byte != null && + this._Byte.Equals(other._Byte) + ) && + ( + this.Binary == other.Binary || + this.Binary != null && + this.Binary.Equals(other.Binary) + ) && + ( + this.Date == other.Date || + this.Date != null && + this.Date.Equals(other.Date) + ) && + ( + this.DateTime == other.DateTime || + this.DateTime != null && + this.DateTime.Equals(other.DateTime) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + 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.Integer != null) + hash = hash * 59 + this.Integer.GetHashCode(); + + if (this.Int32 != null) + hash = hash * 59 + this.Int32.GetHashCode(); + + if (this.Int64 != null) + hash = hash * 59 + this.Int64.GetHashCode(); + + if (this.Number != null) + hash = hash * 59 + this.Number.GetHashCode(); + + if (this._Float != null) + hash = hash * 59 + this._Float.GetHashCode(); + + if (this._Double != null) + hash = hash * 59 + this._Double.GetHashCode(); + + if (this._String != null) + hash = hash * 59 + this._String.GetHashCode(); + + if (this._Byte != null) + hash = hash * 59 + this._Byte.GetHashCode(); + + if (this.Binary != null) + hash = hash * 59 + this.Binary.GetHashCode(); + + if (this.Date != null) + hash = hash * 59 + this.Date.GetHashCode(); + + if (this.DateTime != null) + hash = hash * 59 + this.DateTime.GetHashCode(); + + return hash; + } + } + + } +} diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Name.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Name.cs index 55fd01dfb97..6e5661e1d44 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Name.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Name.cs @@ -22,13 +22,19 @@ namespace IO.Swagger.Model /// Initializes a new instance of the class. /// Initializes a new instance of the class. /// - /// _Name. - /// SnakeCase. + /// _Name (required). - public Name(int? _Name = null, int? SnakeCase = null) + public Name(int? _Name = null) { - this._Name = _Name; - this.SnakeCase = SnakeCase; + // to ensure "_Name" is required (not null) + if (_Name == null) + { + throw new InvalidDataException("_Name is a required property for Name and cannot be null"); + } + else + { + this._Name = _Name; + } } @@ -43,7 +49,7 @@ namespace IO.Swagger.Model /// Gets or Sets SnakeCase /// [DataMember(Name="snake_case", EmitDefaultValue=false)] - public int? SnakeCase { get; set; } + public int? SnakeCase { get; private set; } /// /// Returns the string presentation of the object diff --git a/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.csproj b/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.csproj index 83c4f19ab17..67c8e73b6e5 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.csproj +++ b/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.csproj @@ -66,6 +66,10 @@ + + + + diff --git a/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs b/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs index c507559e57d..d261de4844c 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs +++ b/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs @@ -1,9 +1,11 @@  - + - + + +