Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[csharp][generichost] Fixes de/serialization #20540

Merged
merged 2 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

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

{{/children}}
{{/discriminator}}
Expand Down Expand Up @@ -348,7 +348,7 @@
{{#discriminator}}
{{#children}}
if ({{#lambda.paste}}{{/lambda.paste}} is {{classname}} {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}){
JsonSerializer.Serialize<{{{name}}}>(writer, {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}, jsonSerializerOptions);
JsonSerializer.Serialize<{{{classname}}}>(writer, {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}, jsonSerializerOptions);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2938,3 +2938,28 @@ components:
uuid:
type: string
format: uuid
CopyActivity:
type: object
required:
- $schema
- copyActivitytt
properties:
$schema:
type: string
enum:
- ScopeActivity
copyActivitytt:
type: string
allOf:
- $ref: '#/components/schemas/EntityBase'
EntityBase:
type: object
required:
- $schema
properties:
$schema:
type: string
discriminator:
propertyName: $schema
mapping:
ScopeActivity: '#/components/schemas/CopyActivity'
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ docs/models/ChildCat.md
docs/models/ChildCatAllOfPetType.md
docs/models/ClassModel.md
docs/models/ComplexQuadrilateral.md
docs/models/CopyActivity.md
docs/models/DanishPig.md
docs/models/DateOnlyClass.md
docs/models/DeprecatedObject.md
docs/models/Dog.md
docs/models/Drawing.md
docs/models/EntityBase.md
docs/models/EnumArrays.md
docs/models/EnumArraysArrayEnumInner.md
docs/models/EnumArraysJustSymbol.md
Expand Down Expand Up @@ -187,11 +189,13 @@ src/Org.OpenAPITools/Model/ChildCat.cs
src/Org.OpenAPITools/Model/ChildCatAllOfPetType.cs
src/Org.OpenAPITools/Model/ClassModel.cs
src/Org.OpenAPITools/Model/ComplexQuadrilateral.cs
src/Org.OpenAPITools/Model/CopyActivity.cs
src/Org.OpenAPITools/Model/DanishPig.cs
src/Org.OpenAPITools/Model/DateOnlyClass.cs
src/Org.OpenAPITools/Model/DeprecatedObject.cs
src/Org.OpenAPITools/Model/Dog.cs
src/Org.OpenAPITools/Model/Drawing.cs
src/Org.OpenAPITools/Model/EntityBase.cs
src/Org.OpenAPITools/Model/EnumArrays.cs
src/Org.OpenAPITools/Model/EnumArraysArrayEnumInner.cs
src/Org.OpenAPITools/Model/EnumArraysJustSymbol.cs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2694,6 +2694,31 @@ components:
uuid:
format: uuid
type: string
CopyActivity:
allOf:
- $ref: '#/components/schemas/EntityBase'
properties:
$schema:
enum:
- ScopeActivity
type: string
copyActivitytt:
type: string
required:
- $schema
- copyActivitytt
type: object
EntityBase:
discriminator:
mapping:
ScopeActivity: '#/components/schemas/CopyActivity'
propertyName: $schema
properties:
$schema:
type: string
required:
- $schema
type: object
_foo_get_default_response:
example:
string:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Org.OpenAPITools.Model.CopyActivity

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**CopyActivitytt** | **string** | |
**Schema** | **string** | | [default to SchemaEnum.ScopeActivity]

[[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,10 @@
# Org.OpenAPITools.Model.EntityBase

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Schema** | **string** | |

[[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,74 @@
/*
* 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;

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

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

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

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

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

/// <summary>
/// Test the property 'Schema'
/// </summary>
[Fact]
public void SchemaTest()
{
// TODO unit test for the property 'Schema'
}
}
}
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;

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

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

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

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

/// <summary>
/// Test deserialize a CopyActivity from type EntityBase
/// </summary>
[Fact]
public void CopyActivityDeserializeFromEntityBaseTest()
{
// TODO uncomment below to test deserialize a CopyActivity from type EntityBase
//Assert.IsType<EntityBase>(JsonConvert.DeserializeObject<EntityBase>(new CopyActivity().ToJson()));
}

/// <summary>
/// Test the property 'Schema'
/// </summary>
[Fact]
public void SchemaTest()
{
// TODO unit test for the property 'Schema'
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ public static string ParameterToString(object obj, string format = ISO8601_DATET
: "false";
if (obj is ChildCatAllOfPetType childCatAllOfPetType)
return ChildCatAllOfPetTypeValueConverter.ToJsonValue(childCatAllOfPetType);
if (obj is CopyActivity.SchemaEnum copyActivitySchemaEnum)
return CopyActivity.SchemaEnumToJsonValue(copyActivitySchemaEnum);
if (obj is EnumArraysArrayEnumInner enumArraysArrayEnumInner)
return EnumArraysArrayEnumInnerValueConverter.ToJsonValue(enumArraysArrayEnumInner);
if (obj is EnumArraysJustSymbol enumArraysJustSymbol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ public HostConfiguration(IServiceCollection services)
_jsonOptions.Converters.Add(new ChildCatAllOfPetTypeNullableJsonConverter());
_jsonOptions.Converters.Add(new ClassModelJsonConverter());
_jsonOptions.Converters.Add(new ComplexQuadrilateralJsonConverter());
_jsonOptions.Converters.Add(new CopyActivityJsonConverter());
_jsonOptions.Converters.Add(new DanishPigJsonConverter());
_jsonOptions.Converters.Add(new DateOnlyClassJsonConverter());
_jsonOptions.Converters.Add(new DeprecatedObjectJsonConverter());
_jsonOptions.Converters.Add(new DogJsonConverter());
_jsonOptions.Converters.Add(new DrawingJsonConverter());
_jsonOptions.Converters.Add(new EntityBaseJsonConverter());
_jsonOptions.Converters.Add(new EnumArraysJsonConverter());
_jsonOptions.Converters.Add(new EnumArraysArrayEnumInnerJsonConverter());
_jsonOptions.Converters.Add(new EnumArraysArrayEnumInnerNullableJsonConverter());
Expand Down
Loading
Loading