From dd0af146fdd2b51aa3d544502adedeb4b5b11d69 Mon Sep 17 00:00:00 2001 From: AyeshaAyubG Date: Thu, 9 Jun 2022 15:48:56 +0500 Subject: [PATCH] update ProblemDetails and docs for MEC011 app-support --- docs/api-app-support/.openapi-generator/FILES | 18 ++++- docs/api-app-support/Apis/MecAppSupportApi.md | 24 +++--- docs/api-app-support/Apis/UnsupportedApi.md | 12 +-- docs/api-app-support/README.md | 18 ++++- .../api/app-support/swagger.yaml | 3 + .../server/app-support/app-support.go | 75 +++++++++++-------- .../server/app-support/convert.go | 9 +++ .../app-support/model_problem_details.go | 4 +- 8 files changed, 103 insertions(+), 60 deletions(-) diff --git a/docs/api-app-support/.openapi-generator/FILES b/docs/api-app-support/.openapi-generator/FILES index bad542326..bd7294d0c 100644 --- a/docs/api-app-support/.openapi-generator/FILES +++ b/docs/api-app-support/.openapi-generator/FILES @@ -6,21 +6,31 @@ Models/AppTerminationConfirmation.md Models/AppTerminationNotification.md Models/AppTerminationNotificationLinks.md Models/AppTerminationNotificationSubscription.md -Models/AppTerminationNotificationSubscriptionLinks.md Models/CurrentTime.md Models/DestinationInterface.md +Models/DestinationInterfaceInterfaceType.md Models/DnsRule.md +Models/DnsRuleIpAddressType.md +Models/DnsRuleState.md Models/LinkType.md +Models/MecAppSuptApiSubscriptionLinkList.md +Models/MecAppSuptApiSubscriptionLinkListLinks.md +Models/MecAppSuptApiSubscriptionLinkListSubscription.md Models/OperationActionType.md Models/ProblemDetails.md -Models/SubscriptionLinkList.md -Models/SubscriptionLinkListLinks.md -Models/SubscriptionLinkListLinksSubscriptions.md +Models/Self.md +Models/TimeSourceStatus.md Models/TimingCaps.md Models/TimingCapsNtpServers.md +Models/TimingCapsNtpServersAuthenticationOption.md +Models/TimingCapsNtpServersNtpServerAddrType.md Models/TimingCapsPtpMasters.md Models/TimingCapsTimeStamp.md Models/TrafficFilter.md Models/TrafficRule.md +Models/TrafficRuleAction.md +Models/TrafficRuleFilterType.md +Models/TrafficRuleState.md Models/TunnelInfo.md +Models/TunnelInfoTunnelType.md README.md diff --git a/docs/api-app-support/Apis/MecAppSupportApi.md b/docs/api-app-support/Apis/MecAppSupportApi.md index 06d8d0093..0fb926b8a 100644 --- a/docs/api-app-support/Apis/MecAppSupportApi.md +++ b/docs/api-app-support/Apis/MecAppSupportApi.md @@ -27,7 +27,7 @@ Method | HTTP request | Description Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- **appInstanceId** | **String**| Represents a MEC application instance. Note that the appInstanceId is allocated by the MEC platform manager. | [default to null] - **AppReadyConfirmation** | [**AppReadyConfirmation**](../Models/AppReadyConfirmation.md)| | + **AppReadyConfirmation** | [**AppReadyConfirmation**](../Models/AppReadyConfirmation.md)| | [optional] ### Return type @@ -40,7 +40,7 @@ No authorization required ### HTTP request headers - **Content-Type**: application/json -- **Accept**: application/problem+json +- **Accept**: application/problem+json, text/plain # **applicationsConfirmTerminationPOST** @@ -55,7 +55,7 @@ No authorization required Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- **appInstanceId** | **String**| Represents a MEC application instance. Note that the appInstanceId is allocated by the MEC platform manager. | [default to null] - **AppTerminationConfirmation** | [**AppTerminationConfirmation**](../Models/AppTerminationConfirmation.md)| | + **AppTerminationConfirmation** | [**AppTerminationConfirmation**](../Models/AppTerminationConfirmation.md)| | [optional] ### Return type @@ -68,7 +68,7 @@ No authorization required ### HTTP request headers - **Content-Type**: application/json -- **Accept**: application/problem+json +- **Accept**: application/problem+json, text/plain # **applicationsSubscriptionDELETE** @@ -96,7 +96,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined -- **Accept**: application/problem+json +- **Accept**: application/problem+json, text/plain, # **applicationsSubscriptionGET** @@ -124,11 +124,11 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined -- **Accept**: application/json, application/problem+json +- **Accept**: application/json, application/problem+json, text/plain # **applicationsSubscriptionsGET** -> SubscriptionLinkList applicationsSubscriptionsGET(appInstanceId) +> MecAppSuptApiSubscriptionLinkList applicationsSubscriptionsGET(appInstanceId) @@ -142,7 +142,7 @@ Name | Type | Description | Notes ### Return type -[**SubscriptionLinkList**](../Models/SubscriptionLinkList.md) +[**MecAppSuptApiSubscriptionLinkList**](../Models/MecAppSuptApiSubscriptionLinkList.md) ### Authorization @@ -151,7 +151,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined -- **Accept**: application/json, application/problem+json +- **Accept**: application/json, application/problem+json, text/plain # **applicationsSubscriptionsPOST** @@ -179,7 +179,7 @@ No authorization required ### HTTP request headers - **Content-Type**: application/json -- **Accept**: application/json, application/problem+json +- **Accept**: application/json, application/problem+json, text/plain # **timingCapsGET** @@ -203,7 +203,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined -- **Accept**: application/json, application/problem+json +- **Accept**: application/json, application/problem+json, text/plain # **timingCurrentTimeGET** @@ -227,5 +227,5 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined -- **Accept**: application/json, application/problem+json +- **Accept**: application/json, application/problem+json, text/plain diff --git a/docs/api-app-support/Apis/UnsupportedApi.md b/docs/api-app-support/Apis/UnsupportedApi.md index ea134e2c7..3e59d26dc 100644 --- a/docs/api-app-support/Apis/UnsupportedApi.md +++ b/docs/api-app-support/Apis/UnsupportedApi.md @@ -38,7 +38,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined -- **Accept**: application/json, application/problem+json +- **Accept**: application/json, application/problem+json, text/plain # **applicationsDnsRulePUT** @@ -67,7 +67,7 @@ No authorization required ### HTTP request headers - **Content-Type**: application/json -- **Accept**: application/json, application/problem+json +- **Accept**: application/json, application/problem+json, text/plain # **applicationsDnsRulesGET** @@ -94,7 +94,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined -- **Accept**: application/json, application/problem+json +- **Accept**: application/json, application/problem+json, text/plain # **applicationsTrafficRuleGET** @@ -122,7 +122,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined -- **Accept**: application/json, application/problem+json +- **Accept**: application/json, application/problem+json, text/plain # **applicationsTrafficRulePUT** @@ -151,7 +151,7 @@ No authorization required ### HTTP request headers - **Content-Type**: application/json -- **Accept**: application/json, application/problem+json +- **Accept**: application/json, application/problem+json, text/plain # **applicationsTrafficRulesGET** @@ -178,5 +178,5 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined -- **Accept**: application/json, application/problem+json +- **Accept**: application/json, application/problem+json, text/plain diff --git a/docs/api-app-support/README.md b/docs/api-app-support/README.md index da5d891e5..2d90574b3 100644 --- a/docs/api-app-support/README.md +++ b/docs/api-app-support/README.md @@ -31,23 +31,33 @@ Class | Method | HTTP request | Description - [AppTerminationNotification](./Models/AppTerminationNotification.md) - [AppTerminationNotificationLinks](./Models/AppTerminationNotificationLinks.md) - [AppTerminationNotificationSubscription](./Models/AppTerminationNotificationSubscription.md) - - [AppTerminationNotificationSubscriptionLinks](./Models/AppTerminationNotificationSubscriptionLinks.md) - [CurrentTime](./Models/CurrentTime.md) - [DestinationInterface](./Models/DestinationInterface.md) + - [DestinationInterfaceInterfaceType](./Models/DestinationInterfaceInterfaceType.md) - [DnsRule](./Models/DnsRule.md) + - [DnsRuleIpAddressType](./Models/DnsRuleIpAddressType.md) + - [DnsRuleState](./Models/DnsRuleState.md) - [LinkType](./Models/LinkType.md) + - [MecAppSuptApiSubscriptionLinkList](./Models/MecAppSuptApiSubscriptionLinkList.md) + - [MecAppSuptApiSubscriptionLinkListLinks](./Models/MecAppSuptApiSubscriptionLinkListLinks.md) + - [MecAppSuptApiSubscriptionLinkListSubscription](./Models/MecAppSuptApiSubscriptionLinkListSubscription.md) - [OperationActionType](./Models/OperationActionType.md) - [ProblemDetails](./Models/ProblemDetails.md) - - [SubscriptionLinkList](./Models/SubscriptionLinkList.md) - - [SubscriptionLinkListLinks](./Models/SubscriptionLinkListLinks.md) - - [SubscriptionLinkListLinksSubscriptions](./Models/SubscriptionLinkListLinksSubscriptions.md) + - [Self](./Models/Self.md) + - [TimeSourceStatus](./Models/TimeSourceStatus.md) - [TimingCaps](./Models/TimingCaps.md) - [TimingCapsNtpServers](./Models/TimingCapsNtpServers.md) + - [TimingCapsNtpServersAuthenticationOption](./Models/TimingCapsNtpServersAuthenticationOption.md) + - [TimingCapsNtpServersNtpServerAddrType](./Models/TimingCapsNtpServersNtpServerAddrType.md) - [TimingCapsPtpMasters](./Models/TimingCapsPtpMasters.md) - [TimingCapsTimeStamp](./Models/TimingCapsTimeStamp.md) - [TrafficFilter](./Models/TrafficFilter.md) - [TrafficRule](./Models/TrafficRule.md) + - [TrafficRuleAction](./Models/TrafficRuleAction.md) + - [TrafficRuleFilterType](./Models/TrafficRuleFilterType.md) + - [TrafficRuleState](./Models/TrafficRuleState.md) - [TunnelInfo](./Models/TunnelInfo.md) + - [TunnelInfoTunnelType](./Models/TunnelInfoTunnelType.md) diff --git a/go-apps/meep-app-enablement/api/app-support/swagger.yaml b/go-apps/meep-app-enablement/api/app-support/swagger.yaml index 7aae45448..ab4aec485 100644 --- a/go-apps/meep-app-enablement/api/app-support/swagger.yaml +++ b/go-apps/meep-app-enablement/api/app-support/swagger.yaml @@ -1402,6 +1402,9 @@ components: - TERMINATING ProblemDetails: title: ProblemDetails + required: + - status + - detail type: object properties: type: diff --git a/go-apps/meep-app-enablement/server/app-support/app-support.go b/go-apps/meep-app-enablement/server/app-support/app-support.go index 762c40e4d..28164ace3 100644 --- a/go-apps/meep-app-enablement/server/app-support/app-support.go +++ b/go-apps/meep-app-enablement/server/app-support/app-support.go @@ -215,7 +215,7 @@ func applicationsConfirmReadyPOST(w http.ResponseWriter, r *http.Request) { // Make sure App instance exists appInfo, err := getApp(appId) if err != nil { - http.Error(w, err.Error(), http.StatusNotFound) + errHandlerProblemDetails(w, err.Error(), http.StatusNotFound) return } @@ -225,21 +225,21 @@ func applicationsConfirmReadyPOST(w http.ResponseWriter, r *http.Request) { err = decoder.Decode(&confirmation) if err != nil { log.Error(err.Error()) - http.Error(w, err.Error(), http.StatusInternalServerError) + errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } // Validate App Ready params if confirmation.Indication == "" { log.Error("Mandatory Indication not present") - http.Error(w, "Mandatory Indication not present", http.StatusBadRequest) + errHandlerProblemDetails(w, "Mandatory Indication not present", http.StatusBadRequest) return } switch confirmation.Indication { case "READY": default: log.Error("Mandatory OperationAction value not valid") - http.Error(w, "Mandatory OperationAction value not valid", http.StatusBadRequest) + errHandlerProblemDetails(w, "Mandatory OperationAction value not valid", http.StatusBadRequest) return } @@ -250,7 +250,7 @@ func applicationsConfirmReadyPOST(w http.ResponseWriter, r *http.Request) { err = setAppInfo(appInfo) if err != nil { log.Error(err.Error()) - http.Error(w, err.Error(), http.StatusInternalServerError) + errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } @@ -270,7 +270,7 @@ func applicationsConfirmTerminationPOST(w http.ResponseWriter, r *http.Request) // Get App instance appInfo, err := getApp(appId) if err != nil { - http.Error(w, err.Error(), http.StatusNotFound) + errHandlerProblemDetails(w, err.Error(), http.StatusNotFound) return } @@ -282,7 +282,7 @@ func applicationsConfirmTerminationPOST(w http.ResponseWriter, r *http.Request) w.WriteHeader(code) fmt.Fprintf(w, problemDetails) } else { - http.Error(w, err.Error(), code) + errHandlerProblemDetails(w, err.Error(), code) } return } @@ -291,7 +291,7 @@ func applicationsConfirmTerminationPOST(w http.ResponseWriter, r *http.Request) gracefulTerminateChannel, found := gracefulTerminateMap[appId] if !found { log.Error("Unexpected App Confirmation Termination Notification") - http.Error(w, "Unexpected App Confirmation Termination Notification", http.StatusBadRequest) + errHandlerProblemDetails(w, "Unexpected App Confirmation Termination Notification", http.StatusBadRequest) return } @@ -301,21 +301,21 @@ func applicationsConfirmTerminationPOST(w http.ResponseWriter, r *http.Request) err = decoder.Decode(&confirmation) if err != nil { log.Error(err.Error()) - http.Error(w, err.Error(), http.StatusInternalServerError) + errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } // Validate Termination Confirmation params if confirmation.OperationAction == nil { log.Error("Mandatory OperationAction not present") - http.Error(w, "Mandatory OperationAction not present", http.StatusBadRequest) + errHandlerProblemDetails(w, "Mandatory OperationAction not present", http.StatusBadRequest) return } switch *confirmation.OperationAction { case STOPPING, TERMINATING: default: log.Error("Mandatory OperationAction value not valid") - http.Error(w, "Mandatory OperationAction value not valid", http.StatusBadRequest) + errHandlerProblemDetails(w, "Mandatory OperationAction value not valid", http.StatusBadRequest) return } @@ -337,7 +337,7 @@ func applicationsSubscriptionsPOST(w http.ResponseWriter, r *http.Request) { // Get App instance appInfo, err := getApp(appId) if err != nil { - http.Error(w, err.Error(), http.StatusNotFound) + errHandlerProblemDetails(w, err.Error(), http.StatusNotFound) return } @@ -349,7 +349,7 @@ func applicationsSubscriptionsPOST(w http.ResponseWriter, r *http.Request) { w.WriteHeader(code) fmt.Fprintf(w, problemDetails) } else { - http.Error(w, err.Error(), code) + errHandlerProblemDetails(w, err.Error(), code) } return } @@ -360,29 +360,29 @@ func applicationsSubscriptionsPOST(w http.ResponseWriter, r *http.Request) { err = decoder.Decode(&appTermNotifSub) if err != nil { log.Error(err.Error()) - http.Error(w, err.Error(), http.StatusInternalServerError) + errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } // Verify mandatory properties if appTermNotifSub.CallbackReference == "" { log.Error("Mandatory CallbackReference parameter not present") - http.Error(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest) + errHandlerProblemDetails(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest) return } if appTermNotifSub.SubscriptionType != APP_TERMINATION_NOTIF_SUB_TYPE { log.Error("SubscriptionType shall be AppTerminationNotificationSubscription") - http.Error(w, "SubscriptionType shall be AppTerminationNotificationSubscription", http.StatusBadRequest) + errHandlerProblemDetails(w, "SubscriptionType shall be AppTerminationNotificationSubscription", http.StatusBadRequest) return } if appTermNotifSub.AppInstanceId == "" { log.Error("Mandatory AppInstanceId parameter not present") - http.Error(w, "Mandatory AppInstanceId parameter not present", http.StatusBadRequest) + errHandlerProblemDetails(w, "Mandatory AppInstanceId parameter not present", http.StatusBadRequest) return } if appTermNotifSub.AppInstanceId != appId { log.Error("AppInstanceId in endpoint and in body not matching") - http.Error(w, "AppInstanceId in endpoint and in body not matching", http.StatusBadRequest) + errHandlerProblemDetails(w, "AppInstanceId in endpoint and in body not matching", http.StatusBadRequest) return } @@ -402,7 +402,7 @@ func applicationsSubscriptionsPOST(w http.ResponseWriter, r *http.Request) { _, err = subMgr.CreateSubscription(subCfg, jsonSub) if err != nil { log.Error("Failed to create subscription") - http.Error(w, "Failed to create subscription", http.StatusInternalServerError) + errHandlerProblemDetails(w, "Failed to create subscription", http.StatusInternalServerError) return } @@ -424,7 +424,7 @@ func applicationsSubscriptionGET(w http.ResponseWriter, r *http.Request) { // Get App instance info appInfo, err := getApp(appId) if err != nil { - http.Error(w, err.Error(), http.StatusNotFound) + errHandlerProblemDetails(w, err.Error(), http.StatusNotFound) return } @@ -436,7 +436,7 @@ func applicationsSubscriptionGET(w http.ResponseWriter, r *http.Request) { w.WriteHeader(code) fmt.Fprintf(w, problemDetails) } else { - http.Error(w, err.Error(), code) + errHandlerProblemDetails(w, err.Error(), code) } return } @@ -445,7 +445,7 @@ func applicationsSubscriptionGET(w http.ResponseWriter, r *http.Request) { sub, err := subMgr.GetSubscription(subId) if err != nil { log.Error(err.Error()) - http.Error(w, err.Error(), http.StatusNotFound) + errHandlerProblemDetails(w, err.Error(), http.StatusNotFound) return } @@ -453,7 +453,7 @@ func applicationsSubscriptionGET(w http.ResponseWriter, r *http.Request) { if sub.Cfg.AppId != appId || sub.Cfg.Type != APP_TERMINATION_NOTIF_SUB_TYPE { err = errors.New("Subscription not found") log.Error(err.Error()) - http.Error(w, err.Error(), http.StatusNotFound) + errHandlerProblemDetails(w, err.Error(), http.StatusNotFound) return } @@ -474,7 +474,7 @@ func applicationsSubscriptionDELETE(w http.ResponseWriter, r *http.Request) { // Get App instance info appInfo, err := getApp(appId) if err != nil { - http.Error(w, err.Error(), http.StatusNotFound) + errHandlerProblemDetails(w, err.Error(), http.StatusNotFound) return } @@ -486,7 +486,7 @@ func applicationsSubscriptionDELETE(w http.ResponseWriter, r *http.Request) { w.WriteHeader(code) fmt.Fprintf(w, problemDetails) } else { - http.Error(w, err.Error(), code) + errHandlerProblemDetails(w, err.Error(), code) } return } @@ -495,7 +495,7 @@ func applicationsSubscriptionDELETE(w http.ResponseWriter, r *http.Request) { sub, err := subMgr.GetSubscription(subId) if err != nil { log.Error(err.Error()) - http.Error(w, err.Error(), http.StatusNotFound) + errHandlerProblemDetails(w, err.Error(), http.StatusNotFound) return } @@ -503,7 +503,7 @@ func applicationsSubscriptionDELETE(w http.ResponseWriter, r *http.Request) { if sub.Cfg.AppId != appId || sub.Cfg.Type != APP_TERMINATION_NOTIF_SUB_TYPE { err = errors.New("Subscription not found") log.Error(err.Error()) - http.Error(w, err.Error(), http.StatusNotFound) + errHandlerProblemDetails(w, err.Error(), http.StatusNotFound) return } @@ -511,7 +511,7 @@ func applicationsSubscriptionDELETE(w http.ResponseWriter, r *http.Request) { err = subMgr.DeleteSubscription(sub) if err != nil { log.Error(err.Error()) - http.Error(w, err.Error(), http.StatusInternalServerError) + errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } @@ -530,7 +530,7 @@ func applicationsSubscriptionsGET(w http.ResponseWriter, r *http.Request) { // Get App instance info appInfo, err := getApp(appId) if err != nil { - http.Error(w, err.Error(), http.StatusNotFound) + errHandlerProblemDetails(w, err.Error(), http.StatusNotFound) return } @@ -542,7 +542,7 @@ func applicationsSubscriptionsGET(w http.ResponseWriter, r *http.Request) { w.WriteHeader(code) fmt.Fprintf(w, problemDetails) } else { - http.Error(w, err.Error(), code) + errHandlerProblemDetails(w, err.Error(), code) } return } @@ -594,7 +594,7 @@ func timingCapsGET(w http.ResponseWriter, r *http.Request) { jsonResponse, err := json.Marshal(timingCaps) if err != nil { log.Error(err.Error()) - http.Error(w, err.Error(), http.StatusInternalServerError) + errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } w.WriteHeader(http.StatusOK) @@ -616,7 +616,7 @@ func timingCurrentTimeGET(w http.ResponseWriter, r *http.Request) { jsonResponse, err := json.Marshal(currentTime) if err != nil { log.Error(err.Error()) - http.Error(w, err.Error(), http.StatusInternalServerError) + errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } w.WriteHeader(http.StatusOK) @@ -1011,3 +1011,14 @@ func sendAppRemoveCnf(id string) { return } } + +func errHandlerProblemDetails(w http.ResponseWriter, error string, code int) { + var pd ProblemDetails + pd.Detail = error + pd.Status = int32(code) + + jsonResponse := convertProblemDetailstoJson(&pd) + + w.WriteHeader(code) + fmt.Fprint(w, jsonResponse) +} \ No newline at end of file diff --git a/go-apps/meep-app-enablement/server/app-support/convert.go b/go-apps/meep-app-enablement/server/app-support/convert.go index ec0f536c9..ca9683226 100644 --- a/go-apps/meep-app-enablement/server/app-support/convert.go +++ b/go-apps/meep-app-enablement/server/app-support/convert.go @@ -57,3 +57,12 @@ func convertMecAppSuptApiSubscriptionLinkListToJson(obj *MecAppSuptApiSubscripti } return string(jsonInfo) } + +func convertProblemDetailstoJson(probdetails *ProblemDetails) string { + jsonInfo, err := json.Marshal(*probdetails) + if err != nil { + log.Error(err.Error()) + return "" + } + return string(jsonInfo) +} \ No newline at end of file diff --git a/go-apps/meep-app-enablement/server/app-support/model_problem_details.go b/go-apps/meep-app-enablement/server/app-support/model_problem_details.go index ec66035d0..1cb24a9e2 100644 --- a/go-apps/meep-app-enablement/server/app-support/model_problem_details.go +++ b/go-apps/meep-app-enablement/server/app-support/model_problem_details.go @@ -29,9 +29,9 @@ type ProblemDetails struct { // A short, human-readable summary of the problem type Title string `json:"title,omitempty"` // The HTTP status code for this occurrence of the problem - Status int32 `json:"status,omitempty"` + Status int32 `json:"status"` // A human-readable explanation specific to this occurrence of the problem - Detail string `json:"detail,omitempty"` + Detail string `json:"detail"` // A URI reference that identifies the specific occurrence of the problem Instance string `json:"instance,omitempty"` } -- GitLab