Skip to content

Commit 910a6a7

Browse files
committed
wip
1 parent 1f3143e commit 910a6a7

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

api/v3/atom_types.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type Service struct {
5151
// Language of the service
5252
// +kubebuilder:default:="nl"
5353
// +kubebuilder:validation:MinLength:=2
54-
Lang string `json:"lang"`
54+
Lang string `json:"lang,omitempty"`
5555

5656
// Optional link to a stylesheet used in pages generated by the service.
5757
Stylesheet *smoothoperatormodel.URL `json:"stylesheet,omitempty"`
@@ -133,6 +133,7 @@ type DatasetFeed struct {
133133
// +kubebuilder:validation:Pattern:=`^[0-9a-zA-Z]{8}\-[0-9a-zA-Z]{4}\-[0-9a-zA-Z]{4}\-[0-9a-zA-Z]{4}\-[0-9a-zA-Z]{12}$`
134134
SpatialDatasetIdentifierCode *string `json:"spatialDatasetIdentifierCode,omitempty"`
135135

136+
// TODO user URL type
136137
// SpatialDatasetIdentifierNamespace
137138
// +kubebuilder:validation:Format:=uri
138139
SpatialDatasetIdentifierNamespace *string `json:"spatialDatasetIdentifierNamespace,omitempty"`
@@ -150,6 +151,7 @@ type MetadataLink struct {
150151

151152
// Metadata templates to use
152153
// +kubebuilder:validation:MinItems:=1
154+
// +kubebuilder:validation:items:Enum:=csw;opensearch;html
153155
Templates []string `json:"templates"`
154156
}
155157

@@ -186,7 +188,7 @@ type Entry struct {
186188
// DownloadLink specifies download information for entries
187189
type DownloadLink struct {
188190
// URL to the data
189-
// +kubebuilder:validation:MinLength:=1
191+
// +kubebuilder:validation:Pattern:=^[^\/]+\/.+\/.+
190192
Data string `json:"data"`
191193

192194
// Optional relation if the link, for example: describedby, self or alternate

api/v3/atom_validation.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package v3
22

33
import (
44
"fmt"
5-
65
smoothoperatorv1 "github.com/pdok/smooth-operator/api/v1"
76
smoothoperatorvalidation "github.com/pdok/smooth-operator/pkg/validation"
87

@@ -71,14 +70,32 @@ func ValidateAtom(c client.Client, atom *Atom, warnings *[]string, reasons *[]st
7170
}
7271

7372
func ValidateAtomWithoutClusterChecks(atom *Atom, warnings *[]string, reasons *[]string) {
73+
var path string
7474
if strings.Contains(atom.GetName(), "atom") {
75-
*warnings = append(*warnings, smoothoperatorvalidation.FormatValidationWarning("name should not contain atom", atom.GroupVersionKind(), atom.GetName()))
75+
path = "metadata.name"
76+
smoothoperatorvalidation.AddWarning(warnings, path, "should not contain atom", atom.GroupVersionKind(), atom.GetName())
7677
}
7778

78-
for _, datasetFeed := range atom.Spec.Service.DatasetFeeds {
79-
for _, entry := range datasetFeed.Entries {
79+
for i, datasetFeed := range atom.Spec.Service.DatasetFeeds {
80+
path = fmt.Sprintf("spec.service.datasetFeeds[%d]", i)
81+
if datasetFeed.DatasetMetadataLinks != nil && atom.Spec.Service.ServiceMetadataLinks != nil {
82+
if datasetFeed.DatasetMetadataLinks.MetadataIdentifier == atom.Spec.Service.ServiceMetadataLinks.MetadataIdentifier {
83+
smoothoperatorvalidation.AddReason(reasons, path+".datasetMetadataLinks.MetadataIdentifier", "should not be the same as spec.service.serviceMetadataLinks.metadataIdentifier")
84+
}
85+
}
86+
87+
if datasetFeed.DatasetMetadataLinks != nil && datasetFeed.SpatialDatasetIdentifierCode == nil {
88+
smoothoperatorvalidation.AddReason(reasons, path+".spatialDatasetIdentifierCode", fmt.Sprintf("is required when %s is set", path+".datasetMetadataLinks"))
89+
}
90+
91+
if datasetFeed.SpatialDatasetIdentifierCode != nil && datasetFeed.SpatialDatasetIdentifierNamespace == nil {
92+
smoothoperatorvalidation.AddReason(reasons, path+".spatialDatasetIdentifierNamespace", fmt.Sprintf("is required when %s is set", path+".spatialDatasetIdentifierCode"))
93+
}
94+
95+
for in, entry := range datasetFeed.Entries {
96+
path = fmt.Sprintf("%s.entries[%d]", path, in)
8097
if linkCount := len(entry.DownloadLinks); linkCount > 1 && entry.Content == nil {
81-
*reasons = append(*reasons, "content is required for an Entry with more than 1 DownloadLink")
98+
smoothoperatorvalidation.AddReason(reasons, path+".spatialDatasetIdentifierNamespace", fmt.Sprintf("is required when there are 2 or more downloadLinks"))
8299
}
83100
}
84101
}

config/crd/bases/pdok.nl_atoms.yaml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ spec:
361361
baseUrl:
362362
description: BaseURL of the Atom service. Will be suffixed with
363363
index.xml for the index.
364-
pattern: ^https?://.+
364+
pattern: ^https?://.+/.+
365365
type: string
366366
datasetFeeds:
367367
description: DatasetFeeds in this service
@@ -374,8 +374,12 @@ spec:
374374
the same as the author of the service.
375375
properties:
376376
email:
377+
description: Email of the author
378+
format: email
377379
type: string
378380
name:
381+
description: Name of the author
382+
minLength: 1
379383
type: string
380384
required:
381385
- email
@@ -391,6 +395,10 @@ spec:
391395
templates:
392396
description: Metadata templates to use
393397
items:
398+
enum:
399+
- csw
400+
- opensearch
401+
- html
394402
type: string
395403
minItems: 1
396404
type: array
@@ -445,7 +453,7 @@ spec:
445453
type: object
446454
data:
447455
description: URL to the data
448-
minLength: 1
456+
pattern: ^[^\/]+\/.+\/.+
449457
type: string
450458
rel:
451459
description: 'Optional relation if the link,
@@ -504,7 +512,7 @@ spec:
504512
type: string
505513
uri:
506514
description: URI of the SRS
507-
pattern: ^https?://.+
515+
pattern: ^https?://.+/.+
508516
type: string
509517
required:
510518
- name
@@ -545,7 +553,7 @@ spec:
545553
properties:
546554
href:
547555
description: Actual href of the link
548-
pattern: ^https?://.+
556+
pattern: ^https?://.+/.+
549557
type: string
550558
hreflang:
551559
description: Optional language of the link. If omitted
@@ -616,7 +624,7 @@ spec:
616624
properties:
617625
href:
618626
description: Actual href of the link
619-
pattern: ^https?://.+
627+
pattern: ^https?://.+/.+
620628
type: string
621629
hreflang:
622630
description: Optional language of the link. If omitted the
@@ -661,6 +669,10 @@ spec:
661669
templates:
662670
description: Metadata templates to use
663671
items:
672+
enum:
673+
- csw
674+
- opensearch
675+
- html
664676
type: string
665677
minItems: 1
666678
type: array
@@ -671,7 +683,7 @@ spec:
671683
stylesheet:
672684
description: Optional link to a stylesheet used in pages generated
673685
by the service.
674-
pattern: ^https?://.+
686+
pattern: ^https?://.+/.+
675687
type: string
676688
subtitle:
677689
description: Subtitle of the service
@@ -684,7 +696,6 @@ spec:
684696
required:
685697
- baseUrl
686698
- datasetFeeds
687-
- lang
688699
- ownerInfoRef
689700
- rights
690701
- subtitle

0 commit comments

Comments
 (0)