REST API: use byte array for E2SM event trigger 41/6241/1 v0.8.3
authorMohamed Abukar <abukar.mohamed@nokia.com>
Mon, 7 Jun 2021 06:24:16 +0000 (06:24 +0000)
committerMohamed Abukar <abukar.mohamed@nokia.com>
Mon, 7 Jun 2021 06:24:19 +0000 (06:24 +0000)
Change-Id: I7b71b9aba3fbf206d2a0c9f565eb57f19d23ef1a
Signed-off-by: Mohamed Abukar <abukar.mohamed@nokia.com>
api/xapp_rest_api.yaml
pkg/clientmodel/action_definition.go
pkg/clientmodel/action_to_be_setup.go
pkg/clientmodel/event_trigger_definition.go
pkg/clientmodel/subscription_detail.go
pkg/models/action_definition.go
pkg/models/action_to_be_setup.go
pkg/models/event_trigger_definition.go
pkg/models/subscription_detail.go
pkg/restapi/embedded_spec.go
pkg/xapp/subscription_test.go

index 38a34f9..2890b90 100644 (file)
@@ -122,11 +122,10 @@ definitions:
     items:
       $ref: '#/definitions/XAppConfig'
   ActionDefinition:
-    type: object
-    description: E2SM Octet string. ActionDefinition is an OPTIONAL IE
-    properties:
-      OctetString:
-        type: string
+    type: array
+    description: E2SM byte array. ActionDefinition is an OPTIONAL IE
+    items:
+      type: integer
   SubsequentAction:
     description: SubsequentAction is an OPTIONAL IE
     type: object
@@ -185,11 +184,10 @@ definitions:
     items:
       $ref: '#/definitions/ActionToBeSetup'
   EventTriggerDefinition:
-    type: object
-    description: E2SM Octet string
-    properties:
-      OctetString:
-        type: string
+    type: array
+    description: E2SM byte array
+    items:
+      type: integer
   SubscriptionDetail:
     type: object
     required:
index 71851c2..f69c1f4 100644 (file)
@@ -7,37 +7,14 @@ package clientmodel
 
 import (
        "github.com/go-openapi/strfmt"
-       "github.com/go-openapi/swag"
 )
 
-// ActionDefinition E2SM Octet string. ActionDefinition is an OPTIONAL IE
+// ActionDefinition E2SM byte array. ActionDefinition is an OPTIONAL IE
 //
 // swagger:model ActionDefinition
-type ActionDefinition struct {
-
-       // octet string
-       OctetString string `json:"OctetString,omitempty"`
-}
+type ActionDefinition []int64
 
 // Validate validates this action definition
-func (m *ActionDefinition) Validate(formats strfmt.Registry) error {
-       return nil
-}
-
-// MarshalBinary interface implementation
-func (m *ActionDefinition) MarshalBinary() ([]byte, error) {
-       if m == nil {
-               return nil, nil
-       }
-       return swag.WriteJSON(m)
-}
-
-// UnmarshalBinary interface implementation
-func (m *ActionDefinition) UnmarshalBinary(b []byte) error {
-       var res ActionDefinition
-       if err := swag.ReadJSON(b, &res); err != nil {
-               return err
-       }
-       *m = res
+func (m ActionDefinition) Validate(formats strfmt.Registry) error {
        return nil
 }
index a72a9e2..b347c43 100644 (file)
@@ -20,7 +20,7 @@ import (
 type ActionToBeSetup struct {
 
        // action definition
-       ActionDefinition *ActionDefinition `json:"ActionDefinition,omitempty"`
+       ActionDefinition ActionDefinition `json:"ActionDefinition,omitempty"`
 
        // action ID
        // Required: true
@@ -69,13 +69,11 @@ func (m *ActionToBeSetup) validateActionDefinition(formats strfmt.Registry) erro
                return nil
        }
 
-       if m.ActionDefinition != nil {
-               if err := m.ActionDefinition.Validate(formats); err != nil {
-                       if ve, ok := err.(*errors.Validation); ok {
-                               return ve.ValidateName("ActionDefinition")
-                       }
-                       return err
+       if err := m.ActionDefinition.Validate(formats); err != nil {
+               if ve, ok := err.(*errors.Validation); ok {
+                       return ve.ValidateName("ActionDefinition")
                }
+               return err
        }
 
        return nil
index a4bbd60..2adf2f9 100644 (file)
@@ -7,37 +7,14 @@ package clientmodel
 
 import (
        "github.com/go-openapi/strfmt"
-       "github.com/go-openapi/swag"
 )
 
-// EventTriggerDefinition E2SM Octet string
+// EventTriggerDefinition E2SM byte array
 //
 // swagger:model EventTriggerDefinition
-type EventTriggerDefinition struct {
-
-       // octet string
-       OctetString string `json:"OctetString,omitempty"`
-}
+type EventTriggerDefinition []int64
 
 // Validate validates this event trigger definition
-func (m *EventTriggerDefinition) Validate(formats strfmt.Registry) error {
-       return nil
-}
-
-// MarshalBinary interface implementation
-func (m *EventTriggerDefinition) MarshalBinary() ([]byte, error) {
-       if m == nil {
-               return nil, nil
-       }
-       return swag.WriteJSON(m)
-}
-
-// UnmarshalBinary interface implementation
-func (m *EventTriggerDefinition) UnmarshalBinary(b []byte) error {
-       var res EventTriggerDefinition
-       if err := swag.ReadJSON(b, &res); err != nil {
-               return err
-       }
-       *m = res
+func (m EventTriggerDefinition) Validate(formats strfmt.Registry) error {
        return nil
 }
index f9ecff9..db04cb9 100644 (file)
@@ -23,7 +23,7 @@ type SubscriptionDetail struct {
 
        // event triggers
        // Required: true
-       EventTriggers *EventTriggerDefinition `json:"EventTriggers"`
+       EventTriggers EventTriggerDefinition `json:"EventTriggers"`
 
        // xapp event instance Id
        // Required: true
@@ -76,13 +76,11 @@ func (m *SubscriptionDetail) validateEventTriggers(formats strfmt.Registry) erro
                return err
        }
 
-       if m.EventTriggers != nil {
-               if err := m.EventTriggers.Validate(formats); err != nil {
-                       if ve, ok := err.(*errors.Validation); ok {
-                               return ve.ValidateName("EventTriggers")
-                       }
-                       return err
+       if err := m.EventTriggers.Validate(formats); err != nil {
+               if ve, ok := err.(*errors.Validation); ok {
+                       return ve.ValidateName("EventTriggers")
                }
+               return err
        }
 
        return nil
index cef3607..2cf839a 100644 (file)
@@ -7,37 +7,14 @@ package models
 
 import (
        "github.com/go-openapi/strfmt"
-       "github.com/go-openapi/swag"
 )
 
-// ActionDefinition E2SM Octet string. ActionDefinition is an OPTIONAL IE
+// ActionDefinition E2SM byte array. ActionDefinition is an OPTIONAL IE
 //
 // swagger:model ActionDefinition
-type ActionDefinition struct {
-
-       // octet string
-       OctetString string `json:"OctetString,omitempty"`
-}
+type ActionDefinition []int64
 
 // Validate validates this action definition
-func (m *ActionDefinition) Validate(formats strfmt.Registry) error {
-       return nil
-}
-
-// MarshalBinary interface implementation
-func (m *ActionDefinition) MarshalBinary() ([]byte, error) {
-       if m == nil {
-               return nil, nil
-       }
-       return swag.WriteJSON(m)
-}
-
-// UnmarshalBinary interface implementation
-func (m *ActionDefinition) UnmarshalBinary(b []byte) error {
-       var res ActionDefinition
-       if err := swag.ReadJSON(b, &res); err != nil {
-               return err
-       }
-       *m = res
+func (m ActionDefinition) Validate(formats strfmt.Registry) error {
        return nil
 }
index 3ee10a4..2136bf6 100644 (file)
@@ -20,7 +20,7 @@ import (
 type ActionToBeSetup struct {
 
        // action definition
-       ActionDefinition *ActionDefinition `json:"ActionDefinition,omitempty"`
+       ActionDefinition ActionDefinition `json:"ActionDefinition,omitempty"`
 
        // action ID
        // Required: true
@@ -69,13 +69,11 @@ func (m *ActionToBeSetup) validateActionDefinition(formats strfmt.Registry) erro
                return nil
        }
 
-       if m.ActionDefinition != nil {
-               if err := m.ActionDefinition.Validate(formats); err != nil {
-                       if ve, ok := err.(*errors.Validation); ok {
-                               return ve.ValidateName("ActionDefinition")
-                       }
-                       return err
+       if err := m.ActionDefinition.Validate(formats); err != nil {
+               if ve, ok := err.(*errors.Validation); ok {
+                       return ve.ValidateName("ActionDefinition")
                }
+               return err
        }
 
        return nil
index 6316e4a..d75feda 100644 (file)
@@ -7,37 +7,14 @@ package models
 
 import (
        "github.com/go-openapi/strfmt"
-       "github.com/go-openapi/swag"
 )
 
-// EventTriggerDefinition E2SM Octet string
+// EventTriggerDefinition E2SM byte array
 //
 // swagger:model EventTriggerDefinition
-type EventTriggerDefinition struct {
-
-       // octet string
-       OctetString string `json:"OctetString,omitempty"`
-}
+type EventTriggerDefinition []int64
 
 // Validate validates this event trigger definition
-func (m *EventTriggerDefinition) Validate(formats strfmt.Registry) error {
-       return nil
-}
-
-// MarshalBinary interface implementation
-func (m *EventTriggerDefinition) MarshalBinary() ([]byte, error) {
-       if m == nil {
-               return nil, nil
-       }
-       return swag.WriteJSON(m)
-}
-
-// UnmarshalBinary interface implementation
-func (m *EventTriggerDefinition) UnmarshalBinary(b []byte) error {
-       var res EventTriggerDefinition
-       if err := swag.ReadJSON(b, &res); err != nil {
-               return err
-       }
-       *m = res
+func (m EventTriggerDefinition) Validate(formats strfmt.Registry) error {
        return nil
 }
index baf0ed6..f157aba 100644 (file)
@@ -23,7 +23,7 @@ type SubscriptionDetail struct {
 
        // event triggers
        // Required: true
-       EventTriggers *EventTriggerDefinition `json:"EventTriggers"`
+       EventTriggers EventTriggerDefinition `json:"EventTriggers"`
 
        // xapp event instance Id
        // Required: true
@@ -76,13 +76,11 @@ func (m *SubscriptionDetail) validateEventTriggers(formats strfmt.Registry) erro
                return err
        }
 
-       if m.EventTriggers != nil {
-               if err := m.EventTriggers.Validate(formats); err != nil {
-                       if ve, ok := err.(*errors.Validation); ok {
-                               return ve.ValidateName("EventTriggers")
-                       }
-                       return err
+       if err := m.EventTriggers.Validate(formats); err != nil {
+               if ve, ok := err.(*errors.Validation); ok {
+                       return ve.ValidateName("EventTriggers")
                }
+               return err
        }
 
        return nil
index d3f7c17..4506519 100644 (file)
@@ -156,12 +156,10 @@ func init() {
   },
   "definitions": {
     "ActionDefinition": {
-      "description": "E2SM Octet string. ActionDefinition is an OPTIONAL IE",
-      "type": "object",
-      "properties": {
-        "OctetString": {
-          "type": "string"
-        }
+      "description": "E2SM byte array. ActionDefinition is an OPTIONAL IE",
+      "type": "array",
+      "items": {
+        "type": "integer"
       }
     },
     "ActionToBeSetup": {
@@ -220,12 +218,10 @@ func init() {
       }
     },
     "EventTriggerDefinition": {
-      "description": "E2SM Octet string",
-      "type": "object",
-      "properties": {
-        "OctetString": {
-          "type": "string"
-        }
+      "description": "E2SM byte array",
+      "type": "array",
+      "items": {
+        "type": "integer"
       }
     },
     "SubscriptionData": {
@@ -572,12 +568,10 @@ func init() {
   },
   "definitions": {
     "ActionDefinition": {
-      "description": "E2SM Octet string. ActionDefinition is an OPTIONAL IE",
-      "type": "object",
-      "properties": {
-        "OctetString": {
-          "type": "string"
-        }
+      "description": "E2SM byte array. ActionDefinition is an OPTIONAL IE",
+      "type": "array",
+      "items": {
+        "type": "integer"
       }
     },
     "ActionToBeSetup": {
@@ -637,12 +631,10 @@ func init() {
       }
     },
     "EventTriggerDefinition": {
-      "description": "E2SM Octet string",
-      "type": "object",
-      "properties": {
-        "OctetString": {
-          "type": "string"
-        }
+      "description": "E2SM byte array",
+      "type": "array",
+      "items": {
+        "type": "integer"
       }
     },
     "SubscriptionData": {
index 5772465..c7b00cd 100755 (executable)
@@ -63,16 +63,12 @@ func TestSubscriptionHandling(t *testing.T) {
                SubscriptionDetails: clientmodel.SubscriptionDetailsList{
                        &clientmodel.SubscriptionDetail{
                                XappEventInstanceID: &eventInstanceId,
-                               EventTriggers: &clientmodel.EventTriggerDefinition{
-                                       OctetString: "1234",
-                               },
+                               EventTriggers:       clientmodel.EventTriggerDefinition{00, 0x11, 0x12, 0x13, 0x00, 0x21, 0x22, 0x24, 0x1B, 0x80},
                                ActionToBeSetupList: clientmodel.ActionsToBeSetup{
                                        &clientmodel.ActionToBeSetup{
-                                               ActionID:   &actionId,
-                                               ActionType: &actionType,
-                                               ActionDefinition: &clientmodel.ActionDefinition{
-                                                       OctetString: "5678",
-                                               },
+                                               ActionID:         &actionId,
+                                               ActionType:       &actionType,
+                                               ActionDefinition: clientmodel.ActionDefinition{5, 6, 7, 8},
                                                SubsequentAction: &clientmodel.SubsequentAction{
                                                        SubsequentActionType: &subsequestActioType,
                                                        TimeToWait:           &timeToWait,
@@ -102,16 +98,12 @@ func TestSubscriptionWithClientProvidedIdHandling(t *testing.T) {
                SubscriptionDetails: clientmodel.SubscriptionDetailsList{
                        &clientmodel.SubscriptionDetail{
                                XappEventInstanceID: &eventInstanceId,
-                               EventTriggers: &clientmodel.EventTriggerDefinition{
-                                       OctetString: "1234",
-                               },
+                               EventTriggers:       clientmodel.EventTriggerDefinition{00, 0x11, 0x12, 0x13, 0x00, 0x21, 0x22, 0x24, 0x1B, 0x80},
                                ActionToBeSetupList: clientmodel.ActionsToBeSetup{
                                        &clientmodel.ActionToBeSetup{
-                                               ActionID:   &actionId,
-                                               ActionType: &actionType,
-                                               ActionDefinition: &clientmodel.ActionDefinition{
-                                                       OctetString: "5678",
-                                               },
+                                               ActionID:         &actionId,
+                                               ActionType:       &actionType,
+                                               ActionDefinition: clientmodel.ActionDefinition{5, 6, 7, 8},
                                                SubsequentAction: &clientmodel.SubsequentAction{
                                                        SubsequentActionType: &subsequestActioType,
                                                        TimeToWait:           &timeToWait,
@@ -168,13 +160,14 @@ func subscriptionHandler(params interface{}) (*models.SubscriptionResponse, erro
        assert.Equal(suite, clientEndpoint.RMRPort, p.ClientEndpoint.RMRPort)
 
        assert.Equal(suite, xappEventInstanceId, *p.SubscriptionDetails[0].XappEventInstanceID)
-       assert.Equal(suite, "1234", p.SubscriptionDetails[0].EventTriggers.OctetString)
+       et := []int64{00, 0x11, 0x12, 0x13, 0x00, 0x21, 0x22, 0x24, 0x1B, 0x80}
+       assert.ElementsMatch(suite, et, p.SubscriptionDetails[0].EventTriggers)
        assert.Equal(suite, actionId, *p.SubscriptionDetails[0].ActionToBeSetupList[0].ActionID)
        assert.Equal(suite, actionType, *p.SubscriptionDetails[0].ActionToBeSetupList[0].ActionType)
 
        assert.Equal(suite, subsequestActioType, *p.SubscriptionDetails[0].ActionToBeSetupList[0].SubsequentAction.SubsequentActionType)
        assert.Equal(suite, timeToWait, *p.SubscriptionDetails[0].ActionToBeSetupList[0].SubsequentAction.TimeToWait)
-       assert.Equal(suite, "5678", p.SubscriptionDetails[0].ActionToBeSetupList[0].ActionDefinition.OctetString)
+       assert.ElementsMatch(suite, []int64{5, 6, 7, 8}, p.SubscriptionDetails[0].ActionToBeSetupList[0].ActionDefinition)
 
        // Generate a unique subscriptionId
        subscriptionId = fmt.Sprintf("%s-%s", meid, clientEndpoint.Host)