@@ -2,39 +2,71 @@ package config
22
33import (
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
1112type 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
4072type FeaturesSearchCollections []FeaturesSearchCollection
0 commit comments