Skip to content

Commit

Permalink
[csharp] Fixed data type for maps of maps (OpenAPITools#13701)
Browse files Browse the repository at this point in the history
* fixed data type for maps of maps

* added models to samples

* moved code to avoid a bug in the property generation
  • Loading branch information
devhl-labs authored Oct 19, 2022
1 parent 58f8172 commit 0c1384b
Show file tree
Hide file tree
Showing 79 changed files with 4,523 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,16 @@ private void patchProperty(CodegenModel model, CodegenProperty property){
property.isMap = composedProperty.isMap;
property.isContainer = composedProperty.isContainer;
}

// fix incorrect data types for maps of maps
if (property.datatypeWithEnum.contains("List>") && property.items != null) {
property.datatypeWithEnum = property.datatypeWithEnum.replace("List>", property.items.datatypeWithEnum + ">");
property.dataType = property.datatypeWithEnum;
}
if (property.datatypeWithEnum.contains("Dictionary>") && property.items != null) {
property.datatypeWithEnum = property.datatypeWithEnum.replace("Dictionary>", property.items.datatypeWithEnum + ">");
property.dataType = property.datatypeWithEnum;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2160,3 +2160,22 @@ components:
StringArrayItem:
type: string
format: string
Activity:
description: "test map of maps"
type: object
properties:
activity_outputs:
type: object
additionalProperties:
$ref: '#/components/schemas/ActivityOutputRepresentation'
ActivityOutputRepresentation:
type: array
items:
$ref: '#/components/schemas/ActivityOutputElementRepresentation'
ActivityOutputElementRepresentation:
type: object
properties:
prop1:
type: string
prop2:
type: object
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Org.OpenAPITools.sln
README.md
appveyor.yml
docs/Activity.md
docs/ActivityOutputElementRepresentation.md
docs/AdditionalPropertiesClass.md
docs/Animal.md
docs/AnotherFakeApi.md
Expand Down Expand Up @@ -116,6 +118,8 @@ src/Org.OpenAPITools/Client/OpenAPIDateConverter.cs
src/Org.OpenAPITools/Client/RequestOptions.cs
src/Org.OpenAPITools/Client/RetryConfiguration.cs
src/Org.OpenAPITools/Model/AbstractOpenAPISchema.cs
src/Org.OpenAPITools/Model/Activity.cs
src/Org.OpenAPITools/Model/ActivityOutputElementRepresentation.cs
src/Org.OpenAPITools/Model/AdditionalPropertiesClass.cs
src/Org.OpenAPITools/Model/Animal.cs
src/Org.OpenAPITools/Model/ApiResponse.cs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ Class | Method | HTTP request | Description
<a name="documentation-for-models"></a>
## Documentation for Models

- [Model.Activity](docs/Activity.md)
- [Model.ActivityOutputElementRepresentation](docs/ActivityOutputElementRepresentation.md)
- [Model.AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md)
- [Model.Animal](docs/Animal.md)
- [Model.ApiResponse](docs/ApiResponse.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Org.OpenAPITools.Model.Activity
test map of maps

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**ActivityOutputs** | **Dictionary&lt;string, List&lt;ActivityOutputElementRepresentation&gt;&gt;** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Org.OpenAPITools.Model.ActivityOutputElementRepresentation

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Prop1** | **string** | | [optional]
**Prop2** | **Object** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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: \" \\
*
* The version of the OpenAPI document: 1.0.0
* Generated by: https://github.com/openapitools/openapi-generator.git
*/


using Xunit;

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.Model
{
/// <summary>
/// Class for testing ActivityOutputElementRepresentation
/// </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>
public class ActivityOutputElementRepresentationTests : IDisposable
{
// TODO uncomment below to declare an instance variable for ActivityOutputElementRepresentation
//private ActivityOutputElementRepresentation instance;

public ActivityOutputElementRepresentationTests()
{
// TODO uncomment below to create an instance of ActivityOutputElementRepresentation
//instance = new ActivityOutputElementRepresentation();
}

public void Dispose()
{
// Cleanup when everything is done.
}

/// <summary>
/// Test an instance of ActivityOutputElementRepresentation
/// </summary>
[Fact]
public void ActivityOutputElementRepresentationInstanceTest()
{
// TODO uncomment below to test "IsType" ActivityOutputElementRepresentation
//Assert.IsType<ActivityOutputElementRepresentation>(instance);
}


/// <summary>
/// Test the property 'Prop1'
/// </summary>
[Fact]
public void Prop1Test()
{
// TODO unit test for the property 'Prop1'
}
/// <summary>
/// Test the property 'Prop2'
/// </summary>
[Fact]
public void Prop2Test()
{
// TODO unit test for the property 'Prop2'
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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: \" \\
*
* The version of the OpenAPI document: 1.0.0
* Generated by: https://github.com/openapitools/openapi-generator.git
*/


using Xunit;

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.Model
{
/// <summary>
/// Class for testing Activity
/// </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>
public class ActivityTests : IDisposable
{
// TODO uncomment below to declare an instance variable for Activity
//private Activity instance;

public ActivityTests()
{
// TODO uncomment below to create an instance of Activity
//instance = new Activity();
}

public void Dispose()
{
// Cleanup when everything is done.
}

/// <summary>
/// Test an instance of Activity
/// </summary>
[Fact]
public void ActivityInstanceTest()
{
// TODO uncomment below to test "IsType" Activity
//Assert.IsType<Activity>(instance);
}


/// <summary>
/// Test the property 'ActivityOutputs'
/// </summary>
[Fact]
public void ActivityOutputsTest()
{
// TODO unit test for the property 'ActivityOutputs'
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
* 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: \" \\
*
* The version of the OpenAPI document: 1.0.0
* Generated by: https://github.com/openapitools/openapi-generator.git
*/


using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.IO;
using System.Runtime.Serialization;
using System.Text;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;

namespace Org.OpenAPITools.Model
{
/// <summary>
/// test map of maps
/// </summary>
[DataContract(Name = "Activity")]
public partial class Activity : IEquatable<Activity>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="Activity" /> class.
/// </summary>
/// <param name="activityOutputs">activityOutputs.</param>
public Activity(Dictionary<string, List<ActivityOutputElementRepresentation>> activityOutputs = default(Dictionary<string, List<ActivityOutputElementRepresentation>>))
{
this._ActivityOutputs = activityOutputs;
if (this.ActivityOutputs != null)
{
this._flagActivityOutputs = true;
}
this.AdditionalProperties = new Dictionary<string, object>();
}

/// <summary>
/// Gets or Sets ActivityOutputs
/// </summary>
[DataMember(Name = "activity_outputs", EmitDefaultValue = false)]
public Dictionary<string, List<ActivityOutputElementRepresentation>> ActivityOutputs
{
get{ return _ActivityOutputs;}
set
{
_ActivityOutputs = value;
_flagActivityOutputs = true;
}
}
private Dictionary<string, List<ActivityOutputElementRepresentation>> _ActivityOutputs;
private bool _flagActivityOutputs;

/// <summary>
/// Returns false as ActivityOutputs should not be serialized given that it's read-only.
/// </summary>
/// <returns>false (boolean)</returns>
public bool ShouldSerializeActivityOutputs()
{
return _flagActivityOutputs;
}
/// <summary>
/// Gets or Sets additional properties
/// </summary>
[JsonExtensionData]
public IDictionary<string, object> AdditionalProperties { get; set; }

/// <summary>
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("class Activity {\n");
sb.Append(" ActivityOutputs: ").Append(ActivityOutputs).Append("\n");
sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).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 Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.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 Activity).AreEqual;
}

/// <summary>
/// Returns true if Activity instances are equal
/// </summary>
/// <param name="input">Instance of Activity to be compared</param>
/// <returns>Boolean</returns>
public bool Equals(Activity 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.ActivityOutputs != null)
{
hashCode = (hashCode * 59) + this.ActivityOutputs.GetHashCode();
}
if (this.AdditionalProperties != null)
{
hashCode = (hashCode * 59) + this.AdditionalProperties.GetHashCode();
}
return hashCode;
}
}

/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
public IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> Validate(ValidationContext validationContext)
{
yield break;
}
}

}
Loading

0 comments on commit 0c1384b

Please sign in to comment.