Commit a25c01de authored by Muhammad Umair Khan's avatar Muhammad Umair Khan
Browse files

fix issue#11 Decoding Versions issue in AefProfile:Update Versions to...

fix issue#11 Decoding Versions issue in AefProfile:Update Versions to []Version struct with APIVersion; enforce single version entry
parent 5ec41796
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -1215,11 +1215,16 @@ components:
          description: "AEF identifier. Shall be set to the value of the 'id' attribute as defined in clause 8.1.2.3."
        versions:
          type: array
          items:
            type: string
            description: "API version. This array shall contain a single entry."
          minItems: 1
          maxItems: 1
          items:
            type: object
            properties:
              apiVersion:
                type: string
                description: "The version of the API as per clause 8.1.2.2"
            required:
              - apiVersion
        interfaceDescriptions:
          description: This type represents information about a transport endpoint
          oneOf:
+15 −0
Original line number Diff line number Diff line
/*
 * MEC service management realized by CAPIF APIs
 *
 * The ETSI MEC ISG MEC011 MEC Service Management realized by CAPIF APIs described using OpenAPI
 *
 * API version: 3.2.1
 * Contact: cti_support@etsi.org
 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
 */

package server

type Version struct {
	APIVersion string `json:"apiVersion"`
}
+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ type AefProfile struct {
	// AEF identifier. Shall be set to the value of the 'id' attribute as defined in clause 8.1.2.3.
	AefId string `json:"aefId"`

	Versions []string `json:"versions"`
	Versions []Version `json:"versions"`
	// This type represents information about a transport endpoint
	InterfaceDescriptions *OneOfTransportInfoEndpoint `json:"interfaceDescriptions,omitempty"`

+17 −8
Original line number Diff line number Diff line
@@ -281,6 +281,15 @@ func appServicesPOST(w http.ResponseWriter, r *http.Request) {
		errHandlerProblemDetails(w, errStr, http.StatusBadRequest)
		return
	}
	// Reject if more than one version is provided in any AEF Profile
	for _, aef := range sInfoPost.AefProfiles {
		if len(aef.Versions) > 1 {
			errStr := fmt.Sprintf("Only one apiVersion is allowed per AEF profile; found %d", len(aef.Versions))
			log.Error(errStr)
			errHandlerProblemDetails(w, errStr, http.StatusBadRequest)
			return
		}
	}
	if sInfoPost.VendorSpecificUrnetsimeccapifextserviceInfo.State == nil {
		errStr := "Mandatory Service State parameter not present"
		log.Error(errStr)
@@ -335,7 +344,7 @@ func appServicesPOST(w http.ResponseWriter, r *http.Request) {

	aefProfile := &AefProfile{
		AefId:                 sInfoPost.AefProfiles[0].AefId,
		Versions:              sInfoPost.AefProfiles[0].Versions,
		Versions:              []Version{sInfoPost.AefProfiles[0].Versions[0]},
		InterfaceDescriptions: sInfoPost.AefProfiles[0].InterfaceDescriptions,
		VendorSpecificUrnetsimeccapifexttransportInfo: &MecTransportInfoCapifExt{
			Name:     sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Name,
@@ -374,7 +383,7 @@ func appServicesPOST(w http.ResponseWriter, r *http.Request) {
		SerInstanceId:     dsInfo.ApiId,
		SerName:           dsInfo.ApiName,
		SerCategory:       dsInfo.VendorSpecificUrnetsimeccapifextserviceInfo.Category,
		Version:           dsInfo.AefProfiles[0].Versions[0],
		Version:           dsInfo.AefProfiles[0].Versions[0].APIVersion,
		State:             dsInfo.VendorSpecificUrnetsimeccapifextserviceInfo.State,
		TransportInfo:     &transportInfo_,
		Serializer:        dsInfo.VendorSpecificUrnetsimeccapifextserviceInfo.Serializer,
@@ -510,7 +519,7 @@ func appServicesByIdPUT(w http.ResponseWriter, r *http.Request) {
		SerInstanceId:     dsInfo.ApiId,
		SerName:           dsInfo.ApiName,
		SerCategory:       dsInfo.VendorSpecificUrnetsimeccapifextserviceInfo.Category,
		Version:           dsInfo.AefProfiles[0].Versions[0],
		Version:           dsInfo.AefProfiles[0].Versions[0].APIVersion,
		State:             dsInfo.VendorSpecificUrnetsimeccapifextserviceInfo.State,
		TransportInfo:     &transportInfo_,
		Serializer:        dsInfo.VendorSpecificUrnetsimeccapifextserviceInfo.Serializer,
@@ -673,7 +682,7 @@ func appServicesByIdPATCH(w http.ResponseWriter, r *http.Request) {
	_sInfo := ServiceInfo{
		SerInstanceId:     sInfoPrev.SerInstanceId,
		SerName:           sInfoPrev.SerName,
		Version:           dsInfo.AefProfiles[0].Versions[0],
		Version:           dsInfo.AefProfiles[0].Versions[0].APIVersion,
		SerCategory:       dsInfo.VendorSpecificUrnetsimeccapifextserviceInfo.Category,
		State:             dsInfo.VendorSpecificUrnetsimeccapifextserviceInfo.State,
		TransportInfo:     &transportInfo_,
@@ -1774,7 +1783,7 @@ func getServices(w http.ResponseWriter, r *http.Request, appId string) {
	for _, service := range sInfoList.Services {
		aefProfile := AefProfile{
			AefId:                 service.TransportInfo.Id,
			Versions:              []string{service.Version},
			Versions:              []Version{{APIVersion: service.Version}},
			InterfaceDescriptions: service.TransportInfo.Endpoint,
			VendorSpecificUrnetsimeccapifexttransportInfo: &MecTransportInfoCapifExt{
				Name:     service.TransportInfo.Name,
@@ -1851,7 +1860,7 @@ func getService(w http.ResponseWriter, r *http.Request, appId string, serviceId
	for _, service := range sInfoList.Services {
		aefProfile := AefProfile{
			AefId:                 service.TransportInfo.Id,
			Versions:              []string{service.Version},
			Versions:              []Version{{APIVersion: service.Version}},
			InterfaceDescriptions: service.TransportInfo.Endpoint,
			VendorSpecificUrnetsimeccapifexttransportInfo: &MecTransportInfoCapifExt{
				Name:     service.TransportInfo.Name,
@@ -2078,10 +2087,10 @@ func checkSerAvailNotification(sInfo *ServiceInfo, mep string, changeType CapifE
				}
			}
		}
		versions := []string{sInfo.Version}
		// versions := []string{sInfo.Version}
		aefProfile := &AefProfile{
			AefId:                 sInfo.TransportInfo.Id,
			Versions:              versions,
			Versions:              []Version{{APIVersion: sInfo.Version}},
			InterfaceDescriptions: sInfo.TransportInfo.Endpoint,
			VendorSpecificUrnetsimeccapifexttransportInfo: &MecTransportInfoCapifExt{
				Name:     sInfo.TransportInfo.Name,
+18 −4
Original line number Diff line number Diff line
@@ -7628,7 +7628,7 @@ func TestAppServicesPOST(t *testing.T) {
		AefProfiles: []capif.AefProfile{
			{
				AefId:    "sandboxTransport",
				Versions: []string{"3.1.1"},
				Versions: []capif.Version{{APIVersion: "3.1.1"}},
				InterfaceDescriptions: &capif.OneOfTransportInfoEndpoint{
					EndPointInfoUris: capif.EndPointInfoUris{
						Uris: []string{"http://172.30.225.7/dacdasd/mep1/location/v3/"},
@@ -7781,7 +7781,7 @@ func TestAppServicesPUT(t *testing.T) {
		AefProfiles: []capif.AefProfile{
			{
				AefId:    "sandboxTransport",
				Versions: []string{"3.1.1"},
				Versions: []capif.Version{{APIVersion: "3.1.1"}},
				InterfaceDescriptions: &capif.OneOfTransportInfoEndpoint{
					EndPointInfoUris: capif.EndPointInfoUris{
						Uris: []string{"http://172.30.225.7/dacdasd/mep1/location/v3/"},
@@ -7888,7 +7888,7 @@ func TestAppServicesPATCH(t *testing.T) {
		AefProfiles: []capif.AefProfile{
			{
				AefId:    "sandboxTransport",
				Versions: []string{"3.2.1"},
				Versions: []capif.Version{{APIVersion: "3.1.1"}},
				InterfaceDescriptions: &capif.OneOfTransportInfoEndpoint{
					EndPointInfoUris: capif.EndPointInfoUris{
						Uris: []string{"http://172.30.225.7/dacdasd/mep1/location/v3/"},
@@ -7917,6 +7917,20 @@ func TestAppServicesPATCH(t *testing.T) {
		},
	}

	// type ApiResponse struct {
	// 	ApiName     string `json:"apiName"`
	// 	ApiId       string `json:"apiId"`
	// 	AefProfiles []struct {
	// 		AefId                 string   `json:"aefId"`
	// 		Versions              []string `json:"versions"`
	// 		InterfaceDescriptions struct {
	// 			Uris []string `json:"uris"`
	// 		} `json:"interfaceDescriptions"`
	// 		VendorSpecificTransportInfo map[string]interface{} `json:"vendorSpecific-urn:etsi:mec:capifext:transport-info"`
	// 	} `json:"aefProfiles"`
	// 	VendorSpecificServiceInfo map[string]interface{} `json:"vendorSpecific-urn:etsi:mec:capifext:service-info"`
	// }

	// Marshalling the request body to JSON format
	body, err := json.Marshal(requestBody)
	if err != nil {