Skip to content

Commit

Permalink
[csharp] Fixed model property data type (#16315)
Browse files Browse the repository at this point in the history
* fixed model property data type

* build samples
  • Loading branch information
devhl-labs committed Aug 15, 2023
1 parent 35fec8d commit 76bb8a4
Show file tree
Hide file tree
Showing 90 changed files with 5,894 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -662,15 +662,20 @@ protected void patchProperty(Map<String, CodegenModel> enumRefs, CodegenModel mo
String tmpPropertyName = escapeReservedWord(model, property.name);
property.name = patchPropertyName(model, property.name);

// fix incorrect data types for maps of maps
if (property.datatypeWithEnum.endsWith(", List>") && property.items != null) {
property.datatypeWithEnum = property.datatypeWithEnum.replace(", List>", ", " + property.items.datatypeWithEnum + ">");
property.dataType = property.datatypeWithEnum;
}
if (property.datatypeWithEnum.endsWith(", Dictionary>") && property.items != null) {
property.datatypeWithEnum = property.datatypeWithEnum.replace(", Dictionary>", ", " + property.items.datatypeWithEnum + ">");
property.dataType = property.datatypeWithEnum;
}
String[] nestedTypes = { "List", "Collection", "ICollection", "Dictionary" };

Arrays.stream(nestedTypes).forEach(nestedType -> {
// fix incorrect data types for maps of maps
if (property.datatypeWithEnum.contains(", " + nestedType + ">") && property.items != null) {
property.datatypeWithEnum = property.datatypeWithEnum.replace(", " + nestedType + ">", ", " + property.items.datatypeWithEnum + ">");
property.dataType = property.datatypeWithEnum;
}

if (property.datatypeWithEnum.contains("<" + nestedType + ">") && property.items != null) {
property.datatypeWithEnum = property.datatypeWithEnum.replace("<" + nestedType + ">", "<" + property.items.datatypeWithEnum + ">");
property.dataType = property.datatypeWithEnum;
}
});

// HOTFIX: https://github.com/OpenAPITools/openapi-generator/issues/14944
if (property.datatypeWithEnum.equals("decimal")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,17 @@ paths:
responses:
'200':
description: OK
/test:
get:
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/notificationtest-getElements-v1-Response-mPayload'
description: Successful response
operationId: Test
summary: Retrieve an existing Notificationtest's Elements
servers:
- url: 'http://{server}.swagger.io:{port}/v2'
description: petstore server
Expand Down Expand Up @@ -2350,4 +2361,22 @@ components:
type: string
enum:
- unknown
- notUnknown
- notUnknown
Custom-Variableobject-Response:
description: A Variable object without predefined property names
type: object
additionalProperties: true
Field-pkiNotificationtestID:
type: integer
notificationtest-getElements-v1-Response-mPayload:
required:
- pkiNotificationtestID
- a_objVariableobject
type: object
properties:
pkiNotificationtestID:
$ref: '#/components/schemas/Field-pkiNotificationtestID'
a_objVariableobject:
type: array
items:
$ref: '#/components/schemas/Custom-Variableobject-Response'
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ docs/MixedPropertiesAndAdditionalPropertiesClass.md
docs/Model200Response.md
docs/ModelClient.md
docs/Name.md
docs/NotificationtestGetElementsV1ResponseMPayload.md
docs/NullableClass.md
docs/NullableGuidClass.md
docs/NullableShape.md
Expand Down Expand Up @@ -174,6 +175,7 @@ src/Org.OpenAPITools/Model/MixedPropertiesAndAdditionalPropertiesClass.cs
src/Org.OpenAPITools/Model/Model200Response.cs
src/Org.OpenAPITools/Model/ModelClient.cs
src/Org.OpenAPITools/Model/Name.cs
src/Org.OpenAPITools/Model/NotificationtestGetElementsV1ResponseMPayload.cs
src/Org.OpenAPITools/Model/NullableClass.cs
src/Org.OpenAPITools/Model/NullableGuidClass.cs
src/Org.OpenAPITools/Model/NullableShape.cs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Class | Method | HTTP request | Description
*DefaultApi* | [**GetCountry**](docs/DefaultApi.md#getcountry) | **POST** /country |
*DefaultApi* | [**Hello**](docs/DefaultApi.md#hello) | **GET** /hello | Hello
*DefaultApi* | [**RolesReportGet**](docs/DefaultApi.md#rolesreportget) | **GET** /roles/report |
*DefaultApi* | [**Test**](docs/DefaultApi.md#test) | **GET** /test | Retrieve an existing Notificationtest's Elements
*FakeApi* | [**FakeHealthGet**](docs/FakeApi.md#fakehealthget) | **GET** /fake/health | Health check endpoint
*FakeApi* | [**FakeOuterBooleanSerialize**](docs/FakeApi.md#fakeouterbooleanserialize) | **POST** /fake/outer/boolean |
*FakeApi* | [**FakeOuterCompositeSerialize**](docs/FakeApi.md#fakeoutercompositeserialize) | **POST** /fake/outer/composite |
Expand Down Expand Up @@ -198,6 +199,7 @@ Class | Method | HTTP request | Description
- [Model.Model200Response](docs/Model200Response.md)
- [Model.ModelClient](docs/ModelClient.md)
- [Model.Name](docs/Name.md)
- [Model.NotificationtestGetElementsV1ResponseMPayload](docs/NotificationtestGetElementsV1ResponseMPayload.md)
- [Model.NullableClass](docs/NullableClass.md)
- [Model.NullableGuidClass](docs/NullableGuidClass.md)
- [Model.NullableShape](docs/NullableShape.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,17 @@ paths:
responses:
"200":
description: OK
/test:
get:
operationId: Test
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/notificationtest-getElements-v1-Response-mPayload'
description: Successful response
summary: Retrieve an existing Notificationtest's Elements
components:
requestBodies:
UserArray:
Expand Down Expand Up @@ -2294,6 +2305,29 @@ components:
- notUnknown
type: string
type: object
Custom-Variableobject-Response:
additionalProperties: true
description: A Variable object without predefined property names
type: object
Field-pkiNotificationtestID:
type: integer
notificationtest-getElements-v1-Response-mPayload:
example:
a_objVariableobject:
- null
- null
pkiNotificationtestID: 0
properties:
pkiNotificationtestID:
type: integer
a_objVariableobject:
items:
$ref: '#/components/schemas/Custom-Variableobject-Response'
type: array
required:
- a_objVariableobject
- pkiNotificationtestID
type: object
_foo_get_default_response:
example:
string:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
| [**GetCountry**](DefaultApi.md#getcountry) | **POST** /country | |
| [**Hello**](DefaultApi.md#hello) | **GET** /hello | Hello |
| [**RolesReportGet**](DefaultApi.md#rolesreportget) | **GET** /roles/report | |
| [**Test**](DefaultApi.md#test) | **GET** /test | Retrieve an existing Notificationtest&#39;s Elements |

<a id="fooget"></a>
# **FooGet**
Expand Down Expand Up @@ -342,3 +343,87 @@ No authorization required

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

<a id="test"></a>
# **Test**
> NotificationtestGetElementsV1ResponseMPayload Test ()
Retrieve an existing Notificationtest's Elements

### Example
```csharp
using System.Collections.Generic;
using System.Diagnostics;
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Client;
using Org.OpenAPITools.Model;

namespace Example
{
public class TestExample
{
public static void Main()
{
Configuration config = new Configuration();
config.BasePath = "http://petstore.swagger.io:80/v2";
var apiInstance = new DefaultApi(config);

try
{
// Retrieve an existing Notificationtest's Elements
NotificationtestGetElementsV1ResponseMPayload result = apiInstance.Test();
Debug.WriteLine(result);
}
catch (ApiException e)
{
Debug.Print("Exception when calling DefaultApi.Test: " + e.Message);
Debug.Print("Status Code: " + e.ErrorCode);
Debug.Print(e.StackTrace);
}
}
}
}
```

#### Using the TestWithHttpInfo variant
This returns an ApiResponse object which contains the response data, status code and headers.

```csharp
try
{
// Retrieve an existing Notificationtest's Elements
ApiResponse<NotificationtestGetElementsV1ResponseMPayload> response = apiInstance.TestWithHttpInfo();
Debug.Write("Status Code: " + response.StatusCode);
Debug.Write("Response Headers: " + response.Headers);
Debug.Write("Response Body: " + response.Data);
}
catch (ApiException e)
{
Debug.Print("Exception when calling DefaultApi.TestWithHttpInfo: " + e.Message);
Debug.Print("Status Code: " + e.ErrorCode);
Debug.Print(e.StackTrace);
}
```

### Parameters
This endpoint does not need any parameter.
### Return type

[**NotificationtestGetElementsV1ResponseMPayload**](NotificationtestGetElementsV1ResponseMPayload.md)

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: application/json


### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | Successful response | - |

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

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

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**PkiNotificationtestID** | **int** | |
**AObjVariableobject** | **List&lt;Dictionary&lt;string, Object&gt;&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)

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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.Model;
using Org.OpenAPITools.Client;
using System.Reflection;
using Newtonsoft.Json;

namespace Org.OpenAPITools.Test.Model
{
/// <summary>
/// Class for testing NotificationtestGetElementsV1ResponseMPayload
/// </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 NotificationtestGetElementsV1ResponseMPayloadTests : IDisposable
{
// TODO uncomment below to declare an instance variable for NotificationtestGetElementsV1ResponseMPayload
//private NotificationtestGetElementsV1ResponseMPayload instance;

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

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

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

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

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

0 comments on commit 76bb8a4

Please sign in to comment.