Skip to content

Commit 93588f4

Browse files
authored
Fix C# discriminator's mapping name (OpenAPITools#1942)
* fix C# mapping name * add back jsonsubtypes * add new files
1 parent 562d9d5 commit 93588f4

File tree

9 files changed

+684
-3
lines changed

9 files changed

+684
-3
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpRefactorClientCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ public CodegenModel fromModel(String name, Schema model, Map<String, Schema> all
592592
parentVar.isInherited = true;
593593
parentVar.hasMore = true;
594594
last = parentVar;
595-
LOGGER.info("adding parent variable {}", property.name);
595+
LOGGER.debug("adding parent variable {}", property.name);
596596
codegenModel.parentVars.add(parentVar);
597597
}
598598
}

modules/openapi-generator/src/main/resources/csharp-refactor/modelGeneric.mustache

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
/// </summary>
44
[DataContract]
55
{{#discriminator}}
6-
[JsonConverter(typeof(JsonSubtypes), "{{{discriminatorName}}}")]{{#children}}
7-
[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}}
6+
[JsonConverter(typeof(JsonSubtypes), "{{{discriminatorName}}}")]
7+
{{#children}}
8+
[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}}")]
9+
{{/children}}
10+
{{#mappedModels}}
11+
[JsonSubtypes.KnownSubType(typeof({{{modelName}}}), "{{{mappingName}}}")]
12+
{{/mappedModels}}
813
{{/discriminator}}
914
{{#generatePropertyChanged}}
1015
[ImplementPropertyChanged]

samples/client/petstore/csharp-refactor/OpenAPIClient/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ Class | Method | HTTP request | Description
169169
- [Model.Return](docs/Return.md)
170170
- [Model.SpecialModelName](docs/SpecialModelName.md)
171171
- [Model.Tag](docs/Tag.md)
172+
- [Model.TypeHolderDefault](docs/TypeHolderDefault.md)
173+
- [Model.TypeHolderExample](docs/TypeHolderExample.md)
172174
- [Model.User](docs/User.md)
173175

174176

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Org.OpenAPITools.Model.TypeHolderDefault
2+
## Properties
3+
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**StringItem** | **string** | | [default to "what"]
7+
**NumberItem** | **decimal** | |
8+
**IntegerItem** | **int** | |
9+
**BoolItem** | **bool** | | [default to true]
10+
**ArrayItem** | **List&lt;int&gt;** | |
11+
12+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
13+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Org.OpenAPITools.Model.TypeHolderExample
2+
## Properties
3+
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**StringItem** | **string** | |
7+
**NumberItem** | **decimal** | |
8+
**IntegerItem** | **int** | |
9+
**BoolItem** | **bool** | |
10+
**ArrayItem** | **List&lt;int&gt;** | |
11+
12+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* OpenAPI 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+
*
8+
* Generated by: https://github.com/openapitools/openapi-generator.git
9+
*/
10+
11+
12+
using NUnit.Framework;
13+
14+
using System;
15+
using System.Linq;
16+
using System.IO;
17+
using System.Collections.Generic;
18+
using Org.OpenAPITools.Api;
19+
using Org.OpenAPITools.Model;
20+
using Org.OpenAPITools.Client;
21+
using System.Reflection;
22+
using Newtonsoft.Json;
23+
24+
namespace Org.OpenAPITools.Test
25+
{
26+
/// <summary>
27+
/// Class for testing TypeHolderDefault
28+
/// </summary>
29+
/// <remarks>
30+
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
31+
/// Please update the test case below to test the model.
32+
/// </remarks>
33+
[TestFixture]
34+
public class TypeHolderDefaultTests
35+
{
36+
// TODO uncomment below to declare an instance variable for TypeHolderDefault
37+
//private TypeHolderDefault instance;
38+
39+
/// <summary>
40+
/// Setup before each test
41+
/// </summary>
42+
[SetUp]
43+
public void Init()
44+
{
45+
// TODO uncomment below to create an instance of TypeHolderDefault
46+
//instance = new TypeHolderDefault();
47+
}
48+
49+
/// <summary>
50+
/// Clean up after each test
51+
/// </summary>
52+
[TearDown]
53+
public void Cleanup()
54+
{
55+
56+
}
57+
58+
/// <summary>
59+
/// Test an instance of TypeHolderDefault
60+
/// </summary>
61+
[Test]
62+
public void TypeHolderDefaultInstanceTest()
63+
{
64+
// TODO uncomment below to test "IsInstanceOfType" TypeHolderDefault
65+
//Assert.IsInstanceOfType<TypeHolderDefault> (instance, "variable 'instance' is a TypeHolderDefault");
66+
}
67+
68+
69+
/// <summary>
70+
/// Test the property 'StringItem'
71+
/// </summary>
72+
[Test]
73+
public void StringItemTest()
74+
{
75+
// TODO unit test for the property 'StringItem'
76+
}
77+
/// <summary>
78+
/// Test the property 'NumberItem'
79+
/// </summary>
80+
[Test]
81+
public void NumberItemTest()
82+
{
83+
// TODO unit test for the property 'NumberItem'
84+
}
85+
/// <summary>
86+
/// Test the property 'IntegerItem'
87+
/// </summary>
88+
[Test]
89+
public void IntegerItemTest()
90+
{
91+
// TODO unit test for the property 'IntegerItem'
92+
}
93+
/// <summary>
94+
/// Test the property 'BoolItem'
95+
/// </summary>
96+
[Test]
97+
public void BoolItemTest()
98+
{
99+
// TODO unit test for the property 'BoolItem'
100+
}
101+
/// <summary>
102+
/// Test the property 'ArrayItem'
103+
/// </summary>
104+
[Test]
105+
public void ArrayItemTest()
106+
{
107+
// TODO unit test for the property 'ArrayItem'
108+
}
109+
110+
}
111+
112+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* OpenAPI 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+
*
8+
* Generated by: https://github.com/openapitools/openapi-generator.git
9+
*/
10+
11+
12+
using NUnit.Framework;
13+
14+
using System;
15+
using System.Linq;
16+
using System.IO;
17+
using System.Collections.Generic;
18+
using Org.OpenAPITools.Api;
19+
using Org.OpenAPITools.Model;
20+
using Org.OpenAPITools.Client;
21+
using System.Reflection;
22+
using Newtonsoft.Json;
23+
24+
namespace Org.OpenAPITools.Test
25+
{
26+
/// <summary>
27+
/// Class for testing TypeHolderExample
28+
/// </summary>
29+
/// <remarks>
30+
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
31+
/// Please update the test case below to test the model.
32+
/// </remarks>
33+
[TestFixture]
34+
public class TypeHolderExampleTests
35+
{
36+
// TODO uncomment below to declare an instance variable for TypeHolderExample
37+
//private TypeHolderExample instance;
38+
39+
/// <summary>
40+
/// Setup before each test
41+
/// </summary>
42+
[SetUp]
43+
public void Init()
44+
{
45+
// TODO uncomment below to create an instance of TypeHolderExample
46+
//instance = new TypeHolderExample();
47+
}
48+
49+
/// <summary>
50+
/// Clean up after each test
51+
/// </summary>
52+
[TearDown]
53+
public void Cleanup()
54+
{
55+
56+
}
57+
58+
/// <summary>
59+
/// Test an instance of TypeHolderExample
60+
/// </summary>
61+
[Test]
62+
public void TypeHolderExampleInstanceTest()
63+
{
64+
// TODO uncomment below to test "IsInstanceOfType" TypeHolderExample
65+
//Assert.IsInstanceOfType<TypeHolderExample> (instance, "variable 'instance' is a TypeHolderExample");
66+
}
67+
68+
69+
/// <summary>
70+
/// Test the property 'StringItem'
71+
/// </summary>
72+
[Test]
73+
public void StringItemTest()
74+
{
75+
// TODO unit test for the property 'StringItem'
76+
}
77+
/// <summary>
78+
/// Test the property 'NumberItem'
79+
/// </summary>
80+
[Test]
81+
public void NumberItemTest()
82+
{
83+
// TODO unit test for the property 'NumberItem'
84+
}
85+
/// <summary>
86+
/// Test the property 'IntegerItem'
87+
/// </summary>
88+
[Test]
89+
public void IntegerItemTest()
90+
{
91+
// TODO unit test for the property 'IntegerItem'
92+
}
93+
/// <summary>
94+
/// Test the property 'BoolItem'
95+
/// </summary>
96+
[Test]
97+
public void BoolItemTest()
98+
{
99+
// TODO unit test for the property 'BoolItem'
100+
}
101+
/// <summary>
102+
/// Test the property 'ArrayItem'
103+
/// </summary>
104+
[Test]
105+
public void ArrayItemTest()
106+
{
107+
// TODO unit test for the property 'ArrayItem'
108+
}
109+
110+
}
111+
112+
}

0 commit comments

Comments
 (0)