Skip to content

Commit 4524db0

Browse files
authored
Merge pull request #95 from microsoft/feature/composed-types
feature/composed types
2 parents f8a5f7c + 1075cfe commit 4524db0

File tree

8 files changed

+39
-18
lines changed

8 files changed

+39
-18
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Changed
1111

12+
## [1.0.3] - 2023-06-28
13+
14+
### Changed
15+
16+
- Fixes serialization of composed types for scalar values.
17+
1218
## [1.0.2] - 2023-06-14
1319

1420
- Safely serialize null values in collections of Objects, Enums or primitives.

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.18
44

55
require (
66
github.com/google/uuid v1.3.0
7-
github.com/microsoft/kiota-abstractions-go v1.0.0
7+
github.com/microsoft/kiota-abstractions-go v1.1.0
88
github.com/stretchr/testify v1.8.4
99
)
1010

@@ -16,7 +16,8 @@ require (
1616
github.com/kr/text v0.2.0 // indirect
1717
github.com/pmezard/go-difflib v1.0.0 // indirect
1818
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
19-
go.opentelemetry.io/otel v1.15.1 // indirect
20-
go.opentelemetry.io/otel/trace v1.15.1 // indirect
19+
go.opentelemetry.io/otel v1.16.0 // indirect
20+
go.opentelemetry.io/otel/metric v1.16.0 // indirect
21+
go.opentelemetry.io/otel/trace v1.16.0 // indirect
2122
gopkg.in/yaml.v3 v3.0.1 // indirect
2223
)

go.sum

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,20 @@ github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
1414
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
1515
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
1616
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
17-
github.com/microsoft/kiota-abstractions-go v1.0.0 h1:teQS3yOmcTyps+O48AD17LI8TR1B3wCEwGFcwC6K75c=
18-
github.com/microsoft/kiota-abstractions-go v1.0.0/go.mod h1:2yaRQnx2KU7UaenYSApiTT4pf7fFkPV0B71Rm2uYynQ=
17+
github.com/microsoft/kiota-abstractions-go v1.1.0 h1:X1aKlsYCRs/0RSChr/fbq4j/+kxRzbSY5GeWhtHQNYI=
18+
github.com/microsoft/kiota-abstractions-go v1.1.0/go.mod h1:RkxyZ5x87Njik7iVeQY9M2wtrrL1MJZcXiI/BxD/82g=
1919
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2020
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
2121
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
2222
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
2323
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
2424
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
25-
go.opentelemetry.io/otel v1.15.1 h1:3Iwq3lfRByPaws0f6bU3naAqOR1n5IeDWd9390kWHa8=
26-
go.opentelemetry.io/otel v1.15.1/go.mod h1:mHHGEHVDLal6YrKMmk9LqC4a3sF5g+fHfrttQIB1NTc=
27-
go.opentelemetry.io/otel/trace v1.15.1 h1:uXLo6iHJEzDfrNC0L0mNjItIp06SyaBQxu5t3xMlngY=
28-
go.opentelemetry.io/otel/trace v1.15.1/go.mod h1:IWdQG/5N1x7f6YUlmdLeJvH9yxtuJAfc4VW5Agv9r/8=
25+
go.opentelemetry.io/otel v1.16.0 h1:Z7GVAX/UkAXPKsy94IU+i6thsQS4nb7LviLpnaNeW8s=
26+
go.opentelemetry.io/otel v1.16.0/go.mod h1:vl0h9NUa1D5s1nv3A5vZOYWn8av4K8Ml6JDeHrT/bx4=
27+
go.opentelemetry.io/otel/metric v1.16.0 h1:RbrpwVG1Hfv85LgnZ7+txXioPDoh6EdbZHo26Q3hqOo=
28+
go.opentelemetry.io/otel/metric v1.16.0/go.mod h1:QE47cpOmkwipPiefDwo2wDzwJrlfxxNYodqc4xnGCo4=
29+
go.opentelemetry.io/otel/trace v1.16.0 h1:8JRpaObFoW0pxuVPapkgH8UhHQj+bJW8jJsCZEu5MQs=
30+
go.opentelemetry.io/otel/trace v1.16.0/go.mod h1:Yt9vYq1SdNz3xdjZZK7wcXv1qv2pwLkqr2QVwea0ef0=
2931
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
3032
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
3133
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

internal/intersection_type_mock.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,6 @@ func (e *IntersectionTypeMock) Serialize(writer absser.SerializationWriter) erro
9292
return writer.WriteObjectValue("", e.GetComposedType1(), e.GetComposedType2())
9393
}
9494
}
95+
func (e *IntersectionTypeMock) GetIsComposedType() bool {
96+
return true
97+
}

