github.com/oam-dev/kubevela@v1.9.11/references/cuegen/testdata/valid.go (about) 1 /* 2 Copyright 2023 The KubeVela Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package testdata 18 19 import ( 20 "crypto" 21 "net/http" 22 23 "github.com/kubevela/pkg/cue/cuex/providers" 24 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 25 ) 26 27 type BasicType struct { 28 Field1 string `json:"field1"` 29 Field2 int `json:"field2"` 30 Field3 bool `json:"field3"` 31 Field4 float32 `json:"field4"` 32 Field5 float64 `json:"field5"` 33 Field6 int8 `json:"field6"` 34 Field7 int16 `json:"field7"` 35 Field8 int32 `json:"field8"` 36 Field9 int64 `json:"field9"` 37 Field10 uint `json:"field10"` 38 Field11 uint8 `json:"field11"` 39 Field12 uint16 `json:"field12"` 40 Field13 uint32 `json:"field13"` 41 Field14 uint64 `json:"field14"` 42 Field15 uintptr `json:"field15"` 43 Field16 byte `json:"field16"` 44 Field17 rune `json:"field17"` 45 Field18 interface{} `json:"field18"` 46 Field19 any `json:"field19"` 47 } 48 49 type TagName struct { 50 Field1 string `json:"f1"` 51 Field2 string `json:"f2"` 52 Field3 string `json:"f3"` 53 } 54 55 type SliceAndArray struct { 56 Field1 []string `json:"field1"` 57 Field2 [3]string `json:"field2"` 58 Field3 []int `json:"field3"` 59 Field4 [3]int `json:"field4"` 60 Field5 []bool `json:"field5"` 61 Field6 [3]bool `json:"field6"` 62 Field7 []float32 `json:"field7"` 63 Field8 [3]float32 `json:"field8"` 64 Field9 []float64 `json:"field9"` 65 Field10 [3]float64 `json:"field10"` 66 Field11 [3]byte `json:"field11"` 67 Field12 []byte `json:"field12"` 68 } 69 70 type SmallStruct struct { 71 Field1 string `json:"field1"` 72 Field2 string `json:"field2"` 73 } 74 75 type AnonymousField struct { 76 SmallStruct 77 } 78 79 type ReferenceField struct { 80 Field1 *SmallStruct `json:"field1"` 81 } 82 83 type StructField struct { 84 Field1 SmallStruct `json:"field1"` 85 Field2 *SmallStruct `json:"field2"` 86 } 87 88 type EmbedStruct struct { 89 Field1 struct { 90 Field1 string `json:"field1"` 91 Field2 string `json:"field2"` 92 } `json:"field1"` 93 Field2 struct { 94 Field1 string `json:"field1"` 95 Field2 string `json:"field2"` 96 Field3 struct { 97 Field1 string `json:"field1"` 98 Field2 string `json:"field2"` 99 Field3 struct { 100 Field1 string `json:"field1"` 101 Field2 string `json:"field2"` 102 Field3 struct { 103 Field1 string `json:"field1"` 104 Field2 string `json:"field2"` 105 } `json:"field3"` 106 } `json:"field3"` 107 } `json:"field3"` 108 } `json:"field2"` 109 Field3 http.Header `json:"field3"` 110 Field4 crypto.Hash `json:"field4"` 111 } 112 113 type MapField struct { 114 Field1 map[string]string `json:"field1"` 115 Field2 map[string]int `json:"field2"` 116 Field3 map[string]interface{} `json:"field3"` 117 Field4 map[string]SmallStruct `json:"field4"` 118 Field5 map[string]any `json:"field5"` 119 } 120 121 type EmptyStruct struct{} 122 123 type Interface interface { 124 Foo() 125 } 126 127 // Comment is a test struct1 128 /* Struct is a test struct2 */ 129 /* 130 Struct is a test struct3 131 Struct is a test struct4 132 */ 133 type Comment struct { 134 // Field1 doc 135 Field1 string `json:"field1"` // Field1 comment 136 /* Field2 doc */ 137 Field2 string `json:"field2"` // Field2 comment 138 /* 139 Field3 doc 140 */ 141 Field3 string `json:"field3"` // Field3 comment 142 Field4 string `json:"field4"` // Field4 comment 143 144 // Field5 doc 145 Field5 struct { 146 Field1 string `json:"field1"` // Field5.Field1 comment 147 // Field5.Field2 doc 148 Field2 string `json:"field2"` 149 /* Field5.Field3 doc */ 150 Field3 string `json:"field3"` 151 /* 152 Field5.Field4 doc 153 */ 154 Field4 string `json:"field4"` 155 // Field5.Field5 doc 156 Field5 struct { 157 Field1 string `json:"field1"` // Field5.Field5.Field1 comment 158 // Field5.Field5.Field2 doc 159 Field2 string `json:"field2"` 160 /* Field5.Field5.Field3 doc */ 161 Field3 string `json:"field3"` 162 /* 163 Field5.Field5.Field4 doc 164 */ 165 Field4 string `json:"field4"` 166 } `json:"field5"` 167 } `json:"field5"` 168 169 // Field6 doc 170 Field6 http.Header `json:"field6"` 171 Field7 http.Header `json:"field7"` // Field7 comment 172 // Field8 doc 173 Field8 http.Header `json:"field8"` // Field8 comment 174 Field9 http.Header `json:"field9"` 175 176 /* 177 Field10 doc1 178 Field10 doc2 179 Field10 doc3 180 */ 181 Field10 http.Header `json:"field10"` // Field10 comment 182 183 // Field11 doc 184 Field11 struct { 185 Field1 string `json:"field1"` // Field11.Field1 comment 186 } `json:"field11"` 187 188 // Field12 doc 189 Field12 struct { 190 // Field12.Field1 doc 191 Field1 string `json:"field1"` 192 } `json:"field12"` 193 194 // Field13 doc 195 Field13 struct { 196 Field1 string `json:"field1"` 197 } `json:"field13"` 198 199 // Field14 doc 200 Field14 map[string]string `json:"field14"` 201 } 202 203 type Default struct { 204 A1 string `json:"a1" cue:"default:abc"` 205 A2 string `json:"a2" cue:"default:"` // empty string 206 B1 bool `json:"b1" cue:"default:true"` 207 B2 bool `json:"b2" cue:"default:false"` 208 C1 int `json:"c1" cue:"default:123"` 209 C2 int8 `json:"c2" cue:"default:123"` 210 C3 int16 `json:"c3" cue:"default:123"` 211 C4 int32 `json:"c4" cue:"default:123"` 212 C5 int64 `json:"c5" cue:"default:123"` 213 D1 uint `json:"d1" cue:"default:123"` 214 D2 uint8 `json:"d2" cue:"default:123"` 215 D3 uint16 `json:"d3" cue:"default:123"` 216 D4 uint32 `json:"d4" cue:"default:123"` 217 D5 uint64 `json:"d5" cue:"default:123"` 218 E1 float32 `json:"e1" cue:"default:123.456"` 219 E2 float64 `json:"e2" cue:"default:123.456"` 220 } 221 222 type Enum struct { 223 A string `json:"a" cue:"enum:abc,def,ghi"` 224 B int `json:"b" cue:"enum:1,2,3"` 225 C bool `json:"c" cue:"enum:true,false"` 226 D float64 `json:"d" cue:"enum:1.1,2.2,3.3"` 227 E string `json:"e" cue:"enum:abc,def,ghi;default:ghi"` 228 F int `json:"f" cue:"enum:1,2,3;default:2"` 229 G bool `json:"g" cue:"enum:true,false;default:false"` 230 H float64 `json:"h" cue:"enum:1.1,2.2,3.3;default:1.1"` // if default value is first enum, '*' will not be added 231 I string `json:"i" cue:"enum:abc"` 232 } 233 234 type Unexported struct { 235 Field1 string `json:"field1"` 236 Field2 struct { 237 Field1 string `json:"field1"` 238 field2 string // unexported field will be ignored 239 Field3 struct { 240 Field1 string `json:"field1"` 241 field2 string // unexported field will be ignored 242 Field3 string `json:"field3"` 243 } `json:"field3"` 244 } `json:"field2"` 245 field3 string // unexported field will be ignored 246 } 247 248 // RequestVars is the vars for http request 249 // TODO: support timeout & tls 250 type RequestVars struct { 251 Method string `json:"method"` 252 URL string `json:"url"` 253 Request struct { 254 Body string `json:"body"` 255 Header http.Header `json:"header"` 256 Trailer http.Header `json:"trailer"` 257 } `json:"request"` 258 } 259 260 // ResponseVars is the vars for http response 261 type ResponseVars struct { 262 Body string `json:"body"` 263 Header http.Header `json:"header"` 264 Trailer http.Header `json:"trailer"` 265 StatusCode int `json:"statusCode"` 266 } 267 268 // DoParams is the params for http request 269 type DoParams providers.Params[RequestVars] 270 271 // DoReturns returned struct for http response 272 type DoReturns providers.Returns[ResponseVars] 273 274 type ResourceReturns providers.Returns[*unstructured.Unstructured] 275 276 type InlineStruct1 struct { 277 // Field1 doc 278 Field1 string `json:"field11"` // Field1 comment 279 Field2 string `json:"field12"` 280 // Field3 doc 281 Field3 struct { 282 // Field3.Field1 doc 283 Field1 string `json:"field11"` // Field3.Field1 comment 284 Field2 string `json:"field12"` // Field3.Field2 comment 285 } `json:"field13"` 286 } 287 288 type InlineStruct2 struct { 289 // Field1 doc 290 Field1 string `json:"field21"` 291 InlineStruct1 `json:",inline"` // Field1 comment 292 } 293 294 type InlineStruct3 struct { 295 Field1 string `json:"field31"` 296 InlineStruct2 `json:",inline"` 297 } 298 299 type Optional struct { 300 Field1 string `json:"field1,omitempty"` 301 Field2 string `json:"field2"` 302 Field3 string `json:"field3,omitempty"` 303 Field4 string `json:"field4"` 304 Field5 struct { 305 Field1 string `json:"field1,omitempty"` 306 Field2 string `json:"field2"` 307 } `json:"field5"` 308 Field6 struct { 309 Field1 string `json:"field1,omitempty"` 310 Field2 string `json:"field2"` 311 Field3 struct { 312 Field1 string `json:"field1,omitempty"` 313 Field2 string `json:"field2"` 314 } `json:"field3,omitempty"` 315 } `json:"field6,omitempty"` 316 } 317 318 type Skip struct { 319 Field1 string `json:"-"` 320 Field2 string `json:"field2"` 321 Field3 string `json:"-"` 322 Field4 string `json:"field4"` 323 } 324 325 // TypeFilter should be ignored 326 type TypeFilter http.Header 327 328 // TypeFilterStruct should be ignored 329 type TypeFilterStruct struct { 330 Field1 string `json:"field1"` 331 Field2 string `json:"field2"` 332 } 333 334 type SpecialFieldName struct { 335 Field1 string `json:"field1-foo.bar+123<sa"` 336 Field2 string `json:"field2:foo]bar[foo|bar"` 337 }