From 7b0dca02126022b69305111a21f8cea9e88579ca Mon Sep 17 00:00:00 2001 From: Matteo Mortari Date: Fri, 8 Mar 2024 09:50:05 +0100 Subject: [PATCH] fix REST api to use ModelVersionUpdate in PATCH method Signed-off-by: Matteo Mortari --- api/openapi/model-registry.yaml | 2 +- internal/server/openapi/api.go | 2 +- .../openapi/api_model_registry_service.go | 10 +- .../api_model_registry_service_service.go | 15 +- internal/server/openapi/type_asserts.go | 152 +++++++++--------- pkg/openapi/api_model_registry_service.go | 18 +-- 6 files changed, 99 insertions(+), 100 deletions(-) diff --git a/api/openapi/model-registry.yaml b/api/openapi/model-registry.yaml index 08ee1e063..6753d3e35 100644 --- a/api/openapi/model-registry.yaml +++ b/api/openapi/model-registry.yaml @@ -202,7 +202,7 @@ paths: content: application/json: schema: - $ref: "#/components/schemas/ModelVersion" + $ref: "#/components/schemas/ModelVersionUpdate" required: true tags: - ModelRegistryService diff --git a/internal/server/openapi/api.go b/internal/server/openapi/api.go index 079d32df7..238710259 100644 --- a/internal/server/openapi/api.go +++ b/internal/server/openapi/api.go @@ -94,7 +94,7 @@ type ModelRegistryServiceAPIServicer interface { GetServingEnvironments(context.Context, string, model.OrderByField, model.SortOrder, string) (ImplResponse, error) UpdateInferenceService(context.Context, string, model.InferenceServiceUpdate) (ImplResponse, error) UpdateModelArtifact(context.Context, string, model.ModelArtifactUpdate) (ImplResponse, error) - UpdateModelVersion(context.Context, string, model.ModelVersion) (ImplResponse, error) + UpdateModelVersion(context.Context, string, model.ModelVersionUpdate) (ImplResponse, error) UpdateRegisteredModel(context.Context, string, model.RegisteredModelUpdate) (ImplResponse, error) UpdateServingEnvironment(context.Context, string, model.ServingEnvironmentUpdate) (ImplResponse, error) } diff --git a/internal/server/openapi/api_model_registry_service.go b/internal/server/openapi/api_model_registry_service.go index 68cba2769..d13bbebd6 100644 --- a/internal/server/openapi/api_model_registry_service.go +++ b/internal/server/openapi/api_model_registry_service.go @@ -870,22 +870,22 @@ func (c *ModelRegistryServiceAPIController) UpdateModelArtifact(w http.ResponseW // UpdateModelVersion - Update a ModelVersion func (c *ModelRegistryServiceAPIController) UpdateModelVersion(w http.ResponseWriter, r *http.Request) { modelversionIdParam := chi.URLParam(r, "modelversionId") - modelVersionParam := model.ModelVersion{} + modelVersionUpdateParam := model.ModelVersionUpdate{} d := json.NewDecoder(r.Body) d.DisallowUnknownFields() - if err := d.Decode(&modelVersionParam); err != nil { + if err := d.Decode(&modelVersionUpdateParam); err != nil { c.errorHandler(w, r, &ParsingError{Err: err}, nil) return } - if err := AssertModelVersionRequired(modelVersionParam); err != nil { + if err := AssertModelVersionUpdateRequired(modelVersionUpdateParam); err != nil { c.errorHandler(w, r, err, nil) return } - if err := AssertModelVersionConstraints(modelVersionParam); err != nil { + if err := AssertModelVersionUpdateConstraints(modelVersionUpdateParam); err != nil { c.errorHandler(w, r, err, nil) return } - result, err := c.service.UpdateModelVersion(r.Context(), modelversionIdParam, modelVersionParam) + result, err := c.service.UpdateModelVersion(r.Context(), modelversionIdParam, modelVersionUpdateParam) // If an error occurred, encode the error with the status code if err != nil { c.errorHandler(w, r, err, &result) diff --git a/internal/server/openapi/api_model_registry_service_service.go b/internal/server/openapi/api_model_registry_service_service.go index e111dc13c..18ce3323a 100644 --- a/internal/server/openapi/api_model_registry_service_service.go +++ b/internal/server/openapi/api_model_registry_service_service.go @@ -476,14 +476,13 @@ func (s *ModelRegistryServiceAPIService) UpdateModelArtifact(ctx context.Context } // UpdateModelVersion - Update a ModelVersion -func (s *ModelRegistryServiceAPIService) UpdateModelVersion(ctx context.Context, modelversionId string, modelVersion model.ModelVersion) (ImplResponse, error) { - // TODO: this API is getting model.ModelVersion instead of model.ModelVersionUpdate. - // c, err := s.converter.ConvertModelVersionUpdate(&modelVersion) - // if err != nil { - // return Response(500, model.Error{Message: err.Error()}), nil - // } - // modelVersion.Id = &modelversionId - result, err := s.coreApi.UpsertModelVersion(&modelVersion, nil) +func (s *ModelRegistryServiceAPIService) UpdateModelVersion(ctx context.Context, modelversionId string, modelVersionUpdate model.ModelVersionUpdate) (ImplResponse, error) { + modelVersion, err := s.converter.ConvertModelVersionUpdate(&modelVersionUpdate) + if err != nil { + return Response(500, model.Error{Message: err.Error()}), nil + } + modelVersion.Id = &modelversionId + result, err := s.coreApi.UpsertModelVersion(modelVersion, nil) if err != nil { return Response(500, model.Error{Message: err.Error()}), nil } diff --git a/internal/server/openapi/type_asserts.go b/internal/server/openapi/type_asserts.go index fa32e4c35..49116633b 100644 --- a/internal/server/openapi/type_asserts.go +++ b/internal/server/openapi/type_asserts.go @@ -62,23 +62,23 @@ func AssertArtifactStateConstraints(obj model.ArtifactState) error { return nil } -// AssertBaseArtifactCreateRequired checks if the required fields are not zero-ed -func AssertBaseArtifactCreateRequired(obj model.BaseArtifactCreate) error { +// AssertBaseArtifactRequired checks if the required fields are not zero-ed +func AssertBaseArtifactRequired(obj model.BaseArtifact) error { return nil } -// AssertBaseArtifactCreateConstraints checks if the values respects the defined constraints -func AssertBaseArtifactCreateConstraints(obj model.BaseArtifactCreate) error { +// AssertBaseArtifactConstraints checks if the values respects the defined constraints +func AssertBaseArtifactConstraints(obj model.BaseArtifact) error { return nil } -// AssertBaseArtifactRequired checks if the required fields are not zero-ed -func AssertBaseArtifactRequired(obj model.BaseArtifact) error { +// AssertBaseArtifactCreateRequired checks if the required fields are not zero-ed +func AssertBaseArtifactCreateRequired(obj model.BaseArtifactCreate) error { return nil } -// AssertBaseArtifactConstraints checks if the values respects the defined constraints -func AssertBaseArtifactConstraints(obj model.BaseArtifact) error { +// AssertBaseArtifactCreateConstraints checks if the values respects the defined constraints +func AssertBaseArtifactCreateConstraints(obj model.BaseArtifactCreate) error { return nil } @@ -92,23 +92,23 @@ func AssertBaseArtifactUpdateConstraints(obj model.BaseArtifactUpdate) error { return nil } -// AssertBaseExecutionCreateRequired checks if the required fields are not zero-ed -func AssertBaseExecutionCreateRequired(obj model.BaseExecutionCreate) error { +// AssertBaseExecutionRequired checks if the required fields are not zero-ed +func AssertBaseExecutionRequired(obj model.BaseExecution) error { return nil } -// AssertBaseExecutionCreateConstraints checks if the values respects the defined constraints -func AssertBaseExecutionCreateConstraints(obj model.BaseExecutionCreate) error { +// AssertBaseExecutionConstraints checks if the values respects the defined constraints +func AssertBaseExecutionConstraints(obj model.BaseExecution) error { return nil } -// AssertBaseExecutionRequired checks if the required fields are not zero-ed -func AssertBaseExecutionRequired(obj model.BaseExecution) error { +// AssertBaseExecutionCreateRequired checks if the required fields are not zero-ed +func AssertBaseExecutionCreateRequired(obj model.BaseExecutionCreate) error { return nil } -// AssertBaseExecutionConstraints checks if the values respects the defined constraints -func AssertBaseExecutionConstraints(obj model.BaseExecution) error { +// AssertBaseExecutionCreateConstraints checks if the values respects the defined constraints +func AssertBaseExecutionCreateConstraints(obj model.BaseExecutionCreate) error { return nil } @@ -122,23 +122,23 @@ func AssertBaseExecutionUpdateConstraints(obj model.BaseExecutionUpdate) error { return nil } -// AssertBaseResourceCreateRequired checks if the required fields are not zero-ed -func AssertBaseResourceCreateRequired(obj model.BaseResourceCreate) error { +// AssertBaseResourceRequired checks if the required fields are not zero-ed +func AssertBaseResourceRequired(obj model.BaseResource) error { return nil } -// AssertBaseResourceCreateConstraints checks if the values respects the defined constraints -func AssertBaseResourceCreateConstraints(obj model.BaseResourceCreate) error { +// AssertBaseResourceConstraints checks if the values respects the defined constraints +func AssertBaseResourceConstraints(obj model.BaseResource) error { return nil } -// AssertBaseResourceRequired checks if the required fields are not zero-ed -func AssertBaseResourceRequired(obj model.BaseResource) error { +// AssertBaseResourceCreateRequired checks if the required fields are not zero-ed +func AssertBaseResourceCreateRequired(obj model.BaseResourceCreate) error { return nil } -// AssertBaseResourceConstraints checks if the values respects the defined constraints -func AssertBaseResourceConstraints(obj model.BaseResource) error { +// AssertBaseResourceCreateConstraints checks if the values respects the defined constraints +func AssertBaseResourceCreateConstraints(obj model.BaseResourceCreate) error { return nil } @@ -222,8 +222,8 @@ func AssertExecutionStateConstraints(obj model.ExecutionState) error { return nil } -// AssertInferenceServiceCreateRequired checks if the required fields are not zero-ed -func AssertInferenceServiceCreateRequired(obj model.InferenceServiceCreate) error { +// AssertInferenceServiceRequired checks if the required fields are not zero-ed +func AssertInferenceServiceRequired(obj model.InferenceService) error { elements := map[string]interface{}{ "registeredModelId": obj.RegisteredModelId, "servingEnvironmentId": obj.ServingEnvironmentId, @@ -237,13 +237,13 @@ func AssertInferenceServiceCreateRequired(obj model.InferenceServiceCreate) erro return nil } -// AssertInferenceServiceCreateConstraints checks if the values respects the defined constraints -func AssertInferenceServiceCreateConstraints(obj model.InferenceServiceCreate) error { +// AssertInferenceServiceConstraints checks if the values respects the defined constraints +func AssertInferenceServiceConstraints(obj model.InferenceService) error { return nil } -// AssertInferenceServiceRequired checks if the required fields are not zero-ed -func AssertInferenceServiceRequired(obj model.InferenceService) error { +// AssertInferenceServiceCreateRequired checks if the required fields are not zero-ed +func AssertInferenceServiceCreateRequired(obj model.InferenceServiceCreate) error { elements := map[string]interface{}{ "registeredModelId": obj.RegisteredModelId, "servingEnvironmentId": obj.ServingEnvironmentId, @@ -257,8 +257,8 @@ func AssertInferenceServiceRequired(obj model.InferenceService) error { return nil } -// AssertInferenceServiceConstraints checks if the values respects the defined constraints -func AssertInferenceServiceConstraints(obj model.InferenceService) error { +// AssertInferenceServiceCreateConstraints checks if the values respects the defined constraints +func AssertInferenceServiceCreateConstraints(obj model.InferenceServiceCreate) error { return nil } @@ -456,16 +456,6 @@ func AssertMetadataValueConstraints(obj model.MetadataValue) error { return nil } -// AssertModelArtifactCreateRequired checks if the required fields are not zero-ed -func AssertModelArtifactCreateRequired(obj model.ModelArtifactCreate) error { - return nil -} - -// AssertModelArtifactCreateConstraints checks if the values respects the defined constraints -func AssertModelArtifactCreateConstraints(obj model.ModelArtifactCreate) error { - return nil -} - // AssertModelArtifactRequired checks if the required fields are not zero-ed func AssertModelArtifactRequired(obj model.ModelArtifact) error { elements := map[string]interface{}{ @@ -485,6 +475,16 @@ func AssertModelArtifactConstraints(obj model.ModelArtifact) error { return nil } +// AssertModelArtifactCreateRequired checks if the required fields are not zero-ed +func AssertModelArtifactCreateRequired(obj model.ModelArtifactCreate) error { + return nil +} + +// AssertModelArtifactCreateConstraints checks if the values respects the defined constraints +func AssertModelArtifactCreateConstraints(obj model.ModelArtifactCreate) error { + return nil +} + // AssertModelArtifactListRequired checks if the required fields are not zero-ed func AssertModelArtifactListRequired(obj model.ModelArtifactList) error { elements := map[string]interface{}{ @@ -521,6 +521,16 @@ func AssertModelArtifactUpdateConstraints(obj model.ModelArtifactUpdate) error { return nil } +// AssertModelVersionRequired checks if the required fields are not zero-ed +func AssertModelVersionRequired(obj model.ModelVersion) error { + return nil +} + +// AssertModelVersionConstraints checks if the values respects the defined constraints +func AssertModelVersionConstraints(obj model.ModelVersion) error { + return nil +} + // AssertModelVersionCreateRequired checks if the required fields are not zero-ed func AssertModelVersionCreateRequired(obj model.ModelVersionCreate) error { elements := map[string]interface{}{ @@ -540,16 +550,6 @@ func AssertModelVersionCreateConstraints(obj model.ModelVersionCreate) error { return nil } -// AssertModelVersionRequired checks if the required fields are not zero-ed -func AssertModelVersionRequired(obj model.ModelVersion) error { - return nil -} - -// AssertModelVersionConstraints checks if the values respects the defined constraints -func AssertModelVersionConstraints(obj model.ModelVersion) error { - return nil -} - // AssertModelVersionListRequired checks if the required fields are not zero-ed func AssertModelVersionListRequired(obj model.ModelVersionList) error { elements := map[string]interface{}{ @@ -606,23 +606,23 @@ func AssertOrderByFieldConstraints(obj model.OrderByField) error { return nil } -// AssertRegisteredModelCreateRequired checks if the required fields are not zero-ed -func AssertRegisteredModelCreateRequired(obj model.RegisteredModelCreate) error { +// AssertRegisteredModelRequired checks if the required fields are not zero-ed +func AssertRegisteredModelRequired(obj model.RegisteredModel) error { return nil } -// AssertRegisteredModelCreateConstraints checks if the values respects the defined constraints -func AssertRegisteredModelCreateConstraints(obj model.RegisteredModelCreate) error { +// AssertRegisteredModelConstraints checks if the values respects the defined constraints +func AssertRegisteredModelConstraints(obj model.RegisteredModel) error { return nil } -// AssertRegisteredModelRequired checks if the required fields are not zero-ed -func AssertRegisteredModelRequired(obj model.RegisteredModel) error { +// AssertRegisteredModelCreateRequired checks if the required fields are not zero-ed +func AssertRegisteredModelCreateRequired(obj model.RegisteredModelCreate) error { return nil } -// AssertRegisteredModelConstraints checks if the values respects the defined constraints -func AssertRegisteredModelConstraints(obj model.RegisteredModel) error { +// AssertRegisteredModelCreateConstraints checks if the values respects the defined constraints +func AssertRegisteredModelCreateConstraints(obj model.RegisteredModelCreate) error { return nil } @@ -672,8 +672,8 @@ func AssertRegisteredModelUpdateConstraints(obj model.RegisteredModelUpdate) err return nil } -// AssertServeModelCreateRequired checks if the required fields are not zero-ed -func AssertServeModelCreateRequired(obj model.ServeModelCreate) error { +// AssertServeModelRequired checks if the required fields are not zero-ed +func AssertServeModelRequired(obj model.ServeModel) error { elements := map[string]interface{}{ "modelVersionId": obj.ModelVersionId, } @@ -686,13 +686,13 @@ func AssertServeModelCreateRequired(obj model.ServeModelCreate) error { return nil } -// AssertServeModelCreateConstraints checks if the values respects the defined constraints -func AssertServeModelCreateConstraints(obj model.ServeModelCreate) error { +// AssertServeModelConstraints checks if the values respects the defined constraints +func AssertServeModelConstraints(obj model.ServeModel) error { return nil } -// AssertServeModelRequired checks if the required fields are not zero-ed -func AssertServeModelRequired(obj model.ServeModel) error { +// AssertServeModelCreateRequired checks if the required fields are not zero-ed +func AssertServeModelCreateRequired(obj model.ServeModelCreate) error { elements := map[string]interface{}{ "modelVersionId": obj.ModelVersionId, } @@ -705,8 +705,8 @@ func AssertServeModelRequired(obj model.ServeModel) error { return nil } -// AssertServeModelConstraints checks if the values respects the defined constraints -func AssertServeModelConstraints(obj model.ServeModel) error { +// AssertServeModelCreateConstraints checks if the values respects the defined constraints +func AssertServeModelCreateConstraints(obj model.ServeModelCreate) error { return nil } @@ -746,23 +746,23 @@ func AssertServeModelUpdateConstraints(obj model.ServeModelUpdate) error { return nil } -// AssertServingEnvironmentCreateRequired checks if the required fields are not zero-ed -func AssertServingEnvironmentCreateRequired(obj model.ServingEnvironmentCreate) error { +// AssertServingEnvironmentRequired checks if the required fields are not zero-ed +func AssertServingEnvironmentRequired(obj model.ServingEnvironment) error { return nil } -// AssertServingEnvironmentCreateConstraints checks if the values respects the defined constraints -func AssertServingEnvironmentCreateConstraints(obj model.ServingEnvironmentCreate) error { +// AssertServingEnvironmentConstraints checks if the values respects the defined constraints +func AssertServingEnvironmentConstraints(obj model.ServingEnvironment) error { return nil } -// AssertServingEnvironmentRequired checks if the required fields are not zero-ed -func AssertServingEnvironmentRequired(obj model.ServingEnvironment) error { +// AssertServingEnvironmentCreateRequired checks if the required fields are not zero-ed +func AssertServingEnvironmentCreateRequired(obj model.ServingEnvironmentCreate) error { return nil } -// AssertServingEnvironmentConstraints checks if the values respects the defined constraints -func AssertServingEnvironmentConstraints(obj model.ServingEnvironment) error { +// AssertServingEnvironmentCreateConstraints checks if the values respects the defined constraints +func AssertServingEnvironmentCreateConstraints(obj model.ServingEnvironmentCreate) error { return nil } diff --git a/pkg/openapi/api_model_registry_service.go b/pkg/openapi/api_model_registry_service.go index 6e6361bc4..a6fae4a46 100644 --- a/pkg/openapi/api_model_registry_service.go +++ b/pkg/openapi/api_model_registry_service.go @@ -5103,15 +5103,15 @@ func (a *ModelRegistryServiceAPIService) UpdateModelArtifactExecute(r ApiUpdateM } type ApiUpdateModelVersionRequest struct { - ctx context.Context - ApiService *ModelRegistryServiceAPIService - modelversionId string - modelVersion *ModelVersion + ctx context.Context + ApiService *ModelRegistryServiceAPIService + modelversionId string + modelVersionUpdate *ModelVersionUpdate } // Updated `ModelVersion` information. -func (r ApiUpdateModelVersionRequest) ModelVersion(modelVersion ModelVersion) ApiUpdateModelVersionRequest { - r.modelVersion = &modelVersion +func (r ApiUpdateModelVersionRequest) ModelVersionUpdate(modelVersionUpdate ModelVersionUpdate) ApiUpdateModelVersionRequest { + r.modelVersionUpdate = &modelVersionUpdate return r } @@ -5158,8 +5158,8 @@ func (a *ModelRegistryServiceAPIService) UpdateModelVersionExecute(r ApiUpdateMo localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} localVarFormParams := url.Values{} - if r.modelVersion == nil { - return localVarReturnValue, nil, reportError("modelVersion is required and must be specified") + if r.modelVersionUpdate == nil { + return localVarReturnValue, nil, reportError("modelVersionUpdate is required and must be specified") } // to determine the Content-Type header @@ -5180,7 +5180,7 @@ func (a *ModelRegistryServiceAPIService) UpdateModelVersionExecute(r ApiUpdateMo localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept } // body params - localVarPostBody = r.modelVersion + localVarPostBody = r.modelVersionUpdate req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) if err != nil { return localVarReturnValue, nil, err