Skip to content

Commit 909d494

Browse files
committed
feat: generate server and client files only
Signed-off-by: Sidney Glinton <[email protected]>
1 parent 97988b3 commit 909d494

File tree

14 files changed

+765
-39
lines changed

14 files changed

+765
-39
lines changed

catalog/internal/server/openapi/.openapi-generator/FILES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ model_catalog_model_list.go
1818
model_catalog_source.go
1919
model_catalog_source_list.go
2020
model_error.go
21+
model_filter_option.go
22+
model_filter_option_range.go
23+
model_filter_options_list.go
2124
model_metadata_bool_value.go
2225
model_metadata_double_value.go
2326
model_metadata_int_value.go
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.13.0
1+
7.0.1

catalog/internal/server/openapi/api.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,20 @@ import (
2222
// pass the data to a ModelCatalogServiceAPIServicer to perform the required actions, then write the service results to the http response.
2323
type ModelCatalogServiceAPIRouter interface {
2424
FindModels(http.ResponseWriter, *http.Request)
25+
FindModelsFilterOptions(http.ResponseWriter, *http.Request)
2526
FindSources(http.ResponseWriter, *http.Request)
26-
GetModel(http.ResponseWriter, *http.Request)
2727
GetAllModelArtifacts(http.ResponseWriter, *http.Request)
28+
GetModel(http.ResponseWriter, *http.Request)
2829
}
2930

3031
// ModelCatalogServiceAPIServicer defines the api actions for the ModelCatalogServiceAPI service
3132
// This interface intended to stay up to date with the openapi yaml used to generate it,
3233
// while the service implementation can be ignored with the .openapi-generator-ignore file
3334
// and updated with the logic required for the API.
3435
type ModelCatalogServiceAPIServicer interface {
35-
FindModels(context.Context, []string, string, string, string, model.OrderByField, model.SortOrder, string) (ImplResponse, error)
36+
FindModels(context.Context, []string, string, string, string, model.OrderByField, model.SortOrder, string, string) (ImplResponse, error)
37+
FindModelsFilterOptions(context.Context) (ImplResponse, error)
3638
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)
3740
GetModel(context.Context, string, string) (ImplResponse, error)
38-
GetAllModelArtifacts(context.Context, string, string, string, string, model.OrderByField, model.SortOrder, string) (ImplResponse, error)
3941
}

catalog/internal/server/openapi/api_model_catalog_service.go

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,35 +57,53 @@ func (c *ModelCatalogServiceAPIController) Routes() Routes {
5757
"/api/model_catalog/v1alpha1/models",
5858
c.FindModels,
5959
},
60+
"FindModelsFilterOptions": Route{
61+
strings.ToUpper("Get"),
62+
"/api/model_catalog/v1alpha1/models/filter_options",
63+
c.FindModelsFilterOptions,
64+
},
6065
"FindSources": Route{
6166
strings.ToUpper("Get"),
6267
"/api/model_catalog/v1alpha1/sources",
6368
c.FindSources,
6469
},
65-
"GetModel": Route{
66-
strings.ToUpper("Get"),
67-
"/api/model_catalog/v1alpha1/sources/{source_id}/models/*",
68-
c.GetModel,
69-
},
7070
"GetAllModelArtifacts": Route{
7171
strings.ToUpper("Get"),
7272
"/api/model_catalog/v1alpha1/sources/{source_id}/models/{model_name}/artifacts",
7373
c.GetAllModelArtifacts,
7474
},
75+
"GetModel": Route{
76+
strings.ToUpper("Get"),
77+
"/api/model_catalog/v1alpha1/sources/{source_id}/models/{model_name+}",
78+
c.GetModel,
79+
},
7580
}
7681
}
7782

