Skip to content

Commit

Permalink
Merge pull request #95 from microsoft/feature/composed-types
Browse files Browse the repository at this point in the history
feature/composed types
  • Loading branch information
baywet committed Jun 29, 2023
2 parents f8a5f7c + 1075cfe commit 4524db0
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

## [1.0.3] - 2023-06-28

### Changed

- Fixes serialization of composed types for scalar values.

## [1.0.2] - 2023-06-14

- Safely serialize null values in collections of Objects, Enums or primitives.
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/google/uuid v1.3.0
github.com/microsoft/kiota-abstractions-go v1.0.0
github.com/microsoft/kiota-abstractions-go v1.1.0
github.com/stretchr/testify v1.8.4
)

Expand All @@ -16,7 +16,8 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
go.opentelemetry.io/otel v1.15.1 // indirect
go.opentelemetry.io/otel/trace v1.15.1 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/microsoft/kiota-abstractions-go v1.0.0 h1:teQS3yOmcTyps+O48AD17LI8TR1B3wCEwGFcwC6K75c=
github.com/microsoft/kiota-abstractions-go v1.0.0/go.mod h1:2yaRQnx2KU7UaenYSApiTT4pf7fFkPV0B71Rm2uYynQ=
github.com/microsoft/kiota-abstractions-go v1.1.0 h1:X1aKlsYCRs/0RSChr/fbq4j/+kxRzbSY5GeWhtHQNYI=
github.com/microsoft/kiota-abstractions-go v1.1.0/go.mod h1:RkxyZ5x87Njik7iVeQY9M2wtrrL1MJZcXiI/BxD/82g=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
go.opentelemetry.io/otel v1.15.1 h1:3Iwq3lfRByPaws0f6bU3naAqOR1n5IeDWd9390kWHa8=
go.opentelemetry.io/otel v1.15.1/go.mod h1:mHHGEHVDLal6YrKMmk9LqC4a3sF5g+fHfrttQIB1NTc=
go.opentelemetry.io/otel/trace v1.15.1 h1:uXLo6iHJEzDfrNC0L0mNjItIp06SyaBQxu5t3xMlngY=
go.opentelemetry.io/otel/trace v1.15.1/go.mod h1:IWdQG/5N1x7f6YUlmdLeJvH9yxtuJAfc4VW5Agv9r/8=
go.opentelemetry.io/otel v1.16.0 h1:Z7GVAX/UkAXPKsy94IU+i6thsQS4nb7LviLpnaNeW8s=
go.opentelemetry.io/otel v1.16.0/go.mod h1:vl0h9NUa1D5s1nv3A5vZOYWn8av4K8Ml6JDeHrT/bx4=
go.opentelemetry.io/otel/metric v1.16.0 h1:RbrpwVG1Hfv85LgnZ7+txXioPDoh6EdbZHo26Q3hqOo=
go.opentelemetry.io/otel/metric v1.16.0/go.mod h1:QE47cpOmkwipPiefDwo2wDzwJrlfxxNYodqc4xnGCo4=
go.opentelemetry.io/otel/trace v1.16.0 h1:8JRpaObFoW0pxuVPapkgH8UhHQj+bJW8jJsCZEu5MQs=
go.opentelemetry.io/otel/trace v1.16.0/go.mod h1:Yt9vYq1SdNz3xdjZZK7wcXv1qv2pwLkqr2QVwea0ef0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
3 changes: 3 additions & 0 deletions internal/intersection_type_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@ func (e *IntersectionTypeMock) Serialize(writer absser.SerializationWriter) erro
return writer.WriteObjectValue("", e.GetComposedType1(), e.GetComposedType2())
}
}
func (e *IntersectionTypeMock) GetIsComposedType() bool {
return true
}
4 changes: 4 additions & 0 deletions internal/union_type_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,7 @@ func (e *UnionTypeMock) Serialize(writer absser.SerializationWriter) error {
}
return nil
}

func (e *UnionTypeMock) GetIsComposedType() bool {
return true
}
6 changes: 3 additions & 3 deletions intersection_type_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestItSerializesIntersectionTypeComplexProperty1(t *testing.T) {
source.SetComposedType1(prop1Value)
source.SetComposedType2(prop2Value)
writer := NewJsonSerializationWriter()
err := source.Serialize(writer)
err := writer.WriteObjectValue("", source)
if err != nil {
t.Error(err)
}
Expand All @@ -133,7 +133,7 @@ func TestItSerializesIntersectionTypeComplexProperty2(t *testing.T) {
prop2Value.SetId(&idValue)
source.SetComposedType2(prop2Value)
writer := NewJsonSerializationWriter()
err := source.Serialize(writer)
err := writer.WriteObjectValue("", source)
if err != nil {
t.Error(err)
}
Expand All @@ -159,7 +159,7 @@ func TestItSerializesIntersectionTypeComplexProperty(t *testing.T) {
prop3Value2.SetOfficeLocation(&officeLocationValue2)
source.SetComposedType3([]internal.TestEntityable{prop3Value1, prop3Value2})
writer := NewJsonSerializationWriter()
err := source.Serialize(writer)
err := writer.WriteObjectValue("", source)
if err != nil {
t.Error(err)
}
Expand Down
9 changes: 7 additions & 2 deletions json_serialization_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,10 @@ func (w *JsonSerializationWriter) WriteObjectValue(key string, item absser.Parsa
w.writePropertyName(key)
}
abstractions.InvokeParsableAction(w.GetOnBeforeSerialization(), item)
w.writeObjectStart()
_, isComposedTypeWrapper := item.(absser.ComposedTypeWrapper)
if !isComposedTypeWrapper {
w.writeObjectStart()
}
if item != nil {
err := abstractions.InvokeParsableWriter(w.GetOnStartObjectSerialization(), item, w)
if err != nil {
Expand All @@ -291,7 +294,9 @@ func (w *JsonSerializationWriter) WriteObjectValue(key string, item absser.Parsa
abstractions.InvokeParsableAction(w.GetOnAfterObjectSerialization(), additionalValue)
}

w.writeObjectEnd()
if !isComposedTypeWrapper {
w.writeObjectEnd()
}
if key != "" {
w.writePropertySeparator()
}
Expand Down
8 changes: 4 additions & 4 deletions union_type_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestItSerializesUnionTypeStringValue(t *testing.T) {
source := internal.NewUnionTypeMock()
source.SetStringValue(&value)
writer := NewJsonSerializationWriter()
err := source.Serialize(writer)
err := writer.WriteObjectValue("", source)
if err != nil {
t.Error(err)
}
Expand All @@ -129,7 +129,7 @@ func TestItSerializesUnionTypeComplexProperty1(t *testing.T) {
source.SetComposedType1(prop1Value)
source.SetComposedType2(prop2Value)
writer := NewJsonSerializationWriter()
err := source.Serialize(writer)
err := writer.WriteObjectValue("", source)
if err != nil {
t.Error(err)
}
Expand All @@ -150,7 +150,7 @@ func TestItSerializesUnionTypeComplexProperty2(t *testing.T) {
prop2Value.SetDisplayName(&displayNameValue)
source.SetComposedType2(prop2Value)
writer := NewJsonSerializationWriter()
err := source.Serialize(writer)
err := writer.WriteObjectValue("", source)
if err != nil {
t.Error(err)
}
Expand All @@ -176,7 +176,7 @@ func TestItSerializesUnionTypeComplexProperty3(t *testing.T) {
prop3Value2.SetOfficeLocation(&officeLocationValue2)
source.SetComposedType3([]internal.TestEntityable{prop3Value1, prop3Value2})
writer := NewJsonSerializationWriter()
err := source.Serialize(writer)
err := writer.WriteObjectValue("", source)
if err != nil {
t.Error(err)
}
Expand Down

0 comments on commit 4524db0

Please sign in to comment.