Skip to content

Validation: Format items:Pattern as code #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,8 @@ func parseMarkers(markers markers.MarkerValues) (string, []string) {
name := strings.TrimPrefix(name, "kubebuilder:validation:")

switch name {
case "items:Pattern":
fallthrough
case "Pattern":
value = fmt.Sprintf("`%s`", value)
// FIXME: XValidation currently removed due to being long and difficult to read.
Expand Down
3 changes: 3 additions & 0 deletions test/api/v1/guestbook_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ type GuestbookEntry struct {
// +kubebuilder:validation:MaxLength=80
// +kubebuilder:validation:Pattern=`0*[a-z0-9]*[a-z]*[0-9]`
Name string `json:"name,omitempty"`
// Tags of the entry.
// +kubebuilder:validation:items:Pattern=`[a-z]*`
Tags []string `json:"tags"`
// Time of entry
Time metav1.Time `json:"time,omitempty"`
// Comment by guest. This can be a multi-line comment.
Expand Down
2 changes: 2 additions & 0 deletions test/expected.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ GuestbookEntry defines an entry in a guest book.
| *`name`* __string__ | Name of the guest (pipe \| should be escaped) + | | MaxLength: 80 +
Pattern: `0\*[a-z0-9]*[a-z]*[0-9]` +

| *`tags`* __string array__ | Tags of the entry. + | | items:Pattern: `[a-z]*` +

| *`time`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#time-v1-meta[$$Time$$]__ | Time of entry + | |
| *`comment`* __string__ | Comment by guest. This can be a multi-line comment. +
Like this one. +
Expand Down
1 change: 1 addition & 0 deletions test/expected.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ _Appears in:_
| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `name` _string_ | Name of the guest (pipe \| should be escaped) | | MaxLength: 80 <br />Pattern: `0*[a-z0-9]*[a-z]*[0-9]` <br /> |
| `tags` _string array_ | Tags of the entry. | | items:Pattern: `[a-z]*` <br /> |
| `time` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#time-v1-meta)_ | Time of entry | | |
| `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 /> |
| `rating` _[Rating](#rating)_ | Rating provided by the guest | | Maximum: 5 <br />Minimum: 1 <br /> |
Expand Down
1 change: 1 addition & 0 deletions test/hide.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ _Appears in:_
| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `name` _string_ | Name of the guest (pipe \| should be escaped) | | MaxLength: 80 <br />Pattern: `0*[a-z0-9]*[a-z]*[0-9]` <br /> |
| `tags` _string array_ | Tags of the entry. | | items:Pattern: `[a-z]*` <br /> |
| `time` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#time-v1-meta)_ | Time of entry | | |
| `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 /> |
| `rating` _[Rating](#rating)_ | Rating provided by the guest | | Maximum: 5 <br />Minimum: 1 <br /> |
Expand Down