Swagger Editor C# client with duplicate parameters in constructor
Hi all,
I tried generating a C# client with the Swagger Editor based on the json of my API.
In which the constructor of one of the classes gets duplicate parameters.
Resulting in following errors:
Ambiguity between 'List<OrderStatus>' and 'List<OrderStatus>' SetOrderStatusAction.cs 51
Ambiguity between 'string' and 'string' SetOrderStatusAction.cs 43
Ambiguity between 'string' and 'string' SetOrderStatusAction.cs 49
The parameter name 'status' is a duplicate SetOrderStatusAction.cs 40
The parameter name 'type' is a duplicate SetOrderStatusAction.cs 40
There has to be something that triggers the Swagger Editor to behave this way.
Does anyone know what could cause this? I have added some snippets below.
Thanks in advance.
Part of the json of the API describing two classes:
"OrderUpdateAction": {
"required": [
"$type"
],
"type": "object",
"properties": {
"action": {
"type": "string",
"nullable": true
},
"$type": {
"type": "string",
"default": "XXX.Applications.OrderService.Dto.UpdateAction.OrderUpdateAction"
}
},
"additionalProperties": false,
"discriminator": {
"propertyName": "$type"
}
},
"SetOrderStatusAction": {
"required": [
"$type"
],
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/OrderUpdateAction"
},
{
"required": [
"$type"
],
"type": "object",
"properties": {
"status": {
"type": "array",
"items": {
"$ref": "#/components/schemas/OrderStatus"
},
"nullable": true
},
"action": {
"type": "string",
"nullable": true
}
}
}
],
"properties": {
"$type": {
"type": "string",
"default": "XXX.Applications.OrderService.Dto.UpdateAction.SetOrderStatusAction"
}
},
"additionalProperties": false,
"discriminator": {
"propertyName": "$type"
},
"x-ms-discriminator-value": "XXX.Applications.OrderService.Dto.UpdateAction.SetOrderStatusAction, XXX.Applications.OrderService"
},
The generated class in the client:
/*
* My API
*
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* OpenAPI spec version: v1
*
* Generated by: https://github.com/swagger-api/swagger-codegen.git
*/
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using JsonSubTypes;
using System.ComponentModel.DataAnnotations;
using SwaggerDateConverter = IO.Swagger.Client.SwaggerDateConverter;
namespace IO.Swagger.Model
{
/// <summary>
/// SetOrderStatusAction
/// </summary>
[DataContract]
[JsonConverter(typeof(JsonSubtypes), "Type")]
public partial class SetOrderStatusAction : OrderUpdateAction, IEquatable<SetOrderStatusAction>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="SetOrderStatusAction" /> class.
/// </summary>
/// <param name="status">status.</param>
/// <param name="action">action.</param>
/// <param name="type">type (required) (default to "XXX.Applications.OrderService.Dto.UpdateAction.SetOrderStatusAction").</param>
public SetOrderStatusAction(List<OrderStatus> status = default(List<OrderStatus>), string action = default(string), string type = "XXX.Applications.OrderService.Dto.UpdateAction.SetOrderStatusAction", string type = "XXX.Applications.OrderService.Dto.UpdateAction.SetOrderStatusAction", List<OrderStatus> status = default(List<OrderStatus>)) : base()
{
// to ensure "type" is required (not null)
if (type == null)
{
throw new InvalidDataException("type is a required property for SetOrderStatusAction and cannot be null");
}
else
{
this.Type = type;
}
this.Status = status;
this.Action = action;
}
/// <summary>
/// Gets or Sets Status
/// </summary>
[DataMember(Name="status", EmitDefaultValue=false)]
public List<OrderStatus> Status { get; set; }
/// <summary>
/// Gets or Sets Action
/// </summary>
[DataMember(Name="action", EmitDefaultValue=false)]
public string Action { get; set; }
/// <summary>
/// Gets or Sets Type
/// </summary>
[DataMember(Name="$type", EmitDefaultValue=false)]
public string Type { 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 SetOrderStatusAction {\n");
sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n");
sb.Append(" Status: ").Append(Status).Append("\n");
sb.Append(" Action: ").Append(Action).Append("\n");
sb.Append(" Type: ").Append(Type).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 override string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
}
/// <summary>
/// Returns true if objects are equal
/// </summary>
/// <param name="input">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object input)
{
return this.Equals(input as SetOrderStatusAction);
}
/// <summary>
/// Returns true if SetOrderStatusAction instances are equal
/// </summary>
/// <param name="input">Instance of SetOrderStatusAction to be compared</param>
/// <returns>Boolean</returns>
public bool Equals(SetOrderStatusAction input)
{
if (input == null)
return false;
return base.Equals(input) &&
(
this.Status == input.Status ||
this.Status != null &&
input.Status != null &&
this.Status.SequenceEqual(input.Status)
) && base.Equals(input) &&
(
this.Action == input.Action ||
(this.Action != null &&
this.Action.Equals(input.Action))
) && base.Equals(input) &&
(
this.Type == input.Type ||
(this.Type != null &&
this.Type.Equals(input.Type))
);
}
/// <summary>
/// Gets the hash code
/// </summary>
/// <returns>Hash code</returns>
public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
int hashCode = base.GetHashCode();
if (this.Status != null)
hashCode = hashCode * 59 + this.Status.GetHashCode();
if (this.Action != null)
hashCode = hashCode * 59 + this.Action.GetHashCode();
if (this.Type != null)
hashCode = hashCode * 59 + this.Type.GetHashCode();
return hashCode;
}
}
/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
return this.BaseValidate(validationContext);
}
/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
{
foreach(var x in BaseValidate(validationContext)) yield return x;
yield break;
}
}
}
The original class in the API:
namespace XXX.Applications.OrderService.Dto.UpdateAction
{
using System.Collections.Generic;
public class SetOrderStatusAction : OrderUpdateAction
{
public IEnumerable<OrderStatus> Status { get; set; }
}
}
Perhaps useful is the inherited OrderUpdateAction class in the API:
namespace XXX.Applications.OrderService.Dto.UpdateAction
{
public class OrderUpdateAction
{
public string Action { get; set; }
}
}