Skip to content

Commit f1c1567

Browse files
authored
[csharp][generichost] Fixes de/serialization (OpenAPITools#20540)
* fixed json serializer * build samples
1 parent b033219 commit f1c1567

File tree

186 files changed

+11210
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+11210
-2
lines changed

modules/openapi-generator/src/main/resources/csharp/libraries/generichost/JsonConverter.mustache

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
{{/-first}}
5353
if (discriminator != null && discriminator.Equals("{{name}}"))
54-
return JsonSerializer.Deserialize<{{{name}}}>(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value.");
54+
return JsonSerializer.Deserialize<{{{classname}}}>(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value.");
5555

5656
{{/children}}
5757
{{/discriminator}}
@@ -348,7 +348,7 @@
348348
{{#discriminator}}
349349
{{#children}}
350350
if ({{#lambda.paste}}{{/lambda.paste}} is {{classname}} {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}){
351-
JsonSerializer.Serialize<{{{name}}}>(writer, {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}, jsonSerializerOptions);
351+
JsonSerializer.Serialize<{{{classname}}}>(writer, {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}, jsonSerializerOptions);
352352
return;
353353
}
354354

modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -2938,3 +2938,28 @@ components:
29382938
uuid:
29392939
type: string
29402940
format: uuid
2941+
CopyActivity:
2942+
type: object
2943+
required:
2944+
- $schema
2945+
- copyActivitytt
2946+
properties:
2947+
$schema:
2948+
type: string
2949+
enum:
2950+
- ScopeActivity
2951+
copyActivitytt:
2952+
type: string
2953+
allOf:
2954+
- $ref: '#/components/schemas/EntityBase'
2955+
EntityBase:
2956+
type: object
2957+
required:
2958+
- $schema
2959+
properties:
2960+
$schema:
2961+
type: string
2962+
discriminator:
2963+
propertyName: $schema
2964+
mapping:
2965+
ScopeActivity: '#/components/schemas/CopyActivity'

samples/client/petstore/csharp/generichost/net4.7/FormModels/.openapi-generator/FILES

+4
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ docs/models/ChildCat.md
3030
docs/models/ChildCatAllOfPetType.md
3131
docs/models/ClassModel.md
3232
docs/models/ComplexQuadrilateral.md
33+
docs/models/CopyActivity.md
3334
docs/models/DanishPig.md
3435
docs/models/DateOnlyClass.md
3536
docs/models/DeprecatedObject.md
3637
docs/models/Dog.md
3738
docs/models/Drawing.md
39+
docs/models/EntityBase.md
3840
docs/models/EnumArrays.md
3941
docs/models/EnumArraysArrayEnumInner.md
4042
docs/models/EnumArraysJustSymbol.md
@@ -187,11 +189,13 @@ src/Org.OpenAPITools/Model/ChildCat.cs
187189
src/Org.OpenAPITools/Model/ChildCatAllOfPetType.cs
188190
src/Org.OpenAPITools/Model/ClassModel.cs
189191
src/Org.OpenAPITools/Model/ComplexQuadrilateral.cs
192+
src/Org.OpenAPITools/Model/CopyActivity.cs
190193
src/Org.OpenAPITools/Model/DanishPig.cs
191194
src/Org.OpenAPITools/Model/DateOnlyClass.cs
192195
src/Org.OpenAPITools/Model/DeprecatedObject.cs
193196
src/Org.OpenAPITools/Model/Dog.cs
194197
src/Org.OpenAPITools/Model/Drawing.cs
198+
src/Org.OpenAPITools/Model/EntityBase.cs
195199
src/Org.OpenAPITools/Model/EnumArrays.cs
196200
src/Org.OpenAPITools/Model/EnumArraysArrayEnumInner.cs
197201
src/Org.OpenAPITools/Model/EnumArraysJustSymbol.cs

samples/client/petstore/csharp/generichost/net4.7/FormModels/api/openapi.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -2694,6 +2694,31 @@ components:
26942694
uuid:
26952695
format: uuid
26962696
type: string
2697+
CopyActivity:
2698+
allOf:
2699+
- $ref: '#/components/schemas/EntityBase'
2700+
properties:
2701+
$schema:
2702+
enum:
2703+
- ScopeActivity
2704+
type: string
2705+
copyActivitytt:
2706+
type: string
2707+
required:
2708+
- $schema
2709+
- copyActivitytt
2710+
type: object
2711+
EntityBase:
2712+
discriminator:
2713+
mapping:
2714+
ScopeActivity: '#/components/schemas/CopyActivity'
2715+
propertyName: $schema
2716+
properties:
2717+
$schema:
2718+
type: string
2719+
required:
2720+
- $schema
2721+
type: object
26972722
_foo_get_default_response:
26982723
example:
26992724
string:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Org.OpenAPITools.Model.CopyActivity
2+
3+
## Properties
4+
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**CopyActivitytt** | **string** | |
8+
**Schema** | **string** | | [default to SchemaEnum.ScopeActivity]
9+
10+
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Org.OpenAPITools.Model.EntityBase
2+
3+
## Properties
4+
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**Schema** | **string** | |
8+
9+
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
* The version of the OpenAPI document: 1.0.0
7+
* Generated by: https://github.com/openapitools/openapi-generator.git
8+
*/
9+
10+
11+
using Xunit;
12+
13+
using System;
14+
using System.Linq;
15+
using System.IO;
16+
using System.Collections.Generic;
17+
using Org.OpenAPITools.Model;
18+
using Org.OpenAPITools.Client;
19+
using System.Reflection;
20+
21+
namespace Org.OpenAPITools.Test.Model
22+
{
23+
/// <summary>
24+
/// Class for testing CopyActivity
25+
/// </summary>
26+
/// <remarks>
27+
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
28+
/// Please update the test case below to test the model.
29+
/// </remarks>
30+
public class CopyActivityTests : IDisposable
31+
{
32+
// TODO uncomment below to declare an instance variable for CopyActivity
33+
//private CopyActivity instance;
34+
35+
public CopyActivityTests()
36+
{
37+
// TODO uncomment below to create an instance of CopyActivity
38+
//instance = new CopyActivity();
39+
}
40+
41+
public void Dispose()
42+
{
43+
// Cleanup when everything is done.
44+
}
45+
46+
/// <summary>
47+
/// Test an instance of CopyActivity
48+
/// </summary>
49+
[Fact]
50+
public void CopyActivityInstanceTest()
51+
{
52+
// TODO uncomment below to test "IsType" CopyActivity
53+
//Assert.IsType<CopyActivity>(instance);
54+
}
55+
56+
/// <summary>
57+
/// Test the property 'CopyActivitytt'
58+
/// </summary>
59+
[Fact]
60+
public void CopyActivityttTest()
61+
{
62+
// TODO unit test for the property 'CopyActivitytt'
63+
}
64+
65+
/// <summary>
66+
/// Test the property 'Schema'
67+
/// </summary>
68+
[Fact]
69+
public void SchemaTest()
70+
{
71+
// TODO unit test for the property 'Schema'
72+
}
73+
}
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
* The version of the OpenAPI document: 1.0.0
7+
* Generated by: https://github.com/openapitools/openapi-generator.git
8+
*/
9+
10+
11+
using Xunit;
12+
13+
using System;
14+
using System.Linq;
15+
using System.IO;
16+
using System.Collections.Generic;
17+
using Org.OpenAPITools.Model;
18+
using Org.OpenAPITools.Client;
19+
using System.Reflection;
20+
21+
namespace Org.OpenAPITools.Test.Model
22+
{
23+
/// <summary>
24+
/// Class for testing EntityBase
25+
/// </summary>
26+
/// <remarks>
27+
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
28+
/// Please update the test case below to test the model.
29+
/// </remarks>
30+
public class EntityBaseTests : IDisposable
31+
{
32+
// TODO uncomment below to declare an instance variable for EntityBase
33+
//private EntityBase instance;
34+
35+
public EntityBaseTests()
36+
{
37+
// TODO uncomment below to create an instance of EntityBase
38+
//instance = new EntityBase();
39+
}
40+
41+
public void Dispose()
42+
{
43+
// Cleanup when everything is done.
44+
}
45+
46+
/// <summary>
47+
/// Test an instance of EntityBase
48+
/// </summary>
49+
[Fact]
50+
public void EntityBaseInstanceTest()
51+
{
52+
// TODO uncomment below to test "IsType" EntityBase
53+
//Assert.IsType<EntityBase>(instance);
54+
}
55+
56+
/// <summary>
57+
/// Test deserialize a CopyActivity from type EntityBase
58+
/// </summary>
59+
[Fact]
60+
public void CopyActivityDeserializeFromEntityBaseTest()
61+
{
62+
// TODO uncomment below to test deserialize a CopyActivity from type EntityBase
63+
//Assert.IsType<EntityBase>(JsonConvert.DeserializeObject<EntityBase>(new CopyActivity().ToJson()));
64+
}
65+
66+
/// <summary>
67+
/// Test the property 'Schema'
68+
/// </summary>
69+
[Fact]
70+
public void SchemaTest()
71+
{
72+
// TODO unit test for the property 'Schema'
73+
}
74+
}
75+
}

samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Client/ClientUtils.cs

+2
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ public static string ParameterToString(object obj, string format = ISO8601_DATET
169169
: "false";
170170
if (obj is ChildCatAllOfPetType childCatAllOfPetType)
171171
return ChildCatAllOfPetTypeValueConverter.ToJsonValue(childCatAllOfPetType);
172+
if (obj is CopyActivity.SchemaEnum copyActivitySchemaEnum)
173+
return CopyActivity.SchemaEnumToJsonValue(copyActivitySchemaEnum);
172174
if (obj is EnumArraysArrayEnumInner enumArraysArrayEnumInner)
173175
return EnumArraysArrayEnumInnerValueConverter.ToJsonValue(enumArraysArrayEnumInner);
174176
if (obj is EnumArraysJustSymbol enumArraysJustSymbol)

samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Client/HostConfiguration.cs

+2
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ public HostConfiguration(IServiceCollection services)
6060
_jsonOptions.Converters.Add(new ChildCatAllOfPetTypeNullableJsonConverter());
6161
_jsonOptions.Converters.Add(new ClassModelJsonConverter());
6262
_jsonOptions.Converters.Add(new ComplexQuadrilateralJsonConverter());
63+
_jsonOptions.Converters.Add(new CopyActivityJsonConverter());
6364
_jsonOptions.Converters.Add(new DanishPigJsonConverter());
6465
_jsonOptions.Converters.Add(new DateOnlyClassJsonConverter());
6566
_jsonOptions.Converters.Add(new DeprecatedObjectJsonConverter());
6667
_jsonOptions.Converters.Add(new DogJsonConverter());
6768
_jsonOptions.Converters.Add(new DrawingJsonConverter());
69+
_jsonOptions.Converters.Add(new EntityBaseJsonConverter());
6870
_jsonOptions.Converters.Add(new EnumArraysJsonConverter());
6971
_jsonOptions.Converters.Add(new EnumArraysArrayEnumInnerJsonConverter());
7072
_jsonOptions.Converters.Add(new EnumArraysArrayEnumInnerNullableJsonConverter());

0 commit comments

Comments
 (0)