Skip to content

Commit 1c2ddde

Browse files
authored
Merge pull request #144 from microsoft/bugfix/prefixed-properties
bugfix/prefixed properties
2 parents 1483450 + 7a0f701 commit 1c2ddde

File tree

7 files changed

+11
-7
lines changed

7 files changed

+11
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- Deterministic ordering of properties/methods/indexers/subclasses
1616
- Deterministic import of sub path request builders
1717
- Stopped generating phantom indexer methods for TypeScript and Java
18+
- Fixed a bug where prefixed properties would be missing their prefix for serialization
1819

1920
## [0.0.3] - 2021-04-25
2021

samples

Submodule samples updated 48 files

src/Kiota.Builder/CodeDOM/CodeProperty.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ public CodeProperty(CodeElement parent): base(parent)
2222
public CodeTypeBase Type {get;set;}
2323
public string DefaultValue {get;set;}
2424
public string Description {get; set;}
25+
public string SerializationName { get; set; }
2526
}
2627
}

src/Kiota.Builder/KiotaBuilder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@ private CodeProperty CreateProperty(string childIdentifier, string childType, Co
403403
PropertyKind = kind,
404404
Description = typeSchema?.Description,
405405
};
406+
if(propertyName != childIdentifier)
407+
prop.SerializationName = childIdentifier;
406408
var typeName = childType;
407409
var isExternal = false;
408410
if("string".Equals(typeName, StringComparison.OrdinalIgnoreCase) && "date-time".Equals(typeSchema?.Format, StringComparison.OrdinalIgnoreCase)) {

src/Kiota.Builder/Writers/CSharpWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public override void WriteProperty(CodeProperty code)
8686
.OrderBy(x => x.Name)) {
8787
WriteLine("{");
8888
IncreaseIndent();
89-
WriteLine($"\"{otherProp.Name.ToFirstCharacterLowerCase()}\", (o,n) => {{ o.{otherProp.Name.ToFirstCharacterUpperCase()} = n.{GetDeserializationMethodName(otherProp.Type)}(); }}");
89+
WriteLine($"\"{otherProp.SerializationName ?? otherProp.Name.ToFirstCharacterLowerCase()}\", (o,n) => {{ o.{otherProp.Name.ToFirstCharacterUpperCase()} = n.{GetDeserializationMethodName(otherProp.Type)}(); }}");
9090
DecreaseIndent();
9191
WriteLine("},");
9292
}
@@ -216,7 +216,7 @@ public override void WriteMethod(CodeMethod code)
216216
.OfType<CodeProperty>()
217217
.Where(x => x.PropertyKind == CodePropertyKind.Custom)
218218
.OrderBy(x => x.Name)) {
219-
WriteLine($"writer.{GetSerializationMethodName(otherProp.Type)}(\"{otherProp.Name.ToFirstCharacterLowerCase()}\", {otherProp.Name.ToFirstCharacterUpperCase()});");
219+
WriteLine($"writer.{GetSerializationMethodName(otherProp.Type)}(\"{otherProp.SerializationName ?? otherProp.Name.ToFirstCharacterLowerCase()}\", {otherProp.Name.ToFirstCharacterUpperCase()});");
220220
}
221221
if(additionalDataProperty != null)
222222
WriteLine($"writer.WriteAdditionalData({additionalDataProperty.Name});");

src/Kiota.Builder/Writers/JavaWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public override void WriteMethod(CodeMethod code)
143143
.OfType<CodeProperty>()
144144
.Where(x => x.PropertyKind == CodePropertyKind.Custom)
145145
.OrderBy(x => x.Name)) {
146-
WriteLine($"writer.{GetSerializationMethodName(otherProp.Type)}(\"{otherProp.Name.ToFirstCharacterLowerCase()}\", {otherProp.Name.ToFirstCharacterLowerCase()});");
146+
WriteLine($"writer.{GetSerializationMethodName(otherProp.Type)}(\"{otherProp.SerializationName ?? otherProp.Name.ToFirstCharacterLowerCase()}\", {otherProp.Name.ToFirstCharacterLowerCase()});");
147147
}
148148
if(additionalDataProperty != null)
149149
WriteLine($"writer.writeAdditionalData(this.{additionalDataProperty.Name.ToFirstCharacterLowerCase()});");
@@ -159,7 +159,7 @@ public override void WriteMethod(CodeMethod code)
159159
fieldToSerialize
160160
.OrderBy(x => x.Name)
161161
.Select(x =>
162-
$"fields.put(\"{x.Name.ToFirstCharacterLowerCase()}\", (o, n) -> {{ (({parentClass.Name.ToFirstCharacterUpperCase()})o).{x.Name.ToFirstCharacterLowerCase()} = {GetDeserializationMethodName(x.Type)}; }});")
162+
$"fields.put(\"{x.SerializationName ?? x.Name.ToFirstCharacterLowerCase()}\", (o, n) -> {{ (({parentClass.Name.ToFirstCharacterUpperCase()})o).{x.Name.ToFirstCharacterLowerCase()} = {GetDeserializationMethodName(x.Type)}; }});")
163163
.ToList()
164164
.ForEach(x => WriteLine(x));
165165
WriteLine("return fields;");

src/Kiota.Builder/Writers/TypeScriptWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public override void WriteMethod(CodeMethod code)
283283
.OfType<CodeProperty>()
284284
.Where(x => x.PropertyKind == CodePropertyKind.Custom)
285285
.OrderBy(x => x.Name)) {
286-
WriteLine($"[\"{otherProp.Name.ToFirstCharacterLowerCase()}\", (o, n) => {{ o.{otherProp.Name.ToFirstCharacterLowerCase()} = n.{GetDeserializationMethodName(otherProp.Type)}; }}],");
286+
WriteLine($"[\"{otherProp.SerializationName ?? otherProp.Name.ToFirstCharacterLowerCase()}\", (o, n) => {{ o.{otherProp.Name.ToFirstCharacterLowerCase()} = n.{GetDeserializationMethodName(otherProp.Type)}; }}],");
287287
}
288288
DecreaseIndent();
289289
WriteLine("]);");
@@ -297,7 +297,7 @@ public override void WriteMethod(CodeMethod code)
297297
.OfType<CodeProperty>()
298298
.Where(x => x.PropertyKind == CodePropertyKind.Custom)
299299
.OrderBy(x => x.Name)) {
300-
WriteLine($"writer.{GetSerializationMethodName(otherProp.Type)}(\"{otherProp.Name.ToFirstCharacterLowerCase()}\", this.{otherProp.Name.ToFirstCharacterLowerCase()});");
300+
WriteLine($"writer.{GetSerializationMethodName(otherProp.Type)}(\"{otherProp.SerializationName ?? otherProp.Name.ToFirstCharacterLowerCase()}\", this.{otherProp.Name.ToFirstCharacterLowerCase()});");
301301
}
302302
if(additionalDataProperty != null)
303303
WriteLine($"writer.writeAdditionalData(this.{additionalDataProperty.Name.ToFirstCharacterLowerCase()});");

0 commit comments

Comments
 (0)