File: alpha.go

package info (click to toggle)
golang-k8s-kube-openapi 0.0~git20241212.2c72e55-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,396 kB
  • sloc: sh: 50; makefile: 5
file content (130 lines) | stat: -rw-r--r-- 3,235 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package valuevalidation

import (
	"k8s.io/kube-openapi/pkg/common"
	"k8s.io/kube-openapi/pkg/validation/spec"
)

// Dummy type to test the openapi-gen API rule checker.
// The API rule violations are in format of:
// -> +k8s:validation:[validation rule]=[value]

// +k8s:validation:maxProperties=5
// +k8s:validation:minProperties=1
// +k8s:openapi-gen=true
// +k8s:validation:cel[0]:rule="self == oldSelf"
// +k8s:validation:cel[0]:message="foo"
type Foo struct {
	// +k8s:validation:maxLength=5
	// +k8s:validation:minLength=1
	// +k8s:validation:pattern="^a.*b$"
	StringValue string

	// +k8s:validation:maximum=5.0
	// +k8s:validation:minimum=1.0
	// +k8s:validation:exclusiveMinimum=true
	// +k8s:validation:exclusiveMaximum=true
	// +k8s:validation:multipleOf=2.0
	NumberValue float64

	// +k8s:validation:maxItems=5
	// +k8s:validation:minItems=1
	// +k8s:validation:uniqueItems=true
	ArrayValue []string

	// +k8s:validation:minProperties=1
	// +k8s:validation:maxProperties=5
	MapValue map[string]string

	// +k8s:validation:cel[0]:rule="self.length() > 0"
	// +k8s:validation:cel[0]:message="string message"
	// +k8s:validation:cel[1]:rule="self.length() % 2 == 0"
	// +k8s:validation:cel[1]:messageExpression="self + ' hello'"
	// +optional
	CELField string `json:"celField"`
}

// This one has an open API v3 definition
// +k8s:validation:maxProperties=5
// +k8s:openapi-gen=true
// +k8s:validation:cel[0]:rule="self == oldSelf"
// +k8s:validation:cel[0]:message="foo2"
type Foo2 struct{}

func (Foo2) OpenAPIV3Definition() common.OpenAPIDefinition {
	return common.OpenAPIDefinition{
		Schema: spec.Schema{
			SchemaProps: spec.SchemaProps{
				Type: []string{"object"},
			},
		},
	}
}

func (Foo2) OpenAPISchemaType() []string {
	return []string{"test-type"}
}

func (Foo2) OpenAPISchemaFormat() string {
	return "test-format"
}

// This one has a OneOf
// +k8s:openapi-gen=true
// +k8s:validation:maxProperties=5
// +k8s:openapi-gen=true
// +k8s:validation:cel[0]:rule="self == oldSelf"
// +k8s:validation:cel[0]:message="foo3"
type Foo3 struct{}

func (Foo3) OpenAPIV3OneOfTypes() []string {
	return []string{"number", "string"}
}
func (Foo3) OpenAPISchemaType() []string {
	return []string{"string"}
}
func (Foo3) OpenAPISchemaFormat() string {
	return "string"
}

// this one should ignore marker comments
// +k8s:openapi-gen=true
// +k8s:validation:maximum=6
// +k8s:validation:cel[0]:rule="self == oldSelf"
// +k8s:validation:cel[0]:message="foo4"
type Foo4 struct{}

func (Foo4) OpenAPIDefinition() common.OpenAPIDefinition {
	return common.OpenAPIDefinition{
		Schema: spec.Schema{
			SchemaProps: spec.SchemaProps{
				Type: []string{"integer"},
			},
		},
	}
}

// +k8s:openapi-gen=true
// +k8s:validation:maxProperties=5
// +k8s:validation:minProperties=1
// +k8s:validation:cel[0]:rule="self == oldSelf"
// +k8s:validation:cel[0]:message="foo5"
type Foo5 struct{}

func (Foo5) OpenAPIV3Definition() common.OpenAPIDefinition {
	return common.OpenAPIDefinition{
		Schema: spec.Schema{
			SchemaProps: spec.SchemaProps{
				Type: []string{"object"},
			},
		},
	}
}

func (Foo5) OpenAPISchemaType() []string {
	return []string{"test-type"}
}

func (Foo5) OpenAPISchemaFormat() string {
	return "test-format"
}