Skip to content

Commit

Permalink
Merge pull request #41 from planetlabs/optional-crs-trs
Browse files Browse the repository at this point in the history
Omit CRS in extent if not present
  • Loading branch information
tschaub authored Nov 3, 2023
2 parents d57da74 + ecbbaa5 commit 60ad7ae
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions api/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ type Extent struct {

type SpatialExtent struct {
Bbox [][]float64 `json:"bbox"`
Crs string `json:"crs"`
Crs string `json:"crs,omitempty"`
}

type TemporalExtent struct {
Interval [][]any `json:"interval"`
Trs string `json:"trs"`
Trs string `json:"trs,omitempty"`
}

type CollectionsList struct {
Expand Down
43 changes: 43 additions & 0 deletions api/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,49 @@ import (
"github.com/stretchr/testify/require"
)

func TestCollectionMarshal(t *testing.T) {
cases := []struct {
name string
collection *api.Collection
expected string
}{
{
name: "minimal",
collection: &api.Collection{
Id: "test-1",
Title: "Test Collection",
Description: "Test collection description.",
Extent: &api.Extent{
Spatial: &api.SpatialExtent{
Bbox: [][]float64{{1, 2, 3, 4}},
},
},
Links: []*api.Link{},
},
expected: `{
"id": "test-1",
"title": "Test Collection",
"description": "Test collection description.",
"extent": {
"spatial": {
"bbox": [[1, 2, 3, 4]]
}
},
"links": []
}`,
},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
actual, err := json.Marshal(tc.collection)
require.NoError(t, err)
assert.JSONEq(t, tc.expected, string(actual))
})
}

}

func TestFeatureMarshal(t *testing.T) {
cases := []struct {
name string
Expand Down

0 comments on commit 60ad7ae

Please sign in to comment.