internal/union_type_mock.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,7 @@ func (e *UnionTypeMock) Serialize(writer absser.SerializationWriter) error {
112112
}
113113
return nil
114114
}
115+
116+
func (e *UnionTypeMock) GetIsComposedType() bool {
117+
return true
118+
}

intersection_type_wrapper_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func TestItSerializesIntersectionTypeComplexProperty1(t *testing.T) {
112112
source.SetComposedType1(prop1Value)
113113
source.SetComposedType2(prop2Value)
114114
writer := NewJsonSerializationWriter()
115-
err := source.Serialize(writer)
115+
err := writer.WriteObjectValue("", source)
116116
if err != nil {
117117
t.Error(err)
118118
}
@@ -133,7 +133,7 @@ func TestItSerializesIntersectionTypeComplexProperty2(t *testing.T) {
133133
prop2Value.SetId(&idValue)
134134
source.SetComposedType2(prop2Value)
135135
writer := NewJsonSerializationWriter()
136-
err := source.Serialize(writer)
136+
err := writer.WriteObjectValue("", source)
137137
if err != nil {
138138
t.Error(err)
139139
}
@@ -159,7 +159,7 @@ func TestItSerializesIntersectionTypeComplexProperty(t *testing.T) {
159159
prop3Value2.SetOfficeLocation(&officeLocationValue2)
160160
source.SetComposedType3([]internal.TestEntityable{prop3Value1, prop3Value2})
161161
writer := NewJsonSerializationWriter()
162-
err := source.Serialize(writer)
162+
err := writer.WriteObjectValue("", source)
163163
if err != nil {
164164
t.Error(err)
165165
}

json_serialization_writer.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,10 @@ func (w *JsonSerializationWriter) WriteObjectValue(key string, item absser.Parsa
264264
w.writePropertyName(key)
265265
}
266266
abstractions.InvokeParsableAction(w.GetOnBeforeSerialization(), item)
267-
w.writeObjectStart()
267+
_, isComposedTypeWrapper := item.(absser.ComposedTypeWrapper)
268+
if !isComposedTypeWrapper {
269+
w.writeObjectStart()
270+
}
268271
if item != nil {
269272
err := abstractions.InvokeParsableWriter(w.GetOnStartObjectSerialization(), item, w)
270273
if err != nil {
@@ -291,7 +294,9 @@ func (w *JsonSerializationWriter) WriteObjectValue(key string, item absser.Parsa
291294
abstractions.InvokeParsableAction(w.GetOnAfterObjectSerialization(), additionalValue)
292295
}
293296

294-
w.writeObjectEnd()
297+
if !isComposedTypeWrapper {
298+
w.writeObjectEnd()
299+
}
295300
if key != "" {
296301
w.writePropertySeparator()
297302
}

union_type_wrapper_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func TestItSerializesUnionTypeStringValue(t *testing.T) {
102102
source := internal.NewUnionTypeMock()
103103
source.SetStringValue(&value)
104104
writer := NewJsonSerializationWriter()
105-
err := source.Serialize(writer)
105+
err := writer.WriteObjectValue("", source)
106106
if err != nil {
107107
t.Error(err)
108108
}
@@ -129,7 +129,7 @@ func TestItSerializesUnionTypeComplexProperty1(t *testing.T) {
129129
source.SetComposedType1(prop1Value)
130130
source.SetComposedType2(prop2Value)
131131
writer := NewJsonSerializationWriter()
132-
err := source.Serialize(writer)
132+
err := writer.WriteObjectValue("", source)
133133
if err != nil {
134134
t.Error(err)
135135
}
@@ -150,7 +150,7 @@ func TestItSerializesUnionTypeComplexProperty2(t *testing.T) {
150150
prop2Value.SetDisplayName(&displayNameValue)
151151
source.SetComposedType2(prop2Value)
152152
writer := NewJsonSerializationWriter()
153-
err := source.Serialize(writer)
153+
err := writer.WriteObjectValue("", source)
154154
if err != nil {
155155
t.Error(err)
156156
}
@@ -176,7 +176,7 @@ func TestItSerializesUnionTypeComplexProperty3(t *testing.T) {
176176
prop3Value2.SetOfficeLocation(&officeLocationValue2)
177177
source.SetComposedType3([]internal.TestEntityable{prop3Value1, prop3Value2})
178178
writer := NewJsonSerializationWriter()
179-
err := source.Serialize(writer)
179+
err := writer.WriteObjectValue("", source)
180180
if err != nil {
181181
t.Error(err)
182182
}

0 commit comments

Comments
 (0)