Skip to content

Commit f536295

Browse files
authored
Merge pull request #3331 from wing328/csharp_fix_client_model
[C#] to fix issues when the model name is "Client"
2 parents 89741c7 + 1c52105 commit f536295

File tree

11 files changed

+547
-31
lines changed

11 files changed

+547
-31
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractCSharpCodegen.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public AbstractCSharpCodegen() {
5757

5858
setReservedWordsLowerCase(
5959
Arrays.asList(
60+
// set client as a reserved word to avoid conflicts with IO.Swagger.Client
61+
// this is a workaround and can be removed if c# api client is updated to use
62+
// fully qualified name
63+
"client",
6064
// local variable names in API methods (endpoints)
6165
"localVarPath", "localVarPathParams", "localVarQueryParams", "localVarHeaderParams",
6266
"localVarFormParams", "localVarFileParams", "localVarStatusCode", "localVarResponse",

modules/swagger-codegen/src/main/resources/csharp/README.mustache

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,16 @@ No model defined in this package
128128

129129
## Documentation for Authorization
130130

131-
<a name="{{#authMethods}}{{name}}"></a>
132-
{{^authMethods}} All endpoints do not require authorization.
133-
{{/authMethods}}{{#authMethods}}{{#last}} Authentication schemes defined for the API:{{/last}}{{/authMethods}}
134-
{{#authMethods}}### {{name}}
131+
{{^authMethods}}
132+
All endpoints do not require authorization.
133+
{{/authMethods}}
134+
{{#authMethods}}
135+
{{#last}}
136+
Authentication schemes defined for the API:
137+
{{/last}}
138+
{{/authMethods}}
139+
{{#authMethods}}
140+
### {{name}}
135141

136142
{{#isApiKey}}- **Type**: API key
137143
- **API key parameter name**: {{keyParamName}}

modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,28 @@ paths:
561561
description: User not found
562562

563563
/fake:
564+
patch:
565+
tags:
566+
- fake
567+
summary: To test "client" model
568+
descriptions: To test "client" model
569+
operationId: testClientModel
570+
consumes:
571+
- application/json
572+
produces:
573+
- application/json
574+
parameters:
575+
- in: body
576+
name: body
577+
description: client model
578+
required: true
579+
schema:
580+
$ref: '#/definitions/Client'
581+
responses:
582+
'200':
583+
description: successful operation
584+
schema:
585+
$ref: '#/definitions/Client'
564586
get:
565587
tags:
566588
- fake
@@ -1018,6 +1040,11 @@ definitions:
10181040
type: object
10191041
additionalProperties:
10201042
$ref: '#/definitions/Animal'
1043+
Client:
1044+
type: object
1045+
properties:
1046+
client:
1047+
type: string
10211048
ReadOnlyFirst:
10221049
type: object
10231050
properties:

samples/client/petstore/csharp/SwaggerClient/IO.Swagger.sln

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
22
# Visual Studio 2012
33
VisualStudioVersion = 12.0.0.0
44
MinimumVisualStudioVersion = 10.0.0.1
5-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{9391D4F3-E89A-41F1-B1C9-A9C885B3F96D}"
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{C8F5DE66-0944-4368-91CC-2313B4BFADDE}"
66
EndProject
77
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger.Test", "src\IO.Swagger.Test\IO.Swagger.Test.csproj", "{19F1DEBC-DE5E-4517-8062-F000CD499087}"
88
EndProject
@@ -12,10 +12,10 @@ Debug|Any CPU = Debug|Any CPU
1212
Release|Any CPU = Release|Any CPU
1313
EndGlobalSection
1414
GlobalSection(ProjectConfigurationPlatforms) = postSolution
15-
{9391D4F3-E89A-41F1-B1C9-A9C885B3F96D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
16-
{9391D4F3-E89A-41F1-B1C9-A9C885B3F96D}.Debug|Any CPU.Build.0 = Debug|Any CPU
17-
{9391D4F3-E89A-41F1-B1C9-A9C885B3F96D}.Release|Any CPU.ActiveCfg = Release|Any CPU
18-
{9391D4F3-E89A-41F1-B1C9-A9C885B3F96D}.Release|Any CPU.Build.0 = Release|Any CPU
15+
{C8F5DE66-0944-4368-91CC-2313B4BFADDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
16+
{C8F5DE66-0944-4368-91CC-2313B4BFADDE}.Debug|Any CPU.Build.0 = Debug|Any CPU
17+
{C8F5DE66-0944-4368-91CC-2313B4BFADDE}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{C8F5DE66-0944-4368-91CC-2313B4BFADDE}.Release|Any CPU.Build.0 = Release|Any CPU
1919
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2020
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU
2121
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU

samples/client/petstore/csharp/SwaggerClient/README.md

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# IO.Swagger - the C# library for the Swagger Petstore
22

3-
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
3+
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
44

55
This C# SDK is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:
66

77
- API version: 1.0.0
88
- SDK version: 1.0.0
9-
- Build date: 2016-06-23T12:09:14.609+08:00
9+
- Build date: 2016-07-10T17:40:23.847+08:00
1010
- Build package: class io.swagger.codegen.languages.CSharpClientCodegen
1111

1212
## Frameworks supported
1313
- .NET 4.0 or later
1414
- Windows Phone 7.1 (Mango)
1515

1616
## Dependencies
17-
- [RestSharp] (https://www.nuget.org/packages/RestSharp) - 105.1.0 or later
18-
- [Json.NET] (https://www.nuget.org/packages/Newtonsoft.Json/) - 7.0.0 or later
17+
- [RestSharp](https://www.nuget.org/packages/RestSharp) - 105.1.0 or later
18+
- [Json.NET](https://www.nuget.org/packages/Newtonsoft.Json/) - 7.0.0 or later
1919

2020
The DLLs included in the package may not be the latest version. We recommned using [NuGet] (https://docs.nuget.org/consume/installing-nuget) to obtain the latest version of the packages:
2121
```
@@ -54,39 +54,31 @@ namespace Example
5454
{
5555

5656
var apiInstance = new FakeApi();
57-
var number = 3.4; // decimal? | None
58-
var _double = 1.2; // double? | None
59-
var _string = _string_example; // string | None
60-
var _byte = B; // byte[] | None
61-
var integer = 56; // int? | None (optional)
62-
var int32 = 56; // int? | None (optional)
63-
var int64 = 789; // long? | None (optional)
64-
var _float = 3.4; // float? | None (optional)
65-
var binary = B; // byte[] | None (optional)
66-
var date = 2013-10-20; // DateTime? | None (optional)
67-
var dateTime = 2013-10-20T19:20:30+01:00; // DateTime? | None (optional)
68-
var password = password_example; // string | None (optional)
57+
var body = new ModelClient(); // ModelClient | client model
6958
7059
try
7160
{
72-
// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
73-
apiInstance.TestEndpointParameters(number, _double, _string, _byte, integer, int32, int64, _float, binary, date, dateTime, password);
61+
// To test \"client\" model
62+
ModelClient result = apiInstance.TestClientModel(body);
63+
Debug.WriteLine(result);
7464
}
7565
catch (Exception e)
7666
{
77-
Debug.Print("Exception when calling FakeApi.TestEndpointParameters: " + e.Message );
67+
Debug.Print("Exception when calling FakeApi.TestClientModel: " + e.Message );
7868
}
7969
}
8070
}
8171
}
8272
```
8373

74+
<a name="documentation-for-api-endpoints"></a>
8475
## Documentation for API Endpoints
8576

8677
All URIs are relative to *http://petstore.swagger.io/v2*
8778

8879
Class | Method | HTTP request | Description
8980
------------ | ------------- | ------------- | -------------
81+
*FakeApi* | [**TestClientModel**](docs/FakeApi.md#testclientmodel) | **PATCH** /fake | To test \"client\" model
9082
*FakeApi* | [**TestEndpointParameters**](docs/FakeApi.md#testendpointparameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
9183
*FakeApi* | [**TestEnumQueryParameters**](docs/FakeApi.md#testenumqueryparameters) | **GET** /fake | To test enum query parameters
9284
*PetApi* | [**AddPet**](docs/PetApi.md#addpet) | **POST** /pet | Add a new pet to the store
@@ -111,6 +103,7 @@ Class | Method | HTTP request | Description
111103
*UserApi* | [**UpdateUser**](docs/UserApi.md#updateuser) | **PUT** /user/{username} | Updated user
112104

113105

106+
<a name="documentation-for-models"></a>
114107
## Documentation for Models
115108

116109
- [Model.AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md)
@@ -130,6 +123,7 @@ Class | Method | HTTP request | Description
130123
- [Model.MapTest](docs/MapTest.md)
131124
- [Model.MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md)
132125
- [Model.Model200Response](docs/Model200Response.md)
126+
- [Model.ModelClient](docs/ModelClient.md)
133127
- [Model.ModelReturn](docs/ModelReturn.md)
134128
- [Model.Name](docs/Name.md)
135129
- [Model.NumberOnly](docs/NumberOnly.md)
@@ -143,7 +137,6 @@ Class | Method | HTTP request | Description
143137

144138
## Documentation for Authorization
145139

146-
147140
### api_key
148141

149142
- **Type**: API key

samples/client/petstore/csharp/SwaggerClient/docs/FakeApi.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,71 @@ All URIs are relative to *http://petstore.swagger.io/v2*
44

55
Method | HTTP request | Description
66
------------- | ------------- | -------------
7+
[**TestClientModel**](FakeApi.md#testclientmodel) | **PATCH** /fake | To test \&quot;client\&quot; model
78
[**TestEndpointParameters**](FakeApi.md#testendpointparameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
89
[**TestEnumQueryParameters**](FakeApi.md#testenumqueryparameters) | **GET** /fake | To test enum query parameters
910

1011

12+
<a name="testclientmodel"></a>
13+
# **TestClientModel**
14+
> ModelClient TestClientModel (ModelClient body)
15+
16+
To test \"client\" model
17+
18+
### Example
19+
```csharp
20+
using System;
21+
using System.Diagnostics;
22+
using IO.Swagger.Api;
23+
using IO.Swagger.Client;
24+
using IO.Swagger.Model;
25+
26+
namespace Example
27+
{
28+
public class TestClientModelExample
29+
{
30+
public void main()
31+
{
32+
33+
var apiInstance = new FakeApi();
34+
var body = new ModelClient(); // ModelClient | client model
35+
36+
try
37+
{
38+
// To test \"client\" model
39+
ModelClient result = apiInstance.TestClientModel(body);
40+
Debug.WriteLine(result);
41+
}
42+
catch (Exception e)
43+
{
44+
Debug.Print("Exception when calling FakeApi.TestClientModel: " + e.Message );
45+
}
46+
}
47+
}
48+
}
49+
```
50+
51+
### Parameters
52+
53+
Name | Type | Description | Notes
54+
------------- | ------------- | ------------- | -------------
55+
**body** | [**ModelClient**](ModelClient.md)| client model |
56+
57+
### Return type
58+
59+
[**ModelClient**](ModelClient.md)
60+
61+
### Authorization
62+
63+
No authorization required
64+
65+
### HTTP request headers
66+
67+
- **Content-Type**: application/json
68+
- **Accept**: application/json
69+
70+
[[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)
71+
1172
<a name="testendpointparameters"></a>
1273
# **TestEndpointParameters**
1374
> void TestEndpointParameters (decimal? number, double? _double, string _string, byte[] _byte, int? integer = null, int? int32 = null, long? int64 = null, float? _float = null, byte[] binary = null, DateTime? date = null, DateTime? dateTime = null, string password = null)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# IO.Swagger.Model.ModelClient
2+
## Properties
3+
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**_Client** | **string** | | [optional]
7+
8+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
9+
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Swagger Petstore
3+
*
4+
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
5+
*
6+
* OpenAPI spec version: 1.0.0
7+
* Contact: [email protected]
8+
* Generated by: https://github.com/swagger-api/swagger-codegen.git
9+
*
10+
* Licensed under the Apache License, Version 2.0 (the "License");
11+
* you may not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS,
18+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
*/
22+
23+
24+
using NUnit.Framework;
25+
26+
using System;
27+
using System.Linq;
28+
using System.IO;
29+
using System.Collections.Generic;
30+
using IO.Swagger.Api;
31+
using IO.Swagger.Model;
32+
using IO.Swagger.Client;
33+
using System.Reflection;
34+
35+
namespace IO.Swagger.Test
36+
{
37+
/// <summary>
38+
/// Class for testing ModelClient
39+
/// </summary>
40+
/// <remarks>
41+
/// This file is automatically generated by Swagger Codegen.
42+
/// Please update the test case below to test the model.
43+
/// </remarks>
44+
[TestFixture]
45+
public class ModelClientTests
46+
{
47+
// TODO uncomment below to declare an instance variable for ModelClient
48+
//private ModelClient instance;
49+
50+
/// <summary>
51+
/// Setup before each test
52+
/// </summary>
53+
[SetUp]
54+
public void Init()
55+
{
56+
// TODO uncomment below to create an instance of ModelClient
57+
//instance = new ModelClient();
58+
}
59+
60+
/// <summary>
61+
/// Clean up after each test
62+
/// </summary>
63+
[TearDown]
64+
public void Cleanup()
65+
{
66+
67+
}
68+
69+
/// <summary>
70+
/// Test an instance of ModelClient
71+
/// </summary>
72+
[Test]
73+
public void ModelClientInstanceTest()
74+
{
75+
// TODO uncomment below to test "IsInstanceOfType" ModelClient
76+
//Assert.IsInstanceOfType<ModelClient> (instance, "variable 'instance' is a ModelClient");
77+
}
78+
79+
/// <summary>
80+
/// Test the property '_Client'
81+
/// </summary>
82+
[Test]
83+
public void _ClientTest()
84+
{
85+
// TODO unit test for the property '_Client'
86+
}
87+
88+
}
89+
90+
}

0 commit comments

Comments
 (0)