Skip to content

Commit

Permalink
changed validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Schnides123 committed Jan 3, 2024
1 parent 7197aef commit 0dcc30a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions pkg/generators/markers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"strconv"
"strings"

defaultergen "k8s.io/gengo/examples/defaulter-gen/generators"
"k8s.io/gengo/types"
openapi "k8s.io/kube-openapi/pkg/common"
"k8s.io/kube-openapi/pkg/validation/spec"
Expand Down Expand Up @@ -207,8 +208,13 @@ func parseMarkers(markerComments []string, prefix string) (map[string]any, error
newKey := strings.TrimPrefix(key, prefix)

// Skip ref markers
if len(value) == 1 && regexp.MustCompile(`^(?:\s*ref\s{0,1}\().*\)\s*`).MatchString(value[0]) {
continue
if len(value) == 1 {
foo := value[0]
fmt.Printf("foo: %v\n", foo)
_, ok := defaultergen.ParseSymbolReference(value[0], "")
if ok { // regexp.MustCompile(`^(?:\s*ref\s{0,1}\().*\)\s*`).MatchString(value[0]) {
continue
}
}
if len(newKey) == 0 {
return nil, fmt.Errorf("cannot have empty key for marker comment")
Expand Down
2 changes: 1 addition & 1 deletion pkg/generators/markers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestParseCommentTags(t *testing.T) {
t: &numKind,
name: "ignore refs",
comments: []string{
"+k8s:validation:pattern=ref(\"asdf\")",
"+k8s:validation:pattern=ref(asdf)",
},
},
}
Expand Down

0 comments on commit 0dcc30a

Please sign in to comment.