Debian Codegraph @

test/integration/testdata/valuevalidation/alpha.go

raw symbols SCIP
1 package valuevalidation
2
3 import (
4 "k8s.io/kube-openapi/pkg/common"
5 "k8s.io/kube-openapi/pkg/validation/spec"
6 )
7
8 // Dummy type to test the openapi-gen API rule checker.
9 // The API rule violations are in format of:
10 // -> +k8s:validation:[validation rule]=[value]
11
12 // +k8s:validation:maxProperties=5
13 // +k8s:validation:minProperties=1
14 // +k8s:openapi-gen=true
15 // +k8s:validation:cel[0]:rule="self == oldSelf"
16 // +k8s:validation:cel[0]:message="foo"
17 type Foo struct {
18 // +k8s:validation:maxLength=5
19 // +k8s:validation:minLength=1
20 // +k8s:validation:pattern="^a.*b$"
21 StringValue string
22
23 // +k8s:validation:maximum=5.0
24 // +k8s:validation:minimum=1.0
25 // +k8s:validation:exclusiveMinimum=true
26 // +k8s:validation:exclusiveMaximum=true
27 // +k8s:validation:multipleOf=2.0
28 NumberValue float64
29
30 // +k8s:validation:maxItems=5
31 // +k8s:validation:minItems=1
32 // +k8s:validation:uniqueItems=true
33 ArrayValue []string
34
35 // +k8s:validation:minProperties=1
36 // +k8s:validation:maxProperties=5
37 MapValue map[string]string
38
39 // +k8s:validation:cel[0]:rule="self.length() > 0"
40 // +k8s:validation:cel[0]:message="string message"
41 // +k8s:validation:cel[1]:rule="self.length() % 2 == 0"
42 // +k8s:validation:cel[1]:messageExpression="self + ' hello'"
43 // +optional
44 CELField string `json:"celField"`
45 }
46
47 // This one has an open API v3 definition
48 // +k8s:validation:maxProperties=5
49 // +k8s:openapi-gen=true
50 // +k8s:validation:cel[0]:rule="self == oldSelf"
51 // +k8s:validation:cel[0]:message="foo2"
52 type Foo2 struct{}
53
54 func (Foo2) OpenAPIV3Definition() common.OpenAPIDefinition {
55 return common.OpenAPIDefinition{
56 Schema: spec.Schema{
57 SchemaProps: spec.SchemaProps{
58 Type: []string{"object"},
59 },
60 },
61 }
62 }
63
64 func (Foo2) OpenAPISchemaType() []string {
65 return []string{"test-type"}
66 }
67
68 func (Foo2) OpenAPISchemaFormat() string {
69 return "test-format"
70 }
71
72 // This one has a OneOf
73 // +k8s:openapi-gen=true
74 // +k8s:validation:maxProperties=5
75 // +k8s:openapi-gen=true
76 // +k8s:validation:cel[0]:rule="self == oldSelf"
77 // +k8s:validation:cel[0]:message="foo3"
78 type Foo3 struct{}
79
80 func (Foo3) OpenAPIV3OneOfTypes() []string {
81 return []string{"number", "string"}
82 }
83 func (Foo3) OpenAPISchemaType() []string {
84 return []string{"string"}
85 }
86 func (Foo3) OpenAPISchemaFormat() string {
87 return "string"
88 }
89
90 // this one should ignore marker comments
91 // +k8s:openapi-gen=true
92 // +k8s:validation:maximum=6
93 // +k8s:validation:cel[0]:rule="self == oldSelf"
94 // +k8s:validation:cel[0]:message="foo4"
95 type Foo4 struct{}
96
97 func (Foo4) OpenAPIDefinition() common.OpenAPIDefinition {
98 return common.OpenAPIDefinition{
99 Schema: spec.Schema{
100 SchemaProps: spec.SchemaProps{
101 Type: []string{"integer"},
102 },
103 },
104 }
105 }
106
107 // +k8s:openapi-gen=true
108 // +k8s:validation:maxProperties=5
109 // +k8s:validation:minProperties=1
110 // +k8s:validation:cel[0]:rule="self == oldSelf"
111 // +k8s:validation:cel[0]:message="foo5"
112 type Foo5 struct{}
113
114 func (Foo5) OpenAPIV3Definition() common.OpenAPIDefinition {
115 return common.OpenAPIDefinition{
116 Schema: spec.Schema{
117 SchemaProps: spec.SchemaProps{
118 Type: []string{"object"},
119 },
120 },
121 }
122 }
123
124 func (Foo5) OpenAPISchemaType() []string {
125 return []string{"test-type"}
126 }
127
128 func (Foo5) OpenAPISchemaFormat() string {
129 return "test-format"
130 }