X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=capifcore%2Finternal%2Fpublishservice%2Fpublishservice.go;fp=capifcore%2Finternal%2Fpublishservice%2Fpublishservice.go;h=e3a23146c379095f9428135548373b3337986b66;hb=30931ba398fc7a3b9269af7120dce7bad027c79e;hp=3898a804535b29529e8c06eaf0ef4cf981b98910;hpb=cfe4597782fe0a2bb01d655889b2cca9724f5bc5;p=nonrtric%2Fplt%2Fsme.git diff --git a/capifcore/internal/publishservice/publishservice.go b/capifcore/internal/publishservice/publishservice.go index 3898a80..e3a2314 100644 --- a/capifcore/internal/publishservice/publishservice.go +++ b/capifcore/internal/publishservice/publishservice.go @@ -158,18 +158,22 @@ func (ps *PublishService) GetApfIdServiceApis(ctx echo.Context, apfId string) er // Publish a new API. func (ps *PublishService) PostApfIdServiceApis(ctx echo.Context, apfId string) error { var newServiceAPIDescription publishapi.ServiceAPIDescription + errorMsg := "Unable to register the service due to: %s " err := ctx.Bind(&newServiceAPIDescription) if err != nil { - return sendCoreError(ctx, http.StatusBadRequest, "Invalid format for service "+apfId) + return sendCoreError(ctx, http.StatusBadRequest, fmt.Sprintf(errorMsg, "invalid format for service "+apfId)) } + if err := newServiceAPIDescription.Validate(); err != nil { + return sendCoreError(ctx, http.StatusBadRequest, fmt.Sprintf(errorMsg, err)) + } ps.lock.Lock() defer ps.lock.Unlock() registeredFuncs := ps.serviceRegister.GetAefsForPublisher(apfId) for _, profile := range *newServiceAPIDescription.AefProfiles { if !slices.Contains(registeredFuncs, profile.AefId) { - return sendCoreError(ctx, http.StatusNotFound, fmt.Sprintf("Function %s not registered", profile.AefId)) + return sendCoreError(ctx, http.StatusNotFound, fmt.Sprintf(errorMsg, fmt.Sprintf("function %s not registered", profile.AefId))) } } @@ -344,7 +348,6 @@ func (ps *PublishService) sendEvent(service publishapi.ServiceAPIDescription, ev } func (ps *PublishService) checkProfilesRegistered(apfId string, updatedProfiles []publishapi.AefProfile) error { - registeredFuncs := ps.serviceRegister.GetAefsForPublisher(apfId) for _, profile := range updatedProfiles { if !slices.Contains(registeredFuncs, profile.AefId) { @@ -352,7 +355,6 @@ func (ps *PublishService) checkProfilesRegistered(apfId string, updatedProfiles } } return nil - } // This function wraps sending of an error in the Error format, and