Skip to content

Commit 1c89de2

Browse files
authored
Merge pull request #375 from PDOK/remove-embed-struct
fix: remove embedded struct and include fields directly to allow correct CRD generation
2 parents 477fd8c + e7af16e commit 1c89de2

File tree

5 files changed

+64
-23
lines changed

5 files changed

+64
-23
lines changed

.github/workflows/test-go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
- name: Test generating example CRD
4141
run: hack/generate-crd.sh
4242

43-
- name: Fuzz
43+
- name: Fuzz Testing
4444
run: |
4545
for pkg in $(go list ./...); do
4646
echo "Fuzzing $pkg"

config/ogcapi_features_search.go

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,71 @@ package config
22

33
import (
44
"net/url"
5+
"slices"
56

67
"github.com/PDOK/gokoala/internal/engine/types"
7-
"gopkg.in/yaml.v3"
8+
"github.com/PDOK/gokoala/internal/engine/util"
89
)
910

1011
// +kubebuilder:object:generate=true
1112
type OgcAPIFeaturesSearch struct {
12-
// Builds on top of the OGC API Features configuration.
13-
OgcAPIFeatures `yaml:",inline" json:",inline"`
13+
// Basemap to use in embedded viewer on the HTML pages.
14+
// +kubebuilder:default="OSM"
15+
// +kubebuilder:validation:Enum=OSM;BRT
16+
// +optional
17+
Basemap string `yaml:"basemap,omitempty" json:"basemap,omitempty" default:"OSM" validate:"oneof=OSM BRT"`
1418

1519
// Collections available for search through this API
1620
Collections FeaturesSearchCollections `yaml:"collections" json:"collections" validate:"required,dive"`
1721

22+
// One or more datasources to get the features from (geopackages, postgres, etc).
23+
// Optional since you can also define datasources at the collection level
24+
// +optional
25+
Datasources *Datasources `yaml:"datasources,omitempty" json:"datasources,omitempty"`
26+
27+
// Whether GeoJSON/JSON-FG responses will be validated against the OpenAPI spec
28+
// since it has a significant performance impact when dealing with large JSON payloads.
29+
//
30+
// +kubebuilder:default=true
31+
// +optional
32+
ValidateResponses *bool `yaml:"validateResponses,omitempty" json:"validateResponses,omitempty" default:"true"` // ptr due to https://github.com/creasty/defaults/issues/49
33+
34+
// Maximum number of decimals allowed in geometry coordinates. When not specified (default value of 0) no limit is enforced.
35+
// +optional
36+
// +kubebuilder:validation:Minimum=0
37+
MaxDecimals int `yaml:"maxDecimals,omitempty" json:"maxDecimals,omitempty" default:"0"`
38+
39+
// Force timestamps in features to the UTC timezone.
40+
//
41+
// +kubebuilder:default=false
42+
// +optional
43+
ForceUTC bool `yaml:"forceUtc,omitempty" json:"forceUtc,omitempty"`
44+
1845
// Settings related to the search API/index.
1946
// +optional
2047
SearchSettings SearchSettings `yaml:"searchSettings" json:"searchSettings"`
2148
}
2249

23-
// UnmarshalYAML Handles YAML unmarshalling conflict with the "collections" field
24-
// present in both OgcAPIFeaturesSearch and embedded OgcAPIFeatures.
25-
func (c *OgcAPIFeaturesSearch) UnmarshalYAML(value *yaml.Node) error {
26-
type base OgcAPIFeatures // empty struct/copy to avoid a possible infinite loop
27-
if err := value.Decode((*base)(&c.OgcAPIFeatures)); err != nil {
28-
return err
29-
}
30-
// Favor the 'collections' field from OgcAPIFeaturesSearch
31-
pairSize := 2
32-
for i := 0; i < len(value.Content); i += pairSize {
33-
if value.Content[i].Value == "collections" {
34-
return value.Content[i+1].Decode(&c.Collections)
50+
func (fs *OgcAPIFeaturesSearch) CollectionsSRS() []string {
51+
return fs.CollectionSRS("")
52+
}
53+
54+
func (fs *OgcAPIFeaturesSearch) CollectionSRS(_ string) []string {
55+
uniqueSRSs := make(map[string]struct{})
56+
if fs.Datasources != nil {
57+
for _, d := range fs.Datasources.OnTheFly {
58+
for _, srs := range d.SupportedSrs {
59+
uniqueSRSs[srs.Srs] = struct{}{}
60+
}
61+
}
62+
for _, d := range fs.Datasources.Additional {
63+
uniqueSRSs[d.Srs] = struct{}{}
3564
}
3665
}
37-
return nil
66+
result := util.Keys(uniqueSRSs)
67+
slices.Sort(result)
68+
69+
return result
3870
}
3971

4072
type FeaturesSearchCollections []FeaturesSearchCollection

config/zz_generated.deepcopy.go

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/engine/templates/openapi/features-search.go.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
{
1919
"$ref": "#/components/parameters/q"
2020
},
21-
{{- range $index, $coll := .Config.OgcAPI.FeaturesSearch.OgcAPIFeatures.Collections -}}
21+
{{- range $index, $coll := .Config.OgcAPI.FeaturesSearch.Collections -}}
2222
{{- if $index -}},{{- end -}}
2323
{
2424
"$ref": "#/components/parameters/{{ $coll.ID }}-collection-search"
@@ -566,7 +566,7 @@
566566
"maxLength": 200
567567
}
568568
},
569-
{{- range $index, $coll := .Config.OgcAPI.FeaturesSearch.OgcAPIFeatures.Collections -}}
569+
{{- range $index, $coll := .Config.OgcAPI.FeaturesSearch.Collections -}}
570570
{{- if $index -}},{{- end -}}
571571
"{{ $coll.ID }}-collection-search": {
572572
"name": "{{ $coll.ID }}",
@@ -643,7 +643,7 @@
643643
"default": "http://www.opengis.net/def/crs/OGC/1.3/CRS84",
644644
"enum": [
645645
"http://www.opengis.net/def/crs/OGC/1.3/CRS84"
646-
{{ range $index, $srs := .Config.OgcAPI.FeaturesSearch.OgcAPIFeatures.CollectionsSRS }}
646+
{{ range $index, $srs := .Config.OgcAPI.FeaturesSearch.CollectionsSRS }}
647647
,"http://www.opengis.net/def/crs/EPSG/0/{{ trimPrefix "EPSG:" $srs }}"
648648
{{ end }}
649649
]
@@ -662,7 +662,7 @@
662662
"default": "http://www.opengis.net/def/crs/OGC/1.3/CRS84",
663663
"enum": [
664664
"http://www.opengis.net/def/crs/OGC/1.3/CRS84"
665-
{{ range $index, $srs := .Config.OgcAPI.FeaturesSearch.OgcAPIFeatures.CollectionsSRS }}
665+
{{ range $index, $srs := .Config.OgcAPI.FeaturesSearch.CollectionsSRS }}
666666
,"http://www.opengis.net/def/crs/EPSG/0/{{ trimPrefix "EPSG:" $srs }}"
667667
{{ end }}
668668
]

internal/ogc/features_search/templates/search.go.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ <h2 class="card-header h5">
4444
http://www.opengis.net/def/crs/OGC/1.3/CRS84
4545
</option>
4646
{{ if .Config.OgcAPI.FeaturesSearch }}
47-
{{ range $index, $srs := .Config.OgcAPI.FeaturesSearch.OgcAPIFeatures.CollectionsSRS }}
47+
{{ range $index, $srs := .Config.OgcAPI.FeaturesSearch.CollectionsSRS }}
4848
<option value="http://www.opengis.net/def/crs/EPSG/0/{{ trimPrefix "EPSG:" $srs }}">http://www.opengis.net/def/crs/EPSG/0/{{ trimPrefix "EPSG:" $srs }}</option>
4949
{{ end }}
5050
{{ end }}

0 commit comments

Comments
 (0)