-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreference.v
More file actions
45 lines (36 loc) · 879 Bytes
/
reference.v
File metadata and controls
45 lines (36 loc) · 879 Bytes
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
module openapi
import x.json2 { Any, raw_decode }
import json
pub struct Reference {
pub mut:
ref string
}
pub fn (mut reference Reference) from_json(json Any) ? {
object := json.as_map()
check_required<Reference>(object, '\$ref')?
for key, value in object {
match key {
'\$ref' {
reference.ref = value.str()
}
else {}
}
}
}
// ---------------------------------------- //
pub type ObjectRef<T> = Reference | T
pub fn from_json<T>(json Any) ?ObjectRef<T> {
if tmp := decode<Reference>(json.json_str()) {
return tmp
}
return decode<T>(json.json_str()) or {
return error('Failed ObjectRef<$T.name> decoding: $err')
}
}
// ---------------------------------------- //
pub fn (mut object []ObjectRef<Parameter>) from_json(json Any) ? {
for value in json.arr() {
str := raw_decode(value.json_str())?
object << from_json<Parameter>(str)?
}
}