Skip to content

Commit c04b1db

Browse files
beckclClemens Beckthbkrkr
authored
Validation: Format items:Pattern as code (#139)
This formats the values of the kubebuilder:validation:items:Pattern markers in the same way as the kubebuilder:validation:Pattern markers. --------- Co-authored-by: Clemens Beck <mail@beckcl.dev> Co-authored-by: Thibault Richard <thbkrkr@users.noreply.github.com>
1 parent b7cc7bb commit c04b1db

5 files changed

Lines changed: 8 additions & 1 deletion

File tree

processor/processor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ func parseMarkers(markers markers.MarkerValues) (string, []string) {
544544
name := strings.TrimPrefix(name, "kubebuilder:validation:")
545545

546546
switch name {
547-
case "Pattern":
547+
case "items:Pattern", "Pattern":
548548
value = fmt.Sprintf("`%s`", value)
549549
// FIXME: XValidation currently removed due to being long and difficult to read.
550550
// E.g. "XValidation: {self.page < 200 Please start a new book.}"

test/api/v1/guestbook_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ type GuestbookEntry struct {
127127
// +kubebuilder:validation:MaxLength=80
128128
// +kubebuilder:validation:Pattern=`0*[a-z0-9]*[a-z]*[0-9]`
129129
Name string `json:"name,omitempty"`
130+
// Tags of the entry.
131+
// +kubebuilder:validation:items:Pattern=`[a-z]*`
132+
Tags []string `json:"tags"`
130133
// Time of entry
131134
Time metav1.Time `json:"time,omitempty"`
132135
// Comment by guest. This can be a multi-line comment.

test/expected.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ GuestbookEntry defines an entry in a guest book.
163163
| *`name`* __string__ | Name of the guest (pipe \| should be escaped) + | | MaxLength: 80 +
164164
Pattern: `0\*[a-z0-9]*[a-z]*[0-9]` +
165165

166+
| *`tags`* __string array__ | Tags of the entry. + | | items:Pattern: `[a-z]*` +
167+
166168
| *`time`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#time-v1-meta[$$Time$$]__ | Time of entry + | |
167169
| *`comment`* __string__ | Comment by guest. This can be a multi-line comment. +
168170
Like this one. +

test/expected.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ _Appears in:_
128128
| Field | Description | Default | Validation |
129129
| --- | --- | --- | --- |
130130
| `name` _string_ | Name of the guest (pipe \| should be escaped) | | MaxLength: 80 <br />Pattern: `0*[a-z0-9]*[a-z]*[0-9]` <br /> |
131+
| `tags` _string array_ | Tags of the entry. | | items:Pattern: `[a-z]*` <br /> |
131132
| `time` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#time-v1-meta)_ | Time of entry | | |
132133
| `comment` _string_ | Comment by guest. This can be a multi-line comment.<br />Like this one.<br />Now let's test a list:<br />* a<br />* b<br />Another isolated comment.<br />Looks good? | | Pattern: `0*[a-z0-9]*[a-z]*[0-9]*\|\s` <br /> |
133134
| `rating` _[Rating](#rating)_ | Rating provided by the guest | | Maximum: 5 <br />Minimum: 1 <br /> |

test/hide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ _Appears in:_
129129
| Field | Description | Default | Validation |
130130
| --- | --- | --- | --- |
131131
| `name` _string_ | Name of the guest (pipe \| should be escaped) | | MaxLength: 80 <br />Pattern: `0*[a-z0-9]*[a-z]*[0-9]` <br /> |
132+
| `tags` _string array_ | Tags of the entry. | | items:Pattern: `[a-z]*` <br /> |
132133
| `time` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#time-v1-meta)_ | Time of entry | | |
133134
| `comment` _string_ | Comment by guest. This can be a multi-line comment.<br />Like this one.<br />Now let's test a list:<br />* a<br />* b<br />Another isolated comment.<br />Looks good? | | Pattern: `0*[a-z0-9]*[a-z]*[0-9]*\|\s` <br /> |
134135
| `rating` _[Rating](#rating)_ | Rating provided by the guest | | Maximum: 5 <br />Minimum: 1 <br /> |

0 commit comments

Comments
 (0)