Skip to content

Commit c91aba6

Browse files
committed
fix(catalog): regenerate files
And fix badly generated openapi code. Signed-off-by: Paul Boyd <[email protected]>
1 parent 5f5d6ba commit c91aba6

File tree

11 files changed

+3899
-51
lines changed

11 files changed

+3899
-51
lines changed

catalog/internal/server/openapi/api.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,25 @@ import (
1717
model "github.com/kubeflow/model-registry/catalog/pkg/openapi"
1818
)
1919

20-
21-
2220
// ModelCatalogServiceAPIRouter defines the required methods for binding the api requests to a responses for the ModelCatalogServiceAPI
2321
// The ModelCatalogServiceAPIRouter implementation should parse necessary information from the http request,
2422
// pass the data to a ModelCatalogServiceAPIServicer to perform the required actions, then write the service results to the http response.
25-
type ModelCatalogServiceAPIRouter interface {
23+
type ModelCatalogServiceAPIRouter interface {
2624
FindModels(http.ResponseWriter, *http.Request)
2725
FindModelsFilterOptions(http.ResponseWriter, *http.Request)
2826
FindSources(http.ResponseWriter, *http.Request)
2927
GetAllModelArtifacts(http.ResponseWriter, *http.Request)
3028
GetModel(http.ResponseWriter, *http.Request)
3129
}
3230

33-
3431
// ModelCatalogServiceAPIServicer defines the api actions for the ModelCatalogServiceAPI service
3532
// This interface intended to stay up to date with the openapi yaml used to generate it,
3633
// while the service implementation can be ignored with the .openapi-generator-ignore file
3734
// and updated with the logic required for the API.
38-
type ModelCatalogServiceAPIServicer interface {
39-
FindModels(context.Context, []string, string, string, string, string, model.OrderByField, model.SortOrder, string) (ImplResponse, error)
40-
FindModelsFilterOptions(context.Context) (ImplResponse, error)
41-
FindSources(context.Context, string, string, model.OrderByField, model.SortOrder, string) (ImplResponse, error)
42-
GetAllModelArtifacts(context.Context, string, string, string, model.OrderByField, model.SortOrder, string, string) (ImplResponse, error)
43-
GetModel(context.Context, string, string) (ImplResponse, error)
35+
type ModelCatalogServiceAPIServicer interface {
36+
FindModels(context.Context, []string, string, string, string, string, model.OrderByField, model.SortOrder, string) (ImplResponse, error)
37+
FindModelsFilterOptions(context.Context) (ImplResponse, error)
38+
FindSources(context.Context, string, string, model.OrderByField, model.SortOrder, string) (ImplResponse, error)
39+
GetAllModelArtifacts(context.Context, string, string, string, model.OrderByField, model.SortOrder, string, string) (ImplResponse, error)
40+
GetModel(context.Context, string, string) (ImplResponse, error)
4441
}

catalog/internal/server/openapi/api_model_catalog_service.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
package openapi
1212

1313
import (
14-
1514
"net/http"
1615
"strings"
1716

@@ -75,7 +74,7 @@ func (c *ModelCatalogServiceAPIController) Routes() Routes {
7574
},
7675
"GetModel": Route{
7776
strings.ToUpper("Get"),
78-
"/api/model_catalog/v1alpha1/sources/{source_id}/models/{model_name+}",
77+
"/api/model_catalog/v1alpha1/sources/{source_id}/models/*",
7978
c.GetModel,
8079
},
8180
}
@@ -155,7 +154,22 @@ func (c *ModelCatalogServiceAPIController) GetAllModelArtifacts(w http.ResponseW
155154
// GetModel - Get a `CatalogModel`.
156155
func (c *ModelCatalogServiceAPIController) GetModel(w http.ResponseWriter, r *http.Request) {
157156
sourceIdParam := chi.URLParam(r, "source_id")
158-
modelNameParam := chi.URLParam(r, "model_name+")
157+
modelNameParam := chi.URLParam(r, "*")
158+
159+
// Special handling for getModel to delegate /artifacts requests to getAllModelArtifacts
160+
// The wildcard /* pattern catches /artifacts requests, but we want those to go to GetAllModelArtifacts
161+
if strings.HasSuffix(r.URL.Path, "/artifacts") {
162+
// Extract the model name by removing the /artifacts suffix
163+
modelName := strings.TrimSuffix(modelNameParam, "/artifacts")
164+
165+
// Add the model_name parameter to the route context so GetAllModelArtifacts can access it
166+
chi.RouteContext(r.Context()).URLParams.Add("model_name", modelName)
167+
168+
// Call the GetAllModelArtifacts handler directly
169+
c.GetAllModelArtifacts(w, r)
170+
return
171+
}
172+
159173
result, err := c.service.GetModel(r.Context(), sourceIdParam, modelNameParam)
160174
// If an error occurred, encode the error with the status code
161175
if err != nil {

catalog/internal/server/openapi/helpers.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,28 @@
1111
package openapi
1212

1313
import (
14+
"net/http"
1415
"reflect"
15-
"net/http"
1616

1717
model "github.com/kubeflow/model-registry/pkg/openapi"
1818
)
1919

2020
// Response return a ImplResponse struct filled
2121
func Response(code int, body interface{}) ImplResponse {
22-
return ImplResponse {
22+
return ImplResponse{
2323
Code: code,
2424
Body: body,
2525
}
2626
}
2727

2828
func ErrorResponse(code int, err error) ImplResponse {
29-
return ImplResponse{
30-
Code: code,
31-
Body: model.Error{
32-
Code: http.StatusText(code),
33-
Message: err.Error(),
34-
},
35-
}
29+
return ImplResponse{
30+
Code: code,
31+
Body: model.Error{
32+
Code: http.StatusText(code),
33+
Message: err.Error(),
34+
},
35+
}
3636
}
3737

3838
// IsZeroValue checks if the val is the zero-ed value.

catalog/internal/server/openapi/routers.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import (
3030

3131
// A Route defines the parameters for an api endpoint
3232
type Route struct {
33-
Method string
34-
Pattern string
33+
Method string
34+
Pattern string
3535
HandlerFunc http.HandlerFunc
3636
}
3737

@@ -80,8 +80,8 @@ func EncodeJSONResponse(i interface{}, status *int, w http.ResponseWriter) {
8080

8181
if i != nil {
8282
if err := json.NewEncoder(w).Encode(i); err != nil {
83-
// FIXME: is it too late to inform the client of an error at this point??
84-
glog.Errorf("error encoding JSON response: %v", err)
83+
// FIXME: is it too late to inform the client of an error at this point??
84+
glog.Errorf("error encoding JSON response: %v", err)
8585
}
8686
}
8787
}

catalog/internal/server/openapi/type_asserts.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,6 @@ func AssertErrorRequired(obj model.Error) error {
257257
return nil
258258
}
259259

260-
// AssertFilterOptionConstraints checks if the values respects the defined constraints
261-
func AssertFilterOptionConstraints(obj model.FilterOption) error {
262-
return nil
263-
}
264-
265260
// AssertFilterOptionRangeConstraints checks if the values respects the defined constraints
266261
func AssertFilterOptionRangeConstraints(obj model.FilterOptionRange) error {
267262
return nil
@@ -272,25 +267,6 @@ func AssertFilterOptionRangeRequired(obj model.FilterOptionRange) error {
272267
return nil
273268
}
274269

275-
// AssertFilterOptionRequired checks if the required fields are not zero-ed
276-
func AssertFilterOptionRequired(obj model.FilterOption) error {
277-
elements := map[string]interface{}{
278-
"type": obj.Type,
279-
}
280-
for name, el := range elements {
281-
if isZero := IsZeroValue(el); isZero {
282-
return &RequiredError{Field: name}
283-
}
284-
}
285-
286-
if obj.Range != nil {
287-
if err := AssertFilterOptionRangeRequired(*obj.Range); err != nil {
288-
return err
289-
}
290-
}
291-
return nil
292-
}
293-
294270
// AssertFilterOptionsListConstraints checks if the values respects the defined constraints
295271
func AssertFilterOptionsListConstraints(obj model.FilterOptionsList) error {
296272
return nil

catalog/internal/server/openapi/type_asserts_overrides.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,22 @@ func AssertCatalogArtifactRequired(obj model.CatalogArtifact) error {
1010
// checks the fields from CatalogModelArtifact, which doesn't compile.
1111
return nil
1212
}
13+
14+
// AssertFilterOptionRequired checks if the required fields are not zero-ed
15+
func AssertFilterOptionRequired(obj model.FilterOption) error {
16+
elements := map[string]interface{}{
17+
"type": obj.Type,
18+
}
19+
for name, el := range elements {
20+
if isZero := IsZeroValue(el); isZero {
21+
return &RequiredError{Field: name}
22+
}
23+
}
24+
25+
if obj.Range != nil {
26+
if err := AssertFilterOptionRangeRequired(*obj.Range); err != nil {
27+
return err
28+
}
29+
}
30+
return nil
31+
}

catalog/scripts/gen_type_asserts.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ ASSERT_FILE_PATH="$1/type_asserts.go"
77
PROJECT_ROOT=$(realpath "$(dirname "$0")"/..)
88

99
# These files generate with incorrect logic:
10-
rm -f "$1/model_metadata_value.go" "$1/model_catalog_artifact.go"
10+
rm -f "$1/model_metadata_value.go" \
11+
"$1/model_catalog_artifact.go" \
12+
"$1/model_filter_option.go"
1113

1214
python3 "${PROJECT_ROOT}/scripts/gen_type_asserts.py" $1 >"$ASSERT_FILE_PATH"
1315

0 commit comments

Comments
 (0)