-
Notifications
You must be signed in to change notification settings - Fork 221
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
[C#] Bug: OneOf used inside other OneOf causes duplicated fields in composed type #4478
Comments
Looks very similar, @fzzle any chance you can test using Kiota from my branch ( https://github.com/andreaTP/kiota/tree/initial-fixes-simple-oneOf-py ) with the fixes or from this (non-official)"pre-release" which includes the fixes: https://github.com/andreaTP/kiota-prerelease/releases/tag/v0.0.0-pre%2BandreaTP.initial-fixes-simple-oneOf-py.b46369a |
Hi @andrueastman and @andreaTP, Thanks for the swift reply. I've tested your branch and I can see that it solves the problem. The model now looks like this. // <auto-generated/>
using Microsoft.Kiota.Abstractions.Serialization;
using Microsoft.Kiota.Abstractions;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System;
namespace Namespace.Models {
/// <summary>
/// Composed type wrapper for classes <see cref="ElementModel1"/>, <see cref="ElementModel2"/>
/// </summary>
public class ElementModelBase : IComposedTypeWrapper, IParsable
{
/// <summary>Composed type representation for type <see cref="Namespace.Models.ElementModel1"/></summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public Namespace.Models.ElementModel1? ElementModel1 { get; set; }
#nullable restore
#else
public Namespace.Models.ElementModel1 ElementModel1 { get; set; }
#endif
/// <summary>Composed type representation for type <see cref="Namespace.Models.ElementModel2"/></summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public Namespace.Models.ElementModel2? ElementModel2 { get; set; }
#nullable restore
#else
public Namespace.Models.ElementModel2 ElementModel2 { get; set; }
#endif
/// <summary>
/// Creates a new instance of the appropriate class based on discriminator value
/// </summary>
/// <returns>A <see cref="ElementModelBase"/></returns>
/// <param name="parseNode">The parse node to use to read the discriminator value and create the object</param>
public static ElementModelBase CreateFromDiscriminatorValue(IParseNode parseNode)
{
_ = parseNode ?? throw new ArgumentNullException(nameof(parseNode));
var mappingValue = parseNode.GetChildNode("contentType")?.GetStringValue();
var result = new ElementModelBase();
if("c".Equals(mappingValue, StringComparison.OrdinalIgnoreCase))
{
result.ElementModel1 = new Namespace.Models.ElementModel1();
}
else if("d".Equals(mappingValue, StringComparison.OrdinalIgnoreCase))
{
result.ElementModel2 = new Namespace.Models.ElementModel2();
}
return result;
}
/// <summary>
/// The deserialization information for the current model
/// </summary>
/// <returns>A IDictionary<string, Action<IParseNode>></returns>
public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers()
{
if(ElementModel1 != null)
{
return ElementModel1.GetFieldDeserializers();
}
else if(ElementModel2 != null)
{
return ElementModel2.GetFieldDeserializers();
}
return new Dictionary<string, Action<IParseNode>>();
}
/// <summary>
/// Serializes information the current object
/// </summary>
/// <param name="writer">Serialization writer to use to serialize this model</param>
public virtual void Serialize(ISerializationWriter writer)
{
_ = writer ?? throw new ArgumentNullException(nameof(writer));
if(ElementModel1 != null)
{
writer.WriteObjectValue<Namespace.Models.ElementModel1>(null, ElementModel1);
}
else if(ElementModel2 != null)
{
writer.WriteObjectValue<Namespace.Models.ElementModel2>(null, ElementModel2);
}
}
}
} |
Checked and the problem is still present. |
I'm looking forward to this being fixed. |
cc. @baywet just to be sure that this is under your radar |
This also happens to be resolved with #5657 |
When I generate a client with the following schemas (a OneOf within a OneOf) it duplicates the properties for inner OneOf model.
This is an example of the input I give to Kiota:
And this is the generated ElementModelBase:
Generated using:
The text was updated successfully, but these errors were encountered: