Skip to content

Commit dd9217c

Browse files
authored
mapped a couple remaining json.RawMessages; sorted model version lists (#21)
1 parent 6ad87b2 commit dd9217c

18 files changed

+113
-33
lines changed

accounting_client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"sync"
66

7-
"github.com/modzy/sdk-go/internal/model"
7+
"github.com/modzy/sdk-go/model"
88
)
99

1010
type AccountingClient interface {

accounting_params.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package modzy
22

3-
import "github.com/modzy/sdk-go/internal/model"
3+
import "github.com/modzy/sdk-go/model"
44

55
// GetEntitlementsOutput -
66
type GetEntitlementsOutput struct {

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.16
44

55
require (
66
github.com/docker/go-units v0.4.0
7+
github.com/hashicorp/go-version v1.3.0 // indirect
78
github.com/peterhellberg/link v1.1.0
89
github.com/pkg/errors v0.9.1
910
github.com/sirupsen/logrus v1.8.1

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
33
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
44
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
55
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
6+
github.com/hashicorp/go-version v1.3.0 h1:McDWVJIU/y+u1BRV06dPaLfLCaT7fUTJLp5r04x7iNw=
7+
github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
68
github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8=
79
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
810
github.com/peterhellberg/link v1.1.0 h1:s2+RH8EGuI/mI4QwrWGSYQCRz7uNgip9BaM04HKu5kc=

job_actions_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"testing"
77
"time"
88

9-
"github.com/modzy/sdk-go/internal/model"
9+
"github.com/modzy/sdk-go/model"
1010
)
1111

1212
type testContextKey string

jobs_client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"time"
1010

1111
"github.com/docker/go-units"
12-
"github.com/modzy/sdk-go/internal/model"
12+
"github.com/modzy/sdk-go/model"
1313
"github.com/pkg/errors"
1414
)
1515

jobs_params.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package modzy
33
import (
44
"time"
55

6-
"github.com/modzy/sdk-go/internal/model"
6+
"github.com/modzy/sdk-go/model"
77
)
88

99
// GetJobDetailsInput -
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

internal/model/model.go renamed to model/model.go

+31-25
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ type ModelVersion struct {
99
}
1010

1111
type ModelVersionSummary struct {
12-
ID string `json:"modelId"`
13-
LatestVersion string `json:"latestVersion"`
14-
Versions []string `json:"versions"`
12+
ID string `json:"modelId"`
13+
LatestVersion string `json:"latestVersion"`
14+
Versions SortedVersions `json:"versions"`
1515
}
1616

1717
type ModelDetailsTimeout struct {
@@ -51,11 +51,11 @@ type ModelRunStatus struct {
5151
}
5252

5353
type ModelTag struct {
54-
Identifier string `json:"identifier"`
55-
Name string `json:"name"`
56-
DataType string `json:"dataType"`
57-
IsCategorical bool `json:"isCategorical"`
58-
Images json.RawMessage `json:"images"`
54+
Identifier string `json:"identifier"`
55+
Name string `json:"name"`
56+
DataType string `json:"dataType"`
57+
IsCategorical bool `json:"isCategorical"`
58+
Images []ModelImage `json:"images"`
5959
}
6060

6161
type ModelImage struct {
@@ -70,15 +70,21 @@ type ModelVisibility struct {
7070
Teams []string `json:"teams"`
7171
}
7272

73+
type ModelFeature struct {
74+
Identifier string `json:"identifier"`
75+
Name string `json:"name"`
76+
Description string `json:"description"`
77+
}
78+
7379
type ModelMetdata struct {
7480
ModelID string `json:"modelId"`
7581
LatestVersion string `json:"latestVersion"`
76-
Versions []string `json:"versions"`
82+
Versions SortedVersions `json:"versions"`
7783
Author string `json:"author"`
7884
Name string `json:"name"`
7985
Description string `json:"description"`
8086
Permalink string `json:"permalink"`
81-
Features json.RawMessage `json:"features"`
87+
Features []ModelFeature `json:"features"`
8288
IsActive bool `json:"isActive"`
8389
IsRecommended bool `json:"isRecommended"`
8490
IsCommercial bool `json:"isCommercial"`
@@ -151,35 +157,35 @@ type ModelDetails struct {
151157
ModelID string `json:"modelID"`
152158
LatestVersion string `json:"latestVersion"`
153159
LatestActiveVersion string `json:"latestActiveVersion"`
154-
Versions []string `json:"versions"`
160+
Versions SortedVersions `json:"versions"`
155161
Author string `json:"author"`
156162
Name string `json:"name"`
157163
Description string `json:"description"`
158164
Permalink string `json:"permalink"`
159-
Features json.RawMessage `json:"features"`
165+
Features []ModelFeature `json:"features"`
160166
IsActive bool `json:"isActive"`
161167
IsRecommended bool `json:"isRecommended"`
162168
IsCommercial bool `json:"isCommercial"`
163169
Tags []ModelTag `json:"tags"`
164170
Images []ModelImage `json:"images"`
165-
SnapshotImages json.RawMessage `json:"snapshotImages"`
171+
SnapshotImages []ModelImage `json:"snapshotImages"`
166172
LastActiveDateTime ModzyTime `json:"lastActiveDateTime"`
167173
Visibility ModelVisibility `json:"visibility"`
168174
}
169175

170176
type RelatedModel struct {
171-
ModelID string `json:"identifier"`
172-
LatestVersion string `json:"latestVersion"`
173-
Versions []string `json:"versions"`
174-
Author string `json:"author"`
175-
Name string `json:"name"`
176-
Description string `json:"description"`
177-
Permalink string `json:"permalink"`
178-
Features json.RawMessage `json:"features"`
179-
IsActive bool `json:"isActive"`
180-
IsRecommended bool `json:"isRecommended"`
181-
Tags []ModelTag `json:"tags"`
182-
Images []ModelImage `json:"images"`
177+
ModelID string `json:"identifier"`
178+
LatestVersion string `json:"latestVersion"`
179+
Versions SortedVersions `json:"versions"`
180+
Author string `json:"author"`
181+
Name string `json:"name"`
182+
Description string `json:"description"`
183+
Permalink string `json:"permalink"`
184+
Features []ModelFeature `json:"features"`
185+
IsActive bool `json:"isActive"`
186+
IsRecommended bool `json:"isRecommended"`
187+
Tags []ModelTag `json:"tags"`
188+
Images []ModelImage `json:"images"`
183189
}
184190

185191
type MinimumEngines struct {

model/sorting.go

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package model
2+
3+
import (
4+
"encoding/json"
5+
"sort"
6+
7+
"github.com/hashicorp/go-version"
8+
)
9+
10+
type SortedVersions []string
11+
12+
func (sv *SortedVersions) UnmarshalJSON(data []byte) error {
13+
var v []string
14+
if err := json.Unmarshal(data, &v); err != nil {
15+
return err
16+
}
17+
*sv = SortVersions(v)
18+
return nil
19+
}
20+
21+
func SortVersions(stringVersions []string) []string {
22+
semvers := []*version.Version{}
23+
24+
for _, raw := range stringVersions {
25+
v, _ := version.NewVersion(raw)
26+
semvers = append(semvers, v)
27+
}
28+
29+
sort.Sort(sort.Reverse(version.Collection(semvers)))
30+
31+
sortedStrings := []string{}
32+
for _, s := range semvers {
33+
sortedStrings = append(sortedStrings, s.String())
34+
}
35+
36+
return sortedStrings
37+
}

model/sorting_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package model_test
2+
3+
import (
4+
"encoding/json"
5+
"testing"
6+
7+
"github.com/modzy/sdk-go/model"
8+
)
9+
10+
func TestSortedVersions(t *testing.T) {
11+
var sorted model.SortedVersions
12+
err := json.Unmarshal([]byte(`["1.0.0","1.0.1"]`), &sorted)
13+
if err != nil {
14+
t.Fatalf("Expected no error: %v", err)
15+
}
16+
17+
if len(sorted) != 2 {
18+
t.Errorf("sort not correct length")
19+
}
20+
if sorted[0] != "1.0.1" {
21+
t.Errorf("sort not correct")
22+
}
23+
if sorted[1] != "1.0.0" {
24+
t.Errorf("sort not correct")
25+
}
26+
}
27+
28+
func TestSortedVersionsErr(t *testing.T) {
29+
sorted := &model.SortedVersions{}
30+
err := sorted.UnmarshalJSON([]byte(`junk`))
31+
if err == nil {
32+
t.Fatalf("Expected an error: %v", sorted)
33+
}
34+
}
File renamed without changes.

internal/model/time_test.go renamed to model/time_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"testing"
88
"time"
99

10-
"github.com/modzy/sdk-go/internal/model"
10+
"github.com/modzy/sdk-go/model"
1111
)
1212

1313
type testTime struct {

models_client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"fmt"
77
"strings"
88

9-
"github.com/modzy/sdk-go/internal/model"
9+
"github.com/modzy/sdk-go/model"
1010
)
1111

1212
type ModelsClient interface {

models_params.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package modzy
22

33
import (
4-
"github.com/modzy/sdk-go/internal/model"
4+
"github.com/modzy/sdk-go/model"
55
)
66

77
// GetModelVersionDetailsInput -

0 commit comments

Comments
 (0)