Fix C# discriminator's mapping name (#1942)

* fix C# mapping name

* add back jsonsubtypes

* add new files
This commit is contained in:
William Cheng
2019-01-23 15:54:24 +08:00
committed by GitHub
parent af634c77c4
commit 3ea6cf356f
9 changed files with 684 additions and 3 deletions

View File

@@ -592,7 +592,7 @@ public class CSharpRefactorClientCodegen extends AbstractCSharpCodegen {
parentVar.isInherited = true;
parentVar.hasMore = true;
last = parentVar;
LOGGER.info("adding parent variable {}", property.name);
LOGGER.debug("adding parent variable {}", property.name);
codegenModel.parentVars.add(parentVar);
}
}

View File

@@ -3,8 +3,13 @@
/// </summary>
[DataContract]
{{#discriminator}}
[JsonConverter(typeof(JsonSubtypes), "{{{discriminatorName}}}")]{{#children}}
[JsonSubtypes.KnownSubType(typeof({{classname}}), "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}")]{{/children}}
[JsonConverter(typeof(JsonSubtypes), "{{{discriminatorName}}}")]
{{#children}}
[JsonSubtypes.KnownSubType(typeof({{classname}}), "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}")]
{{/children}}
{{#mappedModels}}
[JsonSubtypes.KnownSubType(typeof({{{modelName}}}), "{{{mappingName}}}")]
{{/mappedModels}}
{{/discriminator}}
{{#generatePropertyChanged}}
[ImplementPropertyChanged]

View File

@@ -169,6 +169,8 @@ Class | Method | HTTP request | Description
- [Model.Return](docs/Return.md)
- [Model.SpecialModelName](docs/SpecialModelName.md)
- [Model.Tag](docs/Tag.md)
- [Model.TypeHolderDefault](docs/TypeHolderDefault.md)
- [Model.TypeHolderExample](docs/TypeHolderExample.md)
- [Model.User](docs/User.md)

View File

@@ -0,0 +1,13 @@
# Org.OpenAPITools.Model.TypeHolderDefault
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**StringItem** | **string** | | [default to "what"]
**NumberItem** | **decimal** | |
**IntegerItem** | **int** | |
**BoolItem** | **bool** | | [default to true]
**ArrayItem** | **List&lt;int&gt;** | |
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@@ -0,0 +1,13 @@
# Org.OpenAPITools.Model.TypeHolderExample
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**StringItem** | **string** | |
**NumberItem** | **decimal** | |
**IntegerItem** | **int** | |
**BoolItem** | **bool** | |
**ArrayItem** | **List&lt;int&gt;** | |
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@@ -0,0 +1,112 @@
/*
* OpenAPI Petstore
*
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* OpenAPI spec version: 1.0.0
*
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
using NUnit.Framework;
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Model;
using Org.OpenAPITools.Client;
using System.Reflection;
using Newtonsoft.Json;
namespace Org.OpenAPITools.Test
{
/// <summary>
/// Class for testing TypeHolderDefault
/// </summary>
/// <remarks>
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
/// Please update the test case below to test the model.
/// </remarks>
[TestFixture]
public class TypeHolderDefaultTests
{
// TODO uncomment below to declare an instance variable for TypeHolderDefault
//private TypeHolderDefault instance;
/// <summary>
/// Setup before each test
/// </summary>
[SetUp]
public void Init()
{
// TODO uncomment below to create an instance of TypeHolderDefault
//instance = new TypeHolderDefault();
}
/// <summary>
/// Clean up after each test
/// </summary>
[TearDown]
public void Cleanup()
{
}
/// <summary>
/// Test an instance of TypeHolderDefault
/// </summary>
[Test]
public void TypeHolderDefaultInstanceTest()
{
// TODO uncomment below to test "IsInstanceOfType" TypeHolderDefault
//Assert.IsInstanceOfType<TypeHolderDefault> (instance, "variable 'instance' is a TypeHolderDefault");
}
/// <summary>
/// Test the property 'StringItem'
/// </summary>
[Test]
public void StringItemTest()
{
// TODO unit test for the property 'StringItem'
}
/// <summary>
/// Test the property 'NumberItem'
/// </summary>
[Test]
public void NumberItemTest()
{
// TODO unit test for the property 'NumberItem'
}
/// <summary>
/// Test the property 'IntegerItem'
/// </summary>
[Test]
public void IntegerItemTest()
{
// TODO unit test for the property 'IntegerItem'
}
/// <summary>
/// Test the property 'BoolItem'
/// </summary>
[Test]
public void BoolItemTest()
{
// TODO unit test for the property 'BoolItem'
}
/// <summary>
/// Test the property 'ArrayItem'
/// </summary>
[Test]
public void ArrayItemTest()
{
// TODO unit test for the property 'ArrayItem'
}
}
}

View File

@@ -0,0 +1,112 @@
/*
* OpenAPI Petstore
*
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* OpenAPI spec version: 1.0.0
*
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
using NUnit.Framework;
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Model;
using Org.OpenAPITools.Client;
using System.Reflection;
using Newtonsoft.Json;
namespace Org.OpenAPITools.Test
{
/// <summary>
/// Class for testing TypeHolderExample
/// </summary>
/// <remarks>
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
/// Please update the test case below to test the model.
/// </remarks>
[TestFixture]
public class TypeHolderExampleTests
{
// TODO uncomment below to declare an instance variable for TypeHolderExample
//private TypeHolderExample instance;
/// <summary>
/// Setup before each test
/// </summary>
[SetUp]
public void Init()
{
// TODO uncomment below to create an instance of TypeHolderExample
//instance = new TypeHolderExample();
}
/// <summary>
/// Clean up after each test
/// </summary>
[TearDown]
public void Cleanup()
{
}
/// <summary>
/// Test an instance of TypeHolderExample
/// </summary>
[Test]
public void TypeHolderExampleInstanceTest()
{
// TODO uncomment below to test "IsInstanceOfType" TypeHolderExample
//Assert.IsInstanceOfType<TypeHolderExample> (instance, "variable 'instance' is a TypeHolderExample");
}
/// <summary>
/// Test the property 'StringItem'
/// </summary>
[Test]
public void StringItemTest()
{
// TODO unit test for the property 'StringItem'
}
/// <summary>
/// Test the property 'NumberItem'
/// </summary>
[Test]
public void NumberItemTest()
{
// TODO unit test for the property 'NumberItem'
}
/// <summary>
/// Test the property 'IntegerItem'
/// </summary>
[Test]
public void IntegerItemTest()
{
// TODO unit test for the property 'IntegerItem'
}
/// <summary>
/// Test the property 'BoolItem'
/// </summary>
[Test]
public void BoolItemTest()
{
// TODO unit test for the property 'BoolItem'
}
/// <summary>
/// Test the property 'ArrayItem'
/// </summary>
[Test]
public void ArrayItemTest()
{
// TODO unit test for the property 'ArrayItem'
}
}
}

View File

@@ -0,0 +1,212 @@
/*
* OpenAPI Petstore
*
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* OpenAPI spec version: 1.0.0
*
* Generated by: https://github.com/openapitools/openapi-generator.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 System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// TypeHolderDefault
/// </summary>
[DataContract]
public partial class TypeHolderDefault : IEquatable<TypeHolderDefault>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="TypeHolderDefault" /> class.
/// </summary>
[JsonConstructorAttribute]
protected TypeHolderDefault() { }
/// <summary>
/// Initializes a new instance of the <see cref="TypeHolderDefault" /> class.
/// </summary>
/// <param name="stringItem">stringItem (required) (default to &quot;what&quot;).</param>
/// <param name="numberItem">numberItem (required).</param>
/// <param name="integerItem">integerItem (required).</param>
/// <param name="boolItem">boolItem (required) (default to true).</param>
/// <param name="arrayItem">arrayItem (required).</param>
public TypeHolderDefault(string stringItem = "what", decimal numberItem = default(decimal), int integerItem = default(int), bool boolItem = true, List<int> arrayItem = default(List<int>))
{
// to ensure "stringItem" is required (not null)
if (stringItem == null)
{
throw new InvalidDataException("stringItem is a required property for TypeHolderDefault and cannot be null");
}
else
{
this.StringItem = stringItem;
}
// to ensure "numberItem" is required (not null)
if (numberItem == null)
{
throw new InvalidDataException("numberItem is a required property for TypeHolderDefault and cannot be null");
}
else
{
this.NumberItem = numberItem;
}
// to ensure "integerItem" is required (not null)
if (integerItem == null)
{
throw new InvalidDataException("integerItem is a required property for TypeHolderDefault and cannot be null");
}
else
{
this.IntegerItem = integerItem;
}
// to ensure "boolItem" is required (not null)
if (boolItem == null)
{
throw new InvalidDataException("boolItem is a required property for TypeHolderDefault and cannot be null");
}
else
{
this.BoolItem = boolItem;
}
// to ensure "arrayItem" is required (not null)
if (arrayItem == null)
{
throw new InvalidDataException("arrayItem is a required property for TypeHolderDefault and cannot be null");
}
else
{
this.ArrayItem = arrayItem;
}
}
/// <summary>
/// Gets or Sets StringItem
/// </summary>
[DataMember(Name="string_item", EmitDefaultValue=false)]
public string StringItem { get; set; }
/// <summary>
/// Gets or Sets NumberItem
/// </summary>
[DataMember(Name="number_item", EmitDefaultValue=false)]
public decimal NumberItem { get; set; }
/// <summary>
/// Gets or Sets IntegerItem
/// </summary>
[DataMember(Name="integer_item", EmitDefaultValue=false)]
public int IntegerItem { get; set; }
/// <summary>
/// Gets or Sets BoolItem
/// </summary>
[DataMember(Name="bool_item", EmitDefaultValue=false)]
public bool BoolItem { get; set; }
/// <summary>
/// Gets or Sets ArrayItem
/// </summary>
[DataMember(Name="array_item", EmitDefaultValue=false)]
public List<int> ArrayItem { 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 TypeHolderDefault {\n");
sb.Append(" StringItem: ").Append(StringItem).Append("\n");
sb.Append(" NumberItem: ").Append(NumberItem).Append("\n");
sb.Append(" IntegerItem: ").Append(IntegerItem).Append("\n");
sb.Append(" BoolItem: ").Append(BoolItem).Append("\n");
sb.Append(" ArrayItem: ").Append(ArrayItem).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 virtual 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 OpenAPIClientUtils.compareLogic.Compare(this, input as TypeHolderDefault).AreEqual;
}
/// <summary>
/// Returns true if TypeHolderDefault instances are equal
/// </summary>
/// <param name="input">Instance of TypeHolderDefault to be compared</param>
/// <returns>Boolean</returns>
public bool Equals(TypeHolderDefault input)
{
return OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual;
}
/// <summary>
/// Gets the hash code
/// </summary>
/// <returns>Hash code</returns>
public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
if (this.StringItem != null)
hashCode = hashCode * 59 + this.StringItem.GetHashCode();
if (this.NumberItem != null)
hashCode = hashCode * 59 + this.NumberItem.GetHashCode();
if (this.IntegerItem != null)
hashCode = hashCode * 59 + this.IntegerItem.GetHashCode();
if (this.BoolItem != null)
hashCode = hashCode * 59 + this.BoolItem.GetHashCode();
if (this.ArrayItem != null)
hashCode = hashCode * 59 + this.ArrayItem.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)
{
yield break;
}
}
}

View File

@@ -0,0 +1,212 @@
/*
* OpenAPI Petstore
*
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* OpenAPI spec version: 1.0.0
*
* Generated by: https://github.com/openapitools/openapi-generator.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 System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// TypeHolderExample
/// </summary>
[DataContract]
public partial class TypeHolderExample : IEquatable<TypeHolderExample>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="TypeHolderExample" /> class.
/// </summary>
[JsonConstructorAttribute]
protected TypeHolderExample() { }
/// <summary>
/// Initializes a new instance of the <see cref="TypeHolderExample" /> class.
/// </summary>
/// <param name="stringItem">stringItem (required).</param>
/// <param name="numberItem">numberItem (required).</param>
/// <param name="integerItem">integerItem (required).</param>
/// <param name="boolItem">boolItem (required).</param>
/// <param name="arrayItem">arrayItem (required).</param>
public TypeHolderExample(string stringItem = default(string), decimal numberItem = default(decimal), int integerItem = default(int), bool boolItem = default(bool), List<int> arrayItem = default(List<int>))
{
// to ensure "stringItem" is required (not null)
if (stringItem == null)
{
throw new InvalidDataException("stringItem is a required property for TypeHolderExample and cannot be null");
}
else
{
this.StringItem = stringItem;
}
// to ensure "numberItem" is required (not null)
if (numberItem == null)
{
throw new InvalidDataException("numberItem is a required property for TypeHolderExample and cannot be null");
}
else
{
this.NumberItem = numberItem;
}
// to ensure "integerItem" is required (not null)
if (integerItem == null)
{
throw new InvalidDataException("integerItem is a required property for TypeHolderExample and cannot be null");
}
else
{
this.IntegerItem = integerItem;
}
// to ensure "boolItem" is required (not null)
if (boolItem == null)
{
throw new InvalidDataException("boolItem is a required property for TypeHolderExample and cannot be null");
}
else
{
this.BoolItem = boolItem;
}
// to ensure "arrayItem" is required (not null)
if (arrayItem == null)
{
throw new InvalidDataException("arrayItem is a required property for TypeHolderExample and cannot be null");
}
else
{
this.ArrayItem = arrayItem;
}
}
/// <summary>
/// Gets or Sets StringItem
/// </summary>
[DataMember(Name="string_item", EmitDefaultValue=false)]
public string StringItem { get; set; }
/// <summary>
/// Gets or Sets NumberItem
/// </summary>
[DataMember(Name="number_item", EmitDefaultValue=false)]
public decimal NumberItem { get; set; }
/// <summary>
/// Gets or Sets IntegerItem
/// </summary>
[DataMember(Name="integer_item", EmitDefaultValue=false)]
public int IntegerItem { get; set; }
/// <summary>
/// Gets or Sets BoolItem
/// </summary>
[DataMember(Name="bool_item", EmitDefaultValue=false)]
public bool BoolItem { get; set; }
/// <summary>
/// Gets or Sets ArrayItem
/// </summary>
[DataMember(Name="array_item", EmitDefaultValue=false)]
public List<int> ArrayItem { 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 TypeHolderExample {\n");
sb.Append(" StringItem: ").Append(StringItem).Append("\n");
sb.Append(" NumberItem: ").Append(NumberItem).Append("\n");
sb.Append(" IntegerItem: ").Append(IntegerItem).Append("\n");
sb.Append(" BoolItem: ").Append(BoolItem).Append("\n");
sb.Append(" ArrayItem: ").Append(ArrayItem).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 virtual 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 OpenAPIClientUtils.compareLogic.Compare(this, input as TypeHolderExample).AreEqual;
}
/// <summary>
/// Returns true if TypeHolderExample instances are equal
/// </summary>
/// <param name="input">Instance of TypeHolderExample to be compared</param>
/// <returns>Boolean</returns>
public bool Equals(TypeHolderExample input)
{
return OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual;
}
/// <summary>
/// Gets the hash code
/// </summary>
/// <returns>Hash code</returns>
public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
if (this.StringItem != null)
hashCode = hashCode * 59 + this.StringItem.GetHashCode();
if (this.NumberItem != null)
hashCode = hashCode * 59 + this.NumberItem.GetHashCode();
if (this.IntegerItem != null)
hashCode = hashCode * 59 + this.IntegerItem.GetHashCode();
if (this.BoolItem != null)
hashCode = hashCode * 59 + this.BoolItem.GetHashCode();
if (this.ArrayItem != null)
hashCode = hashCode * 59 + this.ArrayItem.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)
{
yield break;
}
}
}