-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedia_type.v
81 lines (71 loc) · 1.62 KB
/
media_type.v
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
module openapi
import x.json2 { Any }
import json
pub struct MediaType {
pub mut:
schema ObjectRef<Schema>
example Any
examples map[string]ObjectRef<Example>
encoding map[string]Encoding
}
pub fn (mut media_type MediaType) from_json(json Any) ? {
object := json.as_map()
if 'example' in object && 'examples' in object {
return error('Failed MediaType decoding: "example" and "examples" are mutually exclusives')
}
for key, value in object {
match key {
'schema' {
media_type.schema = from_json<Schema>(value.json_str())?
}
'example' {
media_type.example = value
}
'examples' {
media_type.examples = decode_map_sumtype<Example>(value.json_str(), fake_predicat)?
}
'encoding' {
media_type.encoding = decode_map<Encoding>(value.json_str())?
}
else {}
}
}
}
// ---------------------------------------- //
pub struct Encoding {
pub mut:
content_type string
allow_reserved bool
headers map[string]ObjectRef<Header>
style string
explode bool
}
pub fn (mut encoding Encoding) from_json(json Any) ? {
object := json.as_map()
for key, value in object {
match key {
'contentType' {
encoding.content_type = value.str()
}
'allowReserved' {
encoding.allow_reserved = value.bool()
}
'headers' {
encoding.headers = decode_map_sumtype<Header>(value.json_str(), fake_predicat)?
}
'style' {
encoding.style = value.str()
}
'explode' {
encoding.explode = value.bool()
}
else {}
}
}
if 'style' !in object {
encoding.style = 'form'
}
if 'explode' !in object && encoding.style == 'form' {
encoding.explode = true
}
}