Skip to content

Commit 60ad7ae

Browse files
authored
Merge pull request #41 from planetlabs/optional-crs-trs
Omit CRS in extent if not present
2 parents d57da74 + ecbbaa5 commit 60ad7ae

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

api/features.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ type Extent struct {
8787

8888
type SpatialExtent struct {
8989
Bbox [][]float64 `json:"bbox"`
90-
Crs string `json:"crs"`
90+
Crs string `json:"crs,omitempty"`
9191
}
9292

9393
type TemporalExtent struct {
9494
Interval [][]any `json:"interval"`
95-
Trs string `json:"trs"`
95+
Trs string `json:"trs,omitempty"`
9696
}
9797

9898
type CollectionsList struct {

api/features_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,49 @@ import (
2727
"github.com/stretchr/testify/require"
2828
)
2929

30+
func TestCollectionMarshal(t *testing.T) {
31+
cases := []struct {
32+
name string
33+
collection *api.Collection
34+
expected string
35+
}{
36+
{
37+
name: "minimal",
38+
collection: &api.Collection{
39+
Id: "test-1",
40+
Title: "Test Collection",
41+
Description: "Test collection description.",
42+
Extent: &api.Extent{
43+
Spatial: &api.SpatialExtent{
44+
Bbox: [][]float64{{1, 2, 3, 4}},
45+
},
46+
},
47+
Links: []*api.Link{},
48+
},
49+
expected: `{
50+
"id": "test-1",
51+
"title": "Test Collection",
52+
"description": "Test collection description.",
53+
"extent": {
54+
"spatial": {
55+
"bbox": [[1, 2, 3, 4]]
56+
}
57+
},
58+
"links": []
59+
}`,
60+
},
61+
}
62+
63+
for _, tc := range cases {
64+
t.Run(tc.name, func(t *testing.T) {
65+
actual, err := json.Marshal(tc.collection)
66+
require.NoError(t, err)
67+
assert.JSONEq(t, tc.expected, string(actual))
68+
})
69+
}
70+
71+
}
72+
3073
func TestFeatureMarshal(t *testing.T) {
3174
cases := []struct {
3275
name string

0 commit comments

Comments
 (0)