Skip to content

Commit

Permalink
- moves discriminator prop name to code method
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
  • Loading branch information
baywet committed Feb 10, 2022
1 parent d250a70 commit 8a9b9f6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
7 changes: 1 addition & 6 deletions src/Kiota.Builder/CodeDOM/CodeClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ public CodeClass():base()

public bool IsErrorDefinition { get; set; }

public string Description {get; set;}

/// <summary>
/// Gets/Sets the name of the property to use for discrimination during deserialization.
/// </summary>
public string DiscriminatorPropertyName { get; set; }
public string Description {get; set;}
/// <summary>
/// Name of Class
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions src/Kiota.Builder/CodeDOM/CodeMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ public bool IsSerializationMethod {
/// Gets/Sets the discriminator values for the class where the key is the value as represented in the payload.
/// </summary>
public Dictionary<string, CodeTypeBase> DiscriminatorMappings { get; set; } = new();
/// <summary>
/// Gets/Sets the name of the property to use for discrimination during deserialization.
/// </summary>
public string DiscriminatorPropertyName { get; set; }

public object Clone()
{
Expand All @@ -118,6 +122,7 @@ public object Clone()
OriginalIndexer = OriginalIndexer,
ErrorMappings = ErrorMappings == null ? null : new (ErrorMappings),
DiscriminatorMappings = DiscriminatorMappings == null ? null : new (DiscriminatorMappings),
DiscriminatorPropertyName = DiscriminatorPropertyName?.Clone() as string
};
if(Parameters?.Any() ?? false)
method.AddParameter(Parameters.Select(x => x.Clone() as CodeParameter).ToArray());
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/KiotaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,6 @@ private CodeClass AddModelClass(OpenApiUrlTreeNode currentNode, OpenApiSchema sc
var declaration = newClass.StartBlock as CodeClass.Declaration;
declaration.Inherits = new CodeType { TypeDefinition = inheritsFrom, Name = inheritsFrom.Name };
}
newClass.DiscriminatorPropertyName = schema.Discriminator?.PropertyName;
var factoryMethod = newClass.AddMethod(new CodeMethod {
Name = "Create",
ReturnType = new CodeType { TypeDefinition = newClass, Name = newClass.Name },
Expand All @@ -849,6 +848,7 @@ private CodeClass AddModelClass(OpenApiUrlTreeNode currentNode, OpenApiSchema sc
Optional = false,
Type = new CodeType { Name = ParseNodeInterface, IsExternal = true },
});
factoryMethod.DiscriminatorPropertyName = schema.Discriminator?.PropertyName;
if(schema.Discriminator?.Mapping?.Any() ?? false)
factoryMethod.DiscriminatorMappings = schema.Discriminator
.Mapping
Expand Down

0 comments on commit 8a9b9f6

Please sign in to comment.