Skip to content
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

[Go] [Abstractions] Untyped Nodes #149

Merged
merged 8 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

## [1.8.0] - 2024-02-29

### Added

- Added support for untyped nodes. (https://github.com/microsoft/kiota/pull/4095)

## [1.5.6] - 2024-01-18

### Changed
Expand Down
18 changes: 18 additions & 0 deletions serialization/untyped_array.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package serialization

// UntypedArray defines an untyped collection.
type UntypedArray struct {
UntypedNode
}

// GetValue returns a collection of UntypedNode.
func (un *UntypedArray) GetValue() []UntypedNodeable {
return un.value.([]UntypedNodeable)
}

// NewUntypedArray creates a new UntypedArray object.
func NewUntypedArray(collection []UntypedNodeable) *UntypedArray {
m := &UntypedArray{}
m.value = collection
return m
}
22 changes: 22 additions & 0 deletions serialization/untyped_boolean.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package serialization

// UntypedBoolean defines an untyped boolean object.
type UntypedBoolean struct {
UntypedNode
}

// GetValue returns the bool value.
func (un *UntypedBoolean) GetValue() *bool {
castValue, ok := un.value.(*bool)
if ok {
return castValue
}
return nil
}

// NewUntypedBoolean creates a new UntypedBoolean object.
func NewUntypedBoolean(boolValue bool) *UntypedBoolean {
m := &UntypedBoolean{}
m.value = &boolValue
return m
}
22 changes: 22 additions & 0 deletions serialization/untyped_double.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package serialization

// UntypedDouble defines an untyped float64 object.
type UntypedDouble struct {
UntypedNode
}

// GetValue returns the float64 value.
func (un *UntypedDouble) GetValue() *float64 {
castValue, ok := un.value.(*float64)
if ok {
return castValue
}
return nil
}

// NewUntypedDouble creates a new UntypedDouble object.
func NewUntypedDouble(float64Value float64) *UntypedDouble {
m := &UntypedDouble{}
m.value = &float64Value
return m
}
22 changes: 22 additions & 0 deletions serialization/untyped_float.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package serialization

// UntypedFloat defines an untyped float32 value.
type UntypedFloat struct {
UntypedNode
}

// GetValue returns the float32 value.
func (un *UntypedFloat) GetValue() *float32 {
castValue, ok := un.value.(*float32)
if ok {
return castValue
}
return nil
}

// NewUntypedFloat creates a new UntypedFloat object.
func NewUntypedFloat(float32Value float32) *UntypedFloat {
m := &UntypedFloat{}
m.value = &float32Value
return m
}
22 changes: 22 additions & 0 deletions serialization/untyped_integer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package serialization

// UntypedInteger defines an untyped integer value.
type UntypedInteger struct {
UntypedNode
}

// GetValue returns the int32 value.
func (un *UntypedInteger) GetValue() *int32 {
castValue, ok := un.value.(*int32)
if ok {
return castValue
}
return nil
}

// NewUntypedInteger creates a new UntypedInteger object.
func NewUntypedInteger(int32Value int32) *UntypedInteger {
m := &UntypedInteger{}
m.value = &int32Value
return m
}
22 changes: 22 additions & 0 deletions serialization/untyped_long.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package serialization

// UntypedLong defines an untyped int64 value.
type UntypedLong struct {
UntypedNode
}

// GetValue returns the int64 value.
func (un *UntypedLong) GetValue() *int64 {
castValue, ok := un.value.(*int64)
if ok {
return castValue
}
return nil
}

// NewUntypedLong creates a new UntypedLong object.
func NewUntypedLong(int64Value int64) *UntypedLong {
m := &UntypedLong{}
m.value = &int64Value
return m
}
44 changes: 44 additions & 0 deletions serialization/untyped_node.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package serialization

type UntypedNodeable interface {
Parsable
GetIsUntypedNode() bool
}

// Base model for an untyped object.
type UntypedNode struct {
value any
}

// GetIsUntypedNode returns true if the node is untyped, false otherwise.
func (m *UntypedNode) GetIsUntypedNode() bool {
return true
}

// GetValue gets the underlying object value.
func (m *UntypedNode) GetValue() any {
return m.value
}

// Serialize writes the objects properties to the current writer.
func (m *UntypedNode) Serialize(writer SerializationWriter) error {
// Serialize the entity
return nil
}

// GetFieldDeserializers returns the deserialization information for this object.
func (m *UntypedNode) GetFieldDeserializers() map[string]func(ParseNode) error {
return make(map[string]func(ParseNode) error)
}

// NewUntypedNode instantiates a new untyped node and sets the default values.
func NewUntypedNode(value any) *UntypedNode {
m := &UntypedNode{}
m.value = value
return m
}

// CreateUntypedNodeFromDiscriminatorValue a new untyped node and from a parse node.
func CreateUntypedNodeFromDiscriminatorValue(parseNode ParseNode) (Parsable, error) {
return NewUntypedNode(nil), nil
}
17 changes: 17 additions & 0 deletions serialization/untyped_null.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package serialization

// UntypedNull defines a untyped nil object.
type UntypedNull struct {
UntypedNode
}

// GetValue returns a nil value.
func (un *UntypedNull) GetValue() any {
return nil
}

// NewUntypedString creates a new UntypedNull object.
func NewUntypedNull() *UntypedNull {
m := &UntypedNull{}
return m
}
22 changes: 22 additions & 0 deletions serialization/untyped_object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package serialization

// UntypedObject defines an untyped object.
type UntypedObject struct {
UntypedNode
}

// GetValue gets a map of the properties of the object.
func (un *UntypedObject) GetValue() map[string]UntypedNodeable {
castValue, ok := un.value.(map[string]UntypedNodeable)
if ok {
return castValue
}
return nil
}

// NewUntypedObject creates a new UntypedObject object.
func NewUntypedObject(properties map[string]UntypedNodeable) *UntypedObject {
m := &UntypedObject{}
m.value = properties
return m
}
22 changes: 22 additions & 0 deletions serialization/untyped_string.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package serialization

// UntypedString defines an untyped string object.
type UntypedString struct {
UntypedNode
}

// GetValue returns the string object.
func (un *UntypedString) GetValue() *string {
castValue, ok := un.value.(*string)
if ok {
return castValue
}
return nil
}

// NewUntypedString creates a new UntypedString object.
func NewUntypedString(stringValue string) *UntypedString {
m := &UntypedString{}
m.value = &stringValue
return m
}
Loading