-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.kt
More file actions
554 lines (480 loc) · 16.8 KB
/
Example.kt
File metadata and controls
554 lines (480 loc) · 16.8 KB
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
/*****************************************************************************
** C A U T I O N **
** This file is auto-generated! **
** If you want to make changes, please see the README.md file. **
** Please do not edit this file directly! **
*****************************************************************************/
package de.lancom.openapi.parser.entity
import tools.jackson.databind.annotation.JsonDeserialize
import tools.jackson.databind.annotation.JsonSerialize
import de.lancom.openapi.common.types.*
import de.lancom.openapi.common.util.*
import de.lancom.openapi.parser.field.Field
import de.lancom.openapi.parser.jackson.EntityDeserializer
import de.lancom.openapi.parser.jackson.EntitySerializer
import de.lancom.openapi.parser.jackson.ReferenceParser
import de.lancom.openapi.parser.jackson.Wrapper
import de.lancom.openapi.parser.ref.Referenceable
// hint:9A1BF04C
@Suppress("PropertyName")
@JsonSerialize(using = Example.Companion.Serializer::class)
@JsonDeserialize(using = Example.Companion.Deserializer::class)
data class Example(
val _summary: Field<String?> = Field.unset(),
val _description: Field<String?> = Field.unset(),
val _value: Field<ExampleJson?> = Field.unset(),
val _externalValue: Field<String?> = Field.unset(),
val _extensions: Field<Map<String, Extension?>> = Field.unset(),
val __field_order: Set<Fields> = Fields.all,
override val __referenceName: String? = null,
) : Referenceable {
///////////////////////
//
// summary
//
///////////////////////
// hint:3A7F9B2E
val summary: String?
get() = _summary.orNull
// hint:F0C48D71
fun setSummaryField(summary: Field<String?>): Example {
return copy(_summary = summary)
.updateFields()
}
// hint:8E56A4D9
fun updateSummaryField(updater: (Field<String?>) -> Field<String?>): Example {
return setSummaryField(updater(_summary))
}
// hint:B1D730FC
fun updateSummary(updater: (String?) -> String?): Example {
return updateSummaryField { field ->
field.flatMap { value ->
Field(updater(value))
}
}
}
// hint:6542E98A
fun mergeSummaryField(summaryFieldToMerge: Field<String?>): Example {
return mergeSummary(summaryFieldToMerge.orNull)
}
// hint:A8BC6F23
fun mergeSummary(summaryToMerge: String?): Example {
return if (summaryToMerge == null) {
this
} else {
val oldSummary = _summary.orNull
if (oldSummary == null) {
setSummaryField(Field(summaryToMerge))
} else {
// hint:2F684DAC
setSummary(summaryToMerge)
}
}
}
// hint:87B3E19C
fun setSummary(summary: String?): Example {
return setSummaryField(Field(summary))
}
// hint:D465F782
fun unsetSummary(): Example {
return setSummaryField(Field.unset())
}
// hint:47C9A0F6
fun addSummary(summary: String): Example {
if (this.summary != null) {
throw IllegalStateException("Field summary of Entity Example is already set to '${this.summary}', refused to add new value '$summary'")
}
return setSummary(summary)
}
///////////////////////
//
// description
//
///////////////////////
// hint:3A7F9B2E
val description: String?
get() = _description.orNull
// hint:F0C48D71
fun setDescriptionField(description: Field<String?>): Example {
return copy(_description = description)
.updateFields()
}
// hint:8E56A4D9
fun updateDescriptionField(updater: (Field<String?>) -> Field<String?>): Example {
return setDescriptionField(updater(_description))
}
// hint:B1D730FC
fun updateDescription(updater: (String?) -> String?): Example {
return updateDescriptionField { field ->
field.flatMap { value ->
Field(updater(value))
}
}
}
// hint:6542E98A
fun mergeDescriptionField(descriptionFieldToMerge: Field<String?>): Example {
return mergeDescription(descriptionFieldToMerge.orNull)
}
// hint:A8BC6F23
fun mergeDescription(descriptionToMerge: String?): Example {
return if (descriptionToMerge == null) {
this
} else {
val oldDescription = _description.orNull
if (oldDescription == null) {
setDescriptionField(Field(descriptionToMerge))
} else {
// hint:2F684DAC
setDescription(descriptionToMerge)
}
}
}
// hint:87B3E19C
fun setDescription(description: String?): Example {
return setDescriptionField(Field(description))
}
// hint:D465F782
fun unsetDescription(): Example {
return setDescriptionField(Field.unset())
}
// hint:47C9A0F6
fun addDescription(description: String): Example {
if (this.description != null) {
throw IllegalStateException("Field description of Entity Example is already set to '${this.description}', refused to add new value '$description'")
}
return setDescription(description)
}
///////////////////////
//
// value
//
///////////////////////
// hint:3A7F9B2E
val value: ExampleJson?
get() = _value.orNull
// hint:F0C48D71
fun setValueField(value: Field<ExampleJson?>): Example {
return copy(_value = value)
.updateFields()
}
// hint:8E56A4D9
fun updateValueField(updater: (Field<ExampleJson?>) -> Field<ExampleJson?>): Example {
return setValueField(updater(_value))
}
// hint:B1D730FC
fun updateValue(updater: (ExampleJson?) -> ExampleJson?): Example {
return updateValueField { field ->
field.flatMap { value ->
Field(updater(value))
}
}
}
// hint:6542E98A
fun mergeValueField(valueFieldToMerge: Field<ExampleJson?>): Example {
return mergeValue(valueFieldToMerge.orNull)
}
// hint:A8BC6F23
fun mergeValue(valueToMerge: ExampleJson?): Example {
return if (valueToMerge == null) {
this
} else {
val oldValue = _value.orNull
if (oldValue == null) {
setValueField(Field(valueToMerge))
} else {
// hint:E91B4F65
setValue(oldValue.mergeEntity(valueToMerge))
}
}
}
// hint:87B3E19C
fun setValue(value: ExampleJson?): Example {
return setValueField(Field(value))
}
// hint:D465F782
fun unsetValue(): Example {
return setValueField(Field.unset())
}
// hint:47C9A0F6
fun addValue(value: ExampleJson): Example {
if (this.value != null) {
throw IllegalStateException("Field value of Entity Example is already set to '${this.value}', refused to add new value '$value'")
}
return setValue(value)
}
///////////////////////
//
// externalValue
//
///////////////////////
// hint:3A7F9B2E
val externalValue: String?
get() = _externalValue.orNull
// hint:F0C48D71
fun setExternalValueField(externalValue: Field<String?>): Example {
return copy(_externalValue = externalValue)
.updateFields()
}
// hint:8E56A4D9
fun updateExternalValueField(updater: (Field<String?>) -> Field<String?>): Example {
return setExternalValueField(updater(_externalValue))
}
// hint:B1D730FC
fun updateExternalValue(updater: (String?) -> String?): Example {
return updateExternalValueField { field ->
field.flatMap { value ->
Field(updater(value))
}
}
}
// hint:6542E98A
fun mergeExternalValueField(externalValueFieldToMerge: Field<String?>): Example {
return mergeExternalValue(externalValueFieldToMerge.orNull)
}
// hint:A8BC6F23
fun mergeExternalValue(externalValueToMerge: String?): Example {
return if (externalValueToMerge == null) {
this
} else {
val oldExternalValue = _externalValue.orNull
if (oldExternalValue == null) {
setExternalValueField(Field(externalValueToMerge))
} else {
// hint:2F684DAC
setExternalValue(externalValueToMerge)
}
}
}
// hint:87B3E19C
fun setExternalValue(externalValue: String?): Example {
return setExternalValueField(Field(externalValue))
}
// hint:D465F782
fun unsetExternalValue(): Example {
return setExternalValueField(Field.unset())
}
// hint:47C9A0F6
fun addExternalValue(externalValue: String): Example {
if (this.externalValue != null) {
throw IllegalStateException("Field externalValue of Entity Example is already set to '${this.externalValue}', refused to add new value '$externalValue'")
}
return setExternalValue(externalValue)
}
///////////////////////
//
// extensions
//
///////////////////////
// hint:3A7F9B2E
val extensions: Map<String, Extension?>
get() = _extensions.orNull ?: emptyMap()
// hint:F0C48D71
fun setExtensionsField(extensions: Field<Map<String, Extension?>>): Example {
return copy(_extensions = extensions)
.updateFields()
}
// hint:8E56A4D9
fun updateExtensionsField(updater: (Field<Map<String, Extension?>>) -> Field<Map<String, Extension?>>): Example {
return setExtensionsField(updater(_extensions))
}
// hint:B1D730FC
fun updateExtensions(updater: (Map<String, Extension?>) -> Map<String, Extension?>): Example {
return updateExtensionsField { field ->
field.flatMap { value ->
Field(updater(value))
}
}
}
// hint:6542E98A
fun mergeExtensionsField(extensionsFieldToMerge: Field<Map<String, Extension?>>): Example {
return mergeExtensions(extensionsFieldToMerge.orNull)
}
// hint:A8BC6F23
fun mergeExtensions(extensionsToMerge: Map<String, Extension?>?): Example {
return if (extensionsToMerge == null) {
this
} else {
val oldExtensions = _extensions.orNull
if (oldExtensions == null) {
setExtensionsField(Field(extensionsToMerge))
} else {
// hint:70A3D8B6
setExtensions(de.lancom.openapi.parser.util.mergeMap(oldExtensions, extensionsToMerge))
}
}
}
// hint:87B3E19C
fun setExtensions(extensions: Map<String, Extension?>): Example {
return setExtensionsField(Field(extensions))
}
// hint:D465F782
fun unsetExtensions(): Example {
return setExtensionsField(Field.unset())
}
// hint:5C81D396
fun addExtensions(extensions: Map<String, Extension?>): Example {
return mergeExtensions(extensions)
}
// hint:1A6B37F8
fun addExtensions(vararg extensions: Pair<String, Extension?>): Example {
return addExtensions(extensions.toMap())
}
// hint:9D0E4CA5
fun addExtension(key: String, value: Extension?): Example {
return addExtensions(key to value)
}
// hint:B8F25E73
fun addExtension(pair: Pair<String, Extension?>): Example {
return addExtensions(mapOf(pair))
}
// hint:6A81E3FD
override val entityDescriptor: EntityDescriptor by lazy {
EntityDescriptor(
entity = this,
jsonNode = null,
map = mapOf(
"summary" to _summary,
"description" to _description,
"value" to _value,
"externalValue" to _externalValue,
),
flatMap = listOf(
_extensions,
),
flatten = listOf(
),
order = __field_order.map(Fields::value),
)
}
// hint:49FE6A6F
override fun toString(): String {
return this.toYamlString(ignoreOrder = false)
}
// hint:20011A4E
fun getFields(): Set<Fields> {
val allFields: Set<Fields> = setOfNotNull(
setOfNotNull<Fields>(
if (_summary.isDefined) Fields.summary else null,
if (_description.isDefined) Fields.description else null,
if (_value.isDefined) Fields.value else null,
if (_externalValue.isDefined) Fields.externalValue else null,
),
_extensions.getFields()?.map(::Fields)?.toSet(),
).flatten().toSet()
// keep order
return Fields.cleanupFields(__field_order.filter(allFields::contains).toSet() + allFields)
}
// hint:EFD0D818
fun updateFields(): Example {
return copy(__field_order = getFields())
}
// hint:A0E5F382
override fun mergeEntity(other: Entity?): Example {
return when (other) {
null ->
this
is Example ->
merge(other)
else ->
TODO()
}
}
// hint:D6150566
fun mergeFields(other: Example): Example {
return copy(
__field_order = Fields.cleanupFields(this.__field_order + other.__field_order),
).updateFields()
}
// hint:716BFD54
fun merge(other: Example?): Example {
if (other == null) return this
return this
.mergeSummaryField(other._summary)
.mergeDescriptionField(other._description)
.mergeValueField(other._value)
.mergeExternalValueField(other._externalValue)
.mergeExtensionsField(other._extensions)
.mergeFields(other)
}
// hint:21B416A6
override fun getReferencePath(): String? {
return if (__referenceName == null) {
null
} else {
"#/components/examples/$__referenceName"
}
}
fun setReferenceName(name: String): Example {
return copy(__referenceName = name)
}
companion object : ReferenceParser<Example> {
data class Fields(val value: String) {
val set: Set<Fields> = setOf(this)
companion object {
val summary = Fields("summary")
val description = Fields("description")
val value = Fields("value")
val externalValue = Fields("externalValue")
val all: Set<Fields> = setOf(
summary,
description,
value,
externalValue,
)
val skip: Set<Fields> = setOf(
)
fun cleanupFields(fields: Iterable<Fields>): Set<Fields> {
return fields.filterNot(skip::contains).toSet() + all
}
fun fromWrapper(wrapper: Wrapper): Set<Fields> {
return cleanupFields(wrapper.fieldOrder.map(::Fields))
}
}
}
class Serializer : EntitySerializer<Example>(Example::class.java, Example)
class Deserializer : EntityDeserializer<Example>(Example::class.java, Example)
// hint:5F72B6D8
override fun parseWrapper(wrapper: Wrapper): Example {
return de.lancom.openapi.parser.jackson.extensionParser(wrapper, ::parseWrapperWithExtensions)
}
// hint:2C0E94A7
fun parseWrapperWithExtensions(
wrapper: Wrapper,
extensions: Field<Map<String, Extension?>>,
fieldOrder: Set<String>,
): Example {
return Example(
_summary = wrapper["summary"].getNullOrElse {
getSingle {
getSingle {
getString()
}
}
},
_description = wrapper["description"].getNullOrElse {
getSingle {
getSingle {
getString()
}
}
},
_value = wrapper["value"].getNullOrElse {
getSingle {
getSingle {
getSingle(ExampleJson::parseEntityOpt)
}
}
},
_externalValue = wrapper["externalValue"].getNullOrElse {
getSingle {
getSingle {
getString()
}
}
},
_extensions = extensions,
__field_order = fieldOrder.map(::Fields).toSet() + Fields.all,
)
}
}
}