Skip to content

Commit fc17af2

Browse files
use enum artifactTypes (kubeflow#1789)
* use enum artifactTypes Signed-off-by: Adysen Rothman <85646824+adysenrothman@users.noreply.github.com> * remove common ArtifactTypeQueryParam Signed-off-by: Adysen Rothman <85646824+adysenrothman@users.noreply.github.com> * add ability for multi type query Signed-off-by: Adysen Rothman <85646824+adysenrothman@users.noreply.github.com> * fix gen script Signed-off-by: Adysen Rothman <85646824+adysenrothman@users.noreply.github.com> * one more conflict fix Signed-off-by: Adysen Rothman <85646824+adysenrothman@users.noreply.github.com> * allow backwards compatibility Signed-off-by: Adysen Rothman <85646824+adysenrothman@users.noreply.github.com> * remove singular artifacttype Signed-off-by: Adysen Rothman <85646824+adysenrothman@users.noreply.github.com> * move gen script to patch Signed-off-by: Adysen Rothman <85646824+adysenrothman@users.noreply.github.com> * model name var revert Signed-off-by: Adysen Rothman <85646824+adysenrothman@users.noreply.github.com> * py replace 1 Signed-off-by: Adysen Rothman <85646824+adysenrothman@users.noreply.github.com> --------- Signed-off-by: Adysen Rothman <85646824+adysenrothman@users.noreply.github.com>
1 parent 9b7e5c8 commit fc17af2

17 files changed

Lines changed: 231 additions & 96 deletions

api/openapi/catalog.yaml

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,8 @@ paths:
170170
type: string
171171
in: path
172172
required: true
173-
- name: artifact_type
174-
description: Filter artifacts by type.
175-
schema:
176-
type: string
177-
in: query
178-
required: false
173+
- $ref: "#/components/parameters/artifactType"
174+
- $ref: "#/components/parameters/artifact_type"
179175
- $ref: "#/components/parameters/pageSize"
180176
- $ref: "#/components/parameters/orderBy"
181177
- $ref: "#/components/parameters/sortOrder"
@@ -186,10 +182,7 @@ components:
186182
description: Supported artifact types for querying.
187183
enum:
188184
- model-artifact
189-
- doc-artifact
190-
- dataset-artifact
191-
- metric
192-
- parameter
185+
- metrics-artifact
193186
type: string
194187
BaseModel:
195188
type: object
@@ -734,6 +727,35 @@ components:
734727
$ref: "#/components/schemas/OrderByField"
735728
in: query
736729
required: false
730+
artifactType:
731+
style: form
732+
explode: true
733+
examples:
734+
artifactType:
735+
value: model-artifact
736+
name: artifactType
737+
description: "Specifies the artifact type for listing artifacts."
738+
schema:
739+
type: array
740+
items:
741+
$ref: "#/components/schemas/ArtifactTypeQueryParam"
742+
in: query
743+
required: false
744+
artifact_type:
745+
deprecated: true
746+
style: form
747+
explode: true
748+
examples:
749+
artifact_type:
750+
value: model-artifact
751+
name: artifact_type
752+
description: "Specifies the artifact type for listing artifacts."
753+
schema:
754+
type: array
755+
items:
756+
$ref: "#/components/schemas/ArtifactTypeQueryParam"
757+
in: query
758+
required: false
737759
id:
738760
name: id
739761
description: The ID of resource.
@@ -800,18 +822,6 @@ components:
800822
$ref: "#/components/schemas/SortOrder"
801823
in: query
802824
required: false
803-
artifactType:
804-
style: form
805-
explode: true
806-
examples:
807-
artifactType:
808-
value: model-artifact
809-
name: artifactType
810-
description: "Specifies the artifact type for listing artifacts."
811-
schema:
812-
$ref: "#/components/schemas/ArtifactTypeQueryParam"
813-
in: query
814-
required: false
815825
stepIds:
816826
style: form
817827
explode: true

api/openapi/model-registry.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2996,6 +2996,18 @@ components:
29962996
$ref: "#/components/schemas/OrderByField"
29972997
in: query
29982998
required: false
2999+
artifactType:
3000+
style: form
3001+
explode: true
3002+
examples:
3003+
artifactType:
3004+
value: model-artifact
3005+
name: artifactType
3006+
description: "Specifies the artifact type for listing artifacts."
3007+
schema:
3008+
$ref: "#/components/schemas/ArtifactTypeQueryParam"
3009+
in: query
3010+
required: false
29993011
id:
30003012
name: id
30013013
description: The ID of resource.
@@ -3099,18 +3111,6 @@ components:
30993111
$ref: "#/components/schemas/SortOrder"
31003112
in: query
31013113
required: false
3102-
artifactType:
3103-
style: form
3104-
explode: true
3105-
examples:
3106-
artifactType:
3107-
value: model-artifact
3108-
name: artifactType
3109-
description: "Specifies the artifact type for listing artifacts."
3110-
schema:
3111-
$ref: "#/components/schemas/ArtifactTypeQueryParam"
3112-
in: query
3113-
required: false
31143114
stepIds:
31153115
style: form
31163116
explode: true

api/openapi/src/catalog.yaml

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,8 @@ paths:
170170
type: string
171171
in: path
172172
required: true
173-
- name: artifact_type
174-
description: Filter artifacts by type.
175-
schema:
176-
type: string
177-
in: query
178-
required: false
173+
- $ref: "#/components/parameters/artifactType"
174+
- $ref: "#/components/parameters/artifact_type"
179175
- $ref: "#/components/parameters/pageSize"
180176
- $ref: "#/components/parameters/orderBy"
181177
- $ref: "#/components/parameters/sortOrder"
@@ -205,6 +201,12 @@ components:
205201
required:
206202
- items
207203
- $ref: "#/components/schemas/BaseResourceList"
204+
ArtifactTypeQueryParam:
205+
description: Supported artifact types for querying.
206+
enum:
207+
- model-artifact
208+
- metrics-artifact
209+
type: string
208210
CatalogMetricsArtifact:
209211
description: A metadata Artifact Entity.
210212
allOf:
@@ -446,4 +448,33 @@ components:
446448
$ref: "#/components/schemas/OrderByField"
447449
in: query
448450
required: false
451+
artifactType:
452+
style: form
453+
explode: true
454+
examples:
455+
artifactType:
456+
value: model-artifact
457+
name: artifactType
458+
description: "Specifies the artifact type for listing artifacts."
459+
schema:
460+
type: array
461+
items:
462+
$ref: "#/components/schemas/ArtifactTypeQueryParam"
463+
in: query
464+
required: false
465+
artifact_type:
466+
deprecated: true
467+
style: form
468+
explode: true
469+
examples:
470+
artifact_type:
471+
value: model-artifact
472+
name: artifact_type
473+
description: "Specifies the artifact type for listing artifacts."
474+
schema:
475+
type: array
476+
items:
477+
$ref: "#/components/schemas/ArtifactTypeQueryParam"
478+
in: query
479+
required: false
449480
tags: []

api/openapi/src/lib/common.yaml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
components:
22
schemas:
3-
ArtifactTypeQueryParam:
4-
description: Supported artifact types for querying.
5-
enum:
6-
- model-artifact
7-
- doc-artifact
8-
- dataset-artifact
9-
- metric
10-
- parameter
11-
type: string
123
BaseModel:
134
type: object
145
properties:
@@ -399,18 +390,6 @@ components:
399390
$ref: "#/components/schemas/SortOrder"
400391
in: query
401392
required: false
402-
artifactType:
403-
style: form
404-
explode: true
405-
examples:
406-
artifactType:
407-
value: model-artifact
408-
name: artifactType
409-
description: "Specifies the artifact type for listing artifacts."
410-
schema:
411-
$ref: "#/components/schemas/ArtifactTypeQueryParam"
412-
in: query
413-
required: false
414393
stepIds:
415394
style: form
416395
explode: true

api/openapi/src/model-registry.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,15 @@ components:
16601660
- ABANDONED
16611661
- REFERENCE
16621662
type: string
1663+
ArtifactTypeQueryParam:
1664+
description: Supported artifact types for querying.
1665+
enum:
1666+
- model-artifact
1667+
- doc-artifact
1668+
- dataset-artifact
1669+
- metric
1670+
- parameter
1671+
type: string
16631672
ArtifactUpdate:
16641673
description: An Artifact to be updated.
16651674
oneOf:
@@ -2702,6 +2711,18 @@ components:
27022711
$ref: "#/components/schemas/OrderByField"
27032712
in: query
27042713
required: false
2714+
artifactType:
2715+
style: form
2716+
explode: true
2717+
examples:
2718+
artifactType:
2719+
value: model-artifact
2720+
name: artifactType
2721+
description: "Specifies the artifact type for listing artifacts."
2722+
schema:
2723+
$ref: "#/components/schemas/ArtifactTypeQueryParam"
2724+
in: query
2725+
required: false
27052726
securitySchemes: {}
27062727
links:
27072728
# Artifact

catalog/internal/catalog/catalog.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ type ListModelsParams struct {
1818
}
1919

2020
type ListArtifactsParams struct {
21-
PageSize int32
22-
OrderBy model.OrderByField
23-
SortOrder model.SortOrder
24-
NextPageToken *string
25-
ArtifactType *string
21+
PageSize int32
22+
OrderBy model.OrderByField
23+
SortOrder model.SortOrder
24+
NextPageToken *string
25+
ArtifactTypesFilter []string
2626
}
2727

2828
// APIProvider implements the API endpoints.

catalog/internal/catalog/db_catalog.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ func (d *dbCatalogImpl) GetArtifacts(ctx context.Context, modelName string, sour
153153
parentResourceID32 := int32(parentResourceID)
154154

155155
artifactsList, err := d.catalogArtifactRepository.List(dbmodels.CatalogArtifactListOptions{
156-
ParentResourceID: &parentResourceID32,
157-
ArtifactType: params.ArtifactType,
156+
ParentResourceID: &parentResourceID32,
157+
ArtifactTypesFilter: params.ArtifactTypesFilter,
158158
Pagination: mrmodels.Pagination{
159159
PageSize: &pageSize,
160160
OrderBy: &orderBy,

catalog/internal/db/models/catalog_artifact.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import (
77

88
type CatalogArtifactListOptions struct {
99
models.Pagination
10-
Name *string
11-
ExternalID *string
12-
ParentResourceID *int32
13-
ArtifactType *string
10+
Name *string
11+
ExternalID *string
12+
ParentResourceID *int32
13+
ArtifactType *string
14+
ArtifactTypesFilter []string
1415
}
1516

1617
// GetRestEntityType implements the FilterApplier interface

catalog/internal/db/service/catalog_artifact.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/kubeflow/model-registry/internal/db/schema"
1111
"github.com/kubeflow/model-registry/internal/db/scopes"
1212
"github.com/kubeflow/model-registry/internal/db/utils"
13+
"github.com/kubeflow/model-registry/pkg/api"
1314
"gorm.io/gorm"
1415
)
1516

@@ -77,8 +78,28 @@ func (r *CatalogArtifactRepositoryImpl) List(listOptions models.CatalogArtifactL
7778
query = query.Where("external_id = ?", listOptions.ExternalID)
7879
}
7980

80-
// Filter by artifact type if specified
81-
if listOptions.ArtifactType != nil && *listOptions.ArtifactType != "" {
81+
// Filter by artifact type(s) if specified
82+
if len(listOptions.ArtifactTypesFilter) > 0 {
83+
// Handle multiple artifact types
84+
typeIDs := []int32{}
85+
for _, artifactType := range listOptions.ArtifactTypesFilter {
86+
// Handle "null" string as invalid artifact type
87+
if artifactType == "null" || artifactType == "" {
88+
return nil, fmt.Errorf("invalid artifact type: empty or null value provided: %w", api.ErrBadRequest)
89+
}
90+
typeID, err := r.getTypeIDFromArtifactType(artifactType)
91+
if err != nil {
92+
return nil, fmt.Errorf("invalid catalog artifact type %s: %w", artifactType, err)
93+
}
94+
typeIDs = append(typeIDs, typeID)
95+
}
96+
query = query.Where("type_id IN ?", typeIDs)
97+
} else if listOptions.ArtifactType != nil {
98+
// Handle single artifact type for backward compatibility
99+
// Handle "null" string as invalid artifact type
100+
if *listOptions.ArtifactType == "null" || *listOptions.ArtifactType == "" {
101+
return nil, fmt.Errorf("invalid artifact type: empty or null value provided: %w", api.ErrBadRequest)
102+
}
82103
typeID, err := r.getTypeIDFromArtifactType(*listOptions.ArtifactType)
83104
if err != nil {
84105
return nil, fmt.Errorf("invalid catalog artifact type %s: %w", *listOptions.ArtifactType, err)

catalog/internal/server/openapi/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ type ModelCatalogServiceAPIServicer interface {
3737
FindModelsFilterOptions(context.Context) (ImplResponse, error)
3838
FindSources(context.Context, string, string, model.OrderByField, model.SortOrder, string) (ImplResponse, error)
3939
GetModel(context.Context, string, string) (ImplResponse, error)
40-
GetAllModelArtifacts(context.Context, string, string, string, string, model.OrderByField, model.SortOrder, string) (ImplResponse, error)
40+
GetAllModelArtifacts(context.Context, string, string, []model.ArtifactTypeQueryParam, []model.ArtifactTypeQueryParam, string, model.OrderByField, model.SortOrder, string) (ImplResponse, error)
4141
}

0 commit comments

Comments
 (0)