7883
// FindModels - Search catalog models across sources.
7984
func (c *ModelCatalogServiceAPIController) FindModels(w http.ResponseWriter, r *http.Request) {
8085
query := r.URL.Query()
8186
sourceParam := strings.Split(query.Get("source"), ",")
87+
sourceLabelParam := query.Get("sourceLabel")
8288
qParam := query.Get("q")
83-
filterQueryParam := query.Get("filterQuery")
8489
pageSizeParam := query.Get("pageSize")
8590
orderByParam := query.Get("orderBy")
8691
sortOrderParam := query.Get("sortOrder")
8792
nextPageTokenParam := query.Get("nextPageToken")
88-
result, err := c.service.FindModels(r.Context(), sourceParam, qParam, filterQueryParam, pageSizeParam, model.OrderByField(orderByParam), model.SortOrder(sortOrderParam), nextPageTokenParam)
93+
filterQueryParam := query.Get("filterQuery")
94+
result, err := c.service.FindModels(r.Context(), sourceParam, sourceLabelParam, qParam, pageSizeParam, model.OrderByField(orderByParam), model.SortOrder(sortOrderParam), nextPageTokenParam, filterQueryParam)
95+
// If an error occurred, encode the error with the status code
96+
if err != nil {
97+
c.errorHandler(w, r, err, &result)
98+
return
99+
}
100+
// If no error, encode the body and the result code
101+
EncodeJSONResponse(result.Body, &result.Code, w)
102+
}
103+
104+
// FindModelsFilterOptions - Lists fields and available options that can be used in `filterQuery` on the list models endpoint.
105+
func (c *ModelCatalogServiceAPIController) FindModelsFilterOptions(w http.ResponseWriter, r *http.Request) {
106+
result, err := c.service.FindModelsFilterOptions(r.Context())
89107
// If an error occurred, encode the error with the status code
90108
if err != nil {
91109
c.errorHandler(w, r, err, &result)
@@ -113,6 +131,26 @@ func (c *ModelCatalogServiceAPIController) FindSources(w http.ResponseWriter, r
113131
EncodeJSONResponse(result.Body, &result.Code, w)
114132
}
115133

134+
// GetAllModelArtifacts - List CatalogArtifacts.
135+
func (c *ModelCatalogServiceAPIController) GetAllModelArtifacts(w http.ResponseWriter, r *http.Request) {
136+
query := r.URL.Query()
137+
sourceIdParam := chi.URLParam(r, "source_id")
138+
modelNameParam := chi.URLParam(r, "model_name")
139+
pageSizeParam := query.Get("pageSize")
140+
orderByParam := query.Get("orderBy")
141+
sortOrderParam := query.Get("sortOrder")
142+
nextPageTokenParam := query.Get("nextPageToken")
143+
artifactTypeParam := query.Get("artifactType")
144+
result, err := c.service.GetAllModelArtifacts(r.Context(), sourceIdParam, modelNameParam, pageSizeParam, model.OrderByField(orderByParam), model.SortOrder(sortOrderParam), nextPageTokenParam, artifactTypeParam)
145+
// If an error occurred, encode the error with the status code
146+
if err != nil {
147+
c.errorHandler(w, r, err, &result)
148+
return
149+
}
150+
// If no error, encode the body and the result code
151+
EncodeJSONResponse(result.Body, &result.Code, w)
152+
}
153+
116154
// GetModel - Get a `CatalogModel`.
117155
func (c *ModelCatalogServiceAPIController) GetModel(w http.ResponseWriter, r *http.Request) {
118156
sourceIdParam := chi.URLParam(r, "source_id")
@@ -141,23 +179,3 @@ func (c *ModelCatalogServiceAPIController) GetModel(w http.ResponseWriter, r *ht
141179
// If no error, encode the body and the result code
142180
EncodeJSONResponse(result.Body, &result.Code, w)
143181
}
144-
145-
// GetAllModelArtifacts - List CatalogArtifacts.
146-
func (c *ModelCatalogServiceAPIController) GetAllModelArtifacts(w http.ResponseWriter, r *http.Request) {
147-
query := r.URL.Query()
148-
sourceIdParam := chi.URLParam(r, "source_id")
149-
modelNameParam := chi.URLParam(r, "model_name")
150-
artifactTypeParam := query.Get("artifact_type")
151-
pageSizeParam := query.Get("pageSize")
152-
orderByParam := query.Get("orderBy")
153-
sortOrderParam := query.Get("sortOrder")
154-
nextPageTokenParam := query.Get("nextPageToken")
155-
result, err := c.service.GetAllModelArtifacts(r.Context(), sourceIdParam, modelNameParam, artifactTypeParam, pageSizeParam, model.OrderByField(orderByParam), model.SortOrder(sortOrderParam), nextPageTokenParam)
156-
// If an error occurred, encode the error with the status code
157-
if err != nil {
158-
c.errorHandler(w, r, err, &result)
159-
return
160-
}
161-
// If no error, encode the body and the result code
162-
EncodeJSONResponse(result.Body, &result.Code, w)
163-
}

catalog/internal/server/openapi/api_model_catalog_service_service.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type ModelCatalogServiceAPIService struct {
2525
}
2626

2727
// GetAllModelArtifacts retrieves all model artifacts for a given model from the specified source.
28-
func (m *ModelCatalogServiceAPIService) GetAllModelArtifacts(ctx context.Context, sourceID string, modelName string, artifactType string, pageSize string, orderBy model.OrderByField, sortOrder model.SortOrder, nextPageToken string) (ImplResponse, error) {
28+
func (m *ModelCatalogServiceAPIService) GetAllModelArtifacts(ctx context.Context, sourceID string, modelName string, pageSize string, orderBy model.OrderByField, sortOrder model.SortOrder, nextPageToken string, artifactType string) (ImplResponse, error) {
2929
if newName, err := url.PathUnescape(modelName); err == nil {
3030
modelName = newName
3131
}
@@ -64,7 +64,7 @@ func (m *ModelCatalogServiceAPIService) GetAllModelArtifacts(ctx context.Context
6464
return Response(http.StatusOK, artifacts), nil
6565
}
6666

67-
func (m *ModelCatalogServiceAPIService) FindModels(ctx context.Context, sourceIDs []string, q, filterQuery, pageSize string, orderBy model.OrderByField, sortOrder model.SortOrder, nextPageToken string) (ImplResponse, error) {
67+
func (m *ModelCatalogServiceAPIService) FindModels(ctx context.Context, sourceIDs []string, sourceLabel string, q string, pageSize string, orderBy model.OrderByField, sortOrder model.SortOrder, nextPageToken string, filterQuery string) (ImplResponse, error) {
6868
var err error
6969
pageSizeInt := int32(10)
7070

@@ -78,12 +78,12 @@ func (m *ModelCatalogServiceAPIService) FindModels(ctx context.Context, sourceID
7878

7979
listModelsParams := catalog.ListModelsParams{
8080
Query: q,
81-
FilterQuery: filterQuery,
8281
SourceIDs: sourceIDs,
8382
PageSize: pageSizeInt,
8483
OrderBy: orderBy,
8584
SortOrder: sortOrder,
8685
NextPageToken: &nextPageToken,
86+
// TODO: Add support for sourceLabel and filterQuery
8787
}
8888

8989
models, err := m.provider.ListModels(ctx, listModelsParams)
@@ -94,6 +94,15 @@ func (m *ModelCatalogServiceAPIService) FindModels(ctx context.Context, sourceID
9494
return Response(http.StatusOK, models), nil
9595
}
9696

97+
func (m *ModelCatalogServiceAPIService) FindModelsFilterOptions(ctx context.Context) (ImplResponse, error) {
98+
filterOptions, err := m.provider.GetFilterOptions(ctx)
99+
if err != nil {
100+
return ErrorResponse(http.StatusInternalServerError, err), err
101+
}
102+
103+
return Response(http.StatusOK, filterOptions), nil
104+
}
105+
97106
func (m *ModelCatalogServiceAPIService) GetModel(ctx context.Context, sourceID, modelName string) (ImplResponse, error) {
98107
if newName, err := url.PathUnescape(modelName); err == nil {
99108
modelName = newName

catalog/internal/server/openapi/api_model_catalog_service_service_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,13 @@ func TestFindModels(t *testing.T) {
305305
resp, err := service.FindModels(
306306
context.Background(),
307307
[]string{tc.sourceID},
308+
"", // sourceLabel
308309
tc.q,
309-
tc.filterQuery,
310310
tc.pageSize,
311311
tc.orderBy,
312312
tc.sortOrder,
313313
tc.nextPageToken,
314+
tc.filterQuery,
314315
)
315316

316317
assert.Equal(t, tc.expectedStatus, resp.Code)
@@ -978,6 +979,7 @@ func TestGetAllModelArtifacts(t *testing.T) {
978979
model.ORDERBYFIELD_CREATE_TIME,
979980
model.SORTORDER_ASC,
980981
"",
982+
"", // artifactType
981983
)
982984

983985
// Check response status

catalog/internal/server/openapi/logger.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,23 @@
1111
package openapi
1212

1313
import (
14-
"github.com/go-chi/chi/v5/middleware"
14+
"log"
1515
"net/http"
16+
"time"
1617
)
1718

18-
func Logger(inner http.Handler) http.Handler {
19-
return middleware.Logger(inner)
19+
func Logger(inner http.Handler, name string) http.Handler {
20+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
21+
start := time.Now()
22+
23+
inner.ServeHTTP(w, r)
24+
25+
log.Printf(
26+
"%s %s %s %s",
27+
r.Method,
28+
r.RequestURI,
29+
name,
30+
time.Since(start),
31+
)
32+
})
2033
}

catalog/internal/server/openapi/type_asserts.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,48 @@ 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+
265+
// AssertFilterOptionRangeConstraints checks if the values respects the defined constraints
266+
func AssertFilterOptionRangeConstraints(obj model.FilterOptionRange) error {
267+
return nil
268+
}
269+
270+
// AssertFilterOptionRangeRequired checks if the required fields are not zero-ed
271+
func AssertFilterOptionRangeRequired(obj model.FilterOptionRange) error {
272+
return nil
273+
}
274+
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 err := AssertFilterOptionRangeRequired(obj.Range); err != nil {
287+
return err
288+
}
289+
return nil
290+
}
291+
292+
// AssertFilterOptionsListConstraints checks if the values respects the defined constraints
293+
func AssertFilterOptionsListConstraints(obj model.FilterOptionsList) error {
294+
return nil
295+
}
296+
297+
// AssertFilterOptionsListRequired checks if the required fields are not zero-ed
298+
func AssertFilterOptionsListRequired(obj model.FilterOptionsList) error {
299+
return nil
300+
}
301+
260302
// AssertMetadataBoolValueConstraints checks if the values respects the defined constraints
261303
func AssertMetadataBoolValueConstraints(obj model.MetadataBoolValue) error {
262304
return nil

catalog/openapitools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
33
"spaces": 2,
44
"generator-cli": {
5-
"version": "7.13.0"
5+
"version": "7.0.1"
66
}
77
}

catalog/pkg/openapi/.openapi-generator/FILES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ model_catalog_model_list.go
1515
model_catalog_source.go
1616
model_catalog_source_list.go
1717
model_error.go
18+
model_filter_option.go
19+
model_filter_option_range.go
20+
model_filter_options_list.go
1821
model_metadata_bool_value.go
1922
model_metadata_double_value.go
2023
model_metadata_int_value.go

0 commit comments

Comments
 (0)