/
x-gen-type-datetime.go
258 lines (207 loc) · 5.28 KB
/
x-gen-type-datetime.go
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
package raml
import (
"github.com/Foxcapades/goop/v1/pkg/option"
"github.com/Foxcapades/lib-go-raml/v0/internal/util/assign"
"github.com/Foxcapades/lib-go-raml/v0/pkg/raml"
"github.com/Foxcapades/lib-go-raml/v0/pkg/raml/rmeta"
"github.com/Foxcapades/lib-go-yaml/v1/pkg/xyml"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"
)
// NewDatetimeType returns a new internal implementation
// of the raml.DatetimeType interface.
//
// Generated @ 2023-01-17T10:02:54.294844187-05:00
func NewDatetimeType() *DatetimeType {
out := &DatetimeType{
examples: raml.NewDatetimeExampleMap(0),
}
out.examples.SerializeOrdered(false)
out.ExtendedDataType = NewExtendedDataType(rmeta.TypeDatetime, out)
return out
}
// DatetimeType is a default generated implementation of
// the raml.DatetimeType interface
//
// Generated @ 2023-01-17T10:02:54.294844187-05:00
type DatetimeType struct {
*ExtendedDataType
def *string
example raml.DatetimeExample
examples raml.DatetimeExampleMap
enum []string
format raml.DateFormat
}
func (o *DatetimeType) SetType(s string) raml.DatetimeType {
o.schema = s
return o
}
func (o *DatetimeType) Default() option.String {
return option.NewMaybeString(o.def)
}
func (o *DatetimeType) SetDefault(i string) raml.DatetimeType {
o.def = &i
return o
}
func (o *DatetimeType) UnsetDefault() raml.DatetimeType {
o.def = nil
return o
}
func (o *DatetimeType) Example() raml.DatetimeExample {
return o.example
}
func (o *DatetimeType) SetExample(ex raml.DatetimeExample) raml.DatetimeType {
o.example = ex
return o
}
func (o *DatetimeType) UnsetExample() raml.DatetimeType {
o.example = nil
return o
}
func (o *DatetimeType) Examples() raml.DatetimeExampleMap {
return o.examples
}
func (o *DatetimeType) SetExamples(examples raml.DatetimeExampleMap) raml.DatetimeType {
if examples == nil {
return o.UnsetExamples()
}
o.examples = examples
return o
}
func (o *DatetimeType) UnsetExamples() raml.DatetimeType {
o.examples = raml.NewDatetimeExampleMap(0)
return o
}
func (o *DatetimeType) SetDisplayName(s string) raml.DatetimeType {
o.displayName = &s
return o
}
func (o *DatetimeType) UnsetDisplayName() raml.DatetimeType {
o.displayName = nil
return o
}
func (o *DatetimeType) SetDescription(s string) raml.DatetimeType {
o.description = &s
return o
}
func (o *DatetimeType) UnsetDescription() raml.DatetimeType {
o.description = nil
return o
}
func (o *DatetimeType) SetAnnotations(annotations raml.AnnotationMap) raml.DatetimeType {
if annotations == nil {
return o.UnsetAnnotations()
}
o.hasAnnotations.mp = annotations
return o
}
func (o *DatetimeType) UnsetAnnotations() raml.DatetimeType {
o.hasAnnotations.mp = raml.NewAnnotationMap(0)
return o
}
func (o *DatetimeType) SetFacetDefinitions(facets raml.FacetMap) raml.DatetimeType {
if facets == nil {
return o.UnsetFacetDefinitions()
}
o.facets = facets
return o
}
func (o *DatetimeType) UnsetFacetDefinitions() raml.DatetimeType {
o.facets = raml.NewFacetMap(0)
return o
}
func (o *DatetimeType) SetXML(x raml.XML) raml.DatetimeType {
o.xml = x
return o
}
func (o *DatetimeType) UnsetXML() raml.DatetimeType {
o.xml = nil
return o
}
func (o *DatetimeType) Enum() []string {
return o.enum
}
func (o *DatetimeType) SetEnum(i []string) raml.DatetimeType {
o.enum = i
return o
}
func (o *DatetimeType) UnsetEnum() raml.DatetimeType {
o.enum = nil
return o
}
func (o *DatetimeType) SetExtraFacets(facets raml.AnyMap) raml.DatetimeType {
if facets == nil {
return o.UnsetExtraFacets()
}
o.hasExtra.mp = facets
return o
}
func (o *DatetimeType) UnsetExtraFacets() raml.DatetimeType {
o.hasExtra.mp = raml.NewAnyMap(0)
return o
}
func (o *DatetimeType) SetRequired(b bool) raml.DatetimeType {
o.required = b
return o
}
func (o *DatetimeType) Format() raml.DateFormat {
return o.format
}
func (o *DatetimeType) SetFormat(f raml.DateFormat) raml.DatetimeType {
o.format = f
return o
}
func (o *DatetimeType) UnsetFormat() raml.DatetimeType {
o.format = nil
return o
}
func (o *DatetimeType) marshal(out raml.AnyMap) error {
logrus.Trace("internal.DatetimeType.marshal")
out.PutIfNotNil(rmeta.KeyDefault, o.def)
if err := o.ExtendedDataType.marshal(out); err != nil {
return err
}
out.PutIfNotNil(rmeta.KeyFormat, o.format)
out.PutIfNotNil(rmeta.KeyEnum, o.enum).
PutIfNotNil(rmeta.KeyExample, o.example)
if o.examples.Len() > 0 {
out.PutIfNotNil(rmeta.KeyExamples, o.examples)
}
return nil
}
func (o *DatetimeType) assign(key, val *yaml.Node) error {
switch key.Value {
case rmeta.KeyExample:
if ex, err := ExampleSortingHat(o.kind); err != nil {
return err
} else if err := ex.UnmarshalRAML(val); err != nil {
return err
} else {
o.example = ex.(raml.DatetimeExample)
}
return nil
case rmeta.KeyExamples:
return UnmarshalDatetimeExampleMapRAML(o.examples, val)
case rmeta.KeyEnum:
return xyml.SequenceForEach(val, func(cur *yaml.Node) error {
if val, err := xyml.ToString(cur); err != nil {
return err
} else {
o.enum = append(o.enum, val)
}
return nil
})
return nil
case rmeta.KeyRequired:
return assign.AsBool(val, &o.required)
}
if key.Value == rmeta.KeyFormat {
if val, err := DateFormatSortingHat(val); err != nil {
return err
} else {
o.format = val
}
return nil
}
return o.ExtendedDataType.assign(key, val)
}