Skip to content

Commit 3e89788

Browse files
author
Jelle Dijkstra
committed
Added validations
1 parent 6ca1ae8 commit 3e89788

File tree

2 files changed

+199
-40
lines changed

2 files changed

+199
-40
lines changed

api/v3/wms_types.go

Lines changed: 127 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -45,70 +45,149 @@ const (
4545

4646
// WMSSpec defines the desired state of WMS.
4747
type WMSSpec struct {
48+
// Optional lifecycle settings
4849
Lifecycle *shared_model.Lifecycle `json:"lifecycle,omitempty"`
4950

5051
// +kubebuilder:validation:Type=object
5152
// +kubebuilder:validation:Schemaless
5253
// +kubebuilder:pruning:PreserveUnknownFields
5354
// Optional strategic merge patch for the pod in the deployment. E.g. to patch the resources or add extra env vars.
54-
PodSpecPatch *corev1.PodSpec `json:"podSpecPatch,omitempty"`
55+
PodSpecPatch *corev1.PodSpec `json:"podSpecPatch,omitempty"`
56+
57+
// Optional specification for the HorizontalAutoscaler
5558
HorizontalPodAutoscalerPatch *autoscalingv2.HorizontalPodAutoscalerSpec `json:"horizontalPodAutoscalerPatch,omitempty"`
56-
Options Options `json:"options,omitempty"`
57-
Service WMSService `json:"service"`
59+
60+
// Optional options for the configuration of the service.
61+
Options Options `json:"options,omitempty"`
62+
63+
// Service specification
64+
Service WMSService `json:"service"`
5865
}
5966

6067
type WMSService struct {
61-
URL string `json:"url"`
62-
Title string `json:"title"`
63-
Abstract string `json:"abstract"`
64-
Keywords []string `json:"keywords"`
65-
OwnerInfoRef string `json:"ownerInfoRef"`
66-
Fees *string `json:"fees,omitempty"`
68+
// URL of the service
69+
// +kubebuilder:validation:Format:=uri
70+
URL string `json:"url"`
71+
72+
// Title of the service
73+
// +kubebuilder:validation:MinLength:=1
74+
Title string `json:"title"`
75+
76+
// Abstract (short description) of the service
77+
// +kubebuilder:validation:MinLength:=1
78+
Abstract string `json:"abstract"`
79+
80+
// Keywords of the service
81+
// +kubebuilder:validation:MinItems:=1
82+
Keywords []string `json:"keywords"`
83+
84+
// Reference to a CR of Kind OwnerInfo
85+
// +kubebuilder:validation:MinLength:=1
86+
OwnerInfoRef string `json:"ownerInfoRef"`
87+
88+
// TODO ??
89+
// +kubebuilder:validation:MinLength:=1
90+
Fees *string `json:"fees,omitempty"`
91+
92+
// AccessConstraints (licence) that are applicable to the service
6793
// +kubebuilder:default="https://creativecommons.org/publicdomain/zero/1.0/deed.nl"
68-
AccessConstraints string `json:"accessConstraints"`
69-
MaxSize *int32 `json:"maxSize,omitempty"`
70-
Inspire *Inspire `json:"inspire,omitempty"`
94+
AccessConstraints string `json:"accessConstraints"`
95+
96+
// TODO??
97+
MaxSize *int32 `json:"maxSize,omitempty"`
98+
99+
// Optional specification Inspire themes and ids
100+
Inspire *Inspire `json:"inspire,omitempty"`
101+
102+
// CRS of the data
103+
// +kubebuilder:validation:Pattern:=`(EPSG|CRS):\d+`
71104
//nolint:tagliatelle
72-
DataEPSG string `json:"dataEPSG"`
73-
Resolution *int32 `json:"resolution,omitempty"`
74-
DefResolution *int32 `json:"defResolution,omitempty"`
105+
DataEPSG string `json:"dataEPSG"`
106+
107+
// TODO ??
108+
Resolution *int32 `json:"resolution,omitempty"`
109+
110+
// TODO ??
111+
DefResolution *int32 `json:"defResolution,omitempty"`
112+
113+
// Optional. Required files for the styling of the service
75114
StylingAssets *StylingAssets `json:"stylingAssets,omitempty"`
76-
Mapfile *Mapfile `json:"mapfile,omitempty"`
77-
Layer Layer `json:"layer"`
115+
116+
// Custom mapfile
117+
Mapfile *Mapfile `json:"mapfile,omitempty"`
118+
119+
// Toplayer
120+
Layer Layer `json:"layer"`
78121
}
79122

80123
// +kubebuilder:validation:XValidation:message="Either blobKeys or configMapRefs is required",rule="has(self.blobKeys) || has(self.configMapRefs)"
81124
type StylingAssets struct {
82-
BlobKeys []string `json:"blobKeys,omitempty"`
125+
// +kubebuilder:validations:MinItems:=1
126+
BlobKeys []string `json:"blobKeys,omitempty"`
127+
128+
// +kubebuilder:validations:MinItems:=1
83129
ConfigMapRefs []ConfigMapRef `json:"configMapRefs,omitempty"`
84130
}
85131

86132
type ConfigMapRef struct {
87-
Name string `json:"name"`
133+
// +kubebuilder:validations:MinLength:=1
134+
Name string `json:"name"`
135+
136+
// +kubebuilder:validations:MinItems:=1
88137
Keys []string `json:"keys,omitempty"`
89138
}
90139

140+
// +kubebuilder:validation:XValidation:message="A layer can only have data or layers, not both.", rule="empty(self.data) || empty(self.layers)"
91141
type Layer struct {
142+
// Name of the layer, required for layers on the 2nd or 3rd level
143+
// +kubebuilder:validations:MinLength:=1
144+
Name *string `json:"name,omitempty"`
145+
146+
// Title of the layer
92147
// +kubebuilder:validations:MinLength:=1
93-
Name *string `json:"name,omitempty"`
94-
Title *string `json:"title,omitempty"`
95-
Abstract *string `json:"abstract,omitempty"`
96-
Keywords []string `json:"keywords"`
148+
Title *string `json:"title,omitempty"`
149+
150+
// Abstract of the layer
151+
// +kubebuilder:validations:MinLength:=1
152+
Abstract *string `json:"abstract,omitempty"`
153+
154+
// Keywords of the layer
155+
// +kubebuilder:validations:MinItems:=1
156+
Keywords []string `json:"keywords"`
157+
158+
// BoundingBoxes of the layer. If omitted the boundingboxes of the parent layer of the service is used.
97159
BoundingBoxes []WMSBoundingBox `json:"boundingBoxes,omitempty"`
160+
161+
// Whether or not the layer is visible. At least one of the layers must be visible.
98162
// +kubebuilder:default:=true
99-
Visible *bool `json:"visible,omitempty"`
100-
Authority *Authority `json:"authority,omitempty"`
101-
DatasetMetadataURL *MetadataURL `json:"datasetMetadataUrl,omitempty"`
102-
MinScaleDenominator *string `json:"minscaledenominator,omitempty"`
103-
MaxScaleDenominator *string `json:"maxscaledenominator,omitempty"`
104-
Styles []Style `json:"styles,omitempty"`
105-
LabelNoClip bool `json:"labelNoClip,omitempty"`
106-
Data *Data `json:"data,omitempty"`
107-
Layers *[]Layer `json:"layers,omitempty"`
108-
}
163+
Visible *bool `json:"visible,omitempty"`
164+
165+
// TODO ??
166+
Authority *Authority `json:"authority,omitempty"`
167+
168+
// Links to metadata
169+
DatasetMetadataURL *MetadataURL `json:"datasetMetadataUrl,omitempty"`
170+
171+
// The minimum scale at which this layer functions
172+
// +kubebuilder:validation:Pattern:=`^[1-9][0-9]*(.[0-9]+)$`
173+
MinScaleDenominator *string `json:"minscaledenominator,omitempty"`
174+
175+
// The maximum scale at which this layer functions
176+
// +kubebuilder:validation:Pattern:=`^[1-9][0-9]*(.[0-9]+)$`
177+
MaxScaleDenominator *string `json:"maxscaledenominator,omitempty"`
178+
179+
// List of styles used by the layer
180+
// +kubebuilder:validations:MinItems:=1
181+
Styles []Style `json:"styles,omitempty"`
109182

110-
type RandomType struct {
111-
FieldA string `json:"fieldA"`
183+
// TODO ??
184+
LabelNoClip bool `json:"labelNoClip,omitempty"`
185+
186+
// Data (gpkg/postgis/tif) used by the layer
187+
Data *Data `json:"data,omitempty"`
188+
189+
// Sublayers of the layer
190+
Layers *[]Layer `json:"layers,omitempty"`
112191
}
113192

114193
type WMSBoundingBox struct {
@@ -134,13 +213,22 @@ type Authority struct {
134213
}
135214

136215
type Style struct {
137-
Name string `json:"name"`
138-
Title *string `json:"title,omitempty"`
139-
Abstract *string `json:"abstract,omitempty"`
216+
// +kubebuilder:validations:MinLength:=1
217+
Name string `json:"name"`
218+
219+
// +kubebuilder:validations:MinLength:=1
220+
Title *string `json:"title,omitempty"`
221+
222+
// +kubebuilder:validations:MinLength:=1
223+
Abstract *string `json:"abstract,omitempty"`
224+
225+
// +kubebuilder:validations:MinLength:=1
140226
Visualization *string `json:"visualization,omitempty"`
141-
Legend *Legend `json:"legend,omitempty"`
227+
228+
Legend *Legend `json:"legend,omitempty"`
142229
}
143230

231+
// TODO add validations + descriptions
144232
type Legend struct {
145233
Width int32 `json:"width"`
146234
Height int32 `json:"height"`

0 commit comments

Comments
 (0)