-
Notifications
You must be signed in to change notification settings - Fork 38
/
operation_processing_result.go
87 lines (72 loc) · 2.49 KB
/
operation_processing_result.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
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"bytes"
"io"
"io/ioutil"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
"github.com/go-openapi/validate"
)
// OperationProcessingResult operation processing result
// swagger:discriminator OperationProcessingResult discriminator
type OperationProcessingResult interface {
runtime.Validatable
// discriminator
// Required: true
Discriminator() string
SetDiscriminator(string)
// errors
Errors() []*ErrorRecordV2
SetErrors([]*ErrorRecordV2)
}
// UnmarshalOperationProcessingResultSlice unmarshals polymorphic slices of OperationProcessingResult
func UnmarshalOperationProcessingResultSlice(reader io.Reader, consumer runtime.Consumer) ([]OperationProcessingResult, error) {
var elements [][]byte
if err := consumer.Consume(reader, &elements); err != nil {
return nil, err
}
var result []OperationProcessingResult
for _, element := range elements {
obj, err := unmarshalOperationProcessingResult(element, consumer)
if err != nil {
return nil, err
}
result = append(result, obj)
}
return result, nil
}
// UnmarshalOperationProcessingResult unmarshals polymorphic OperationProcessingResult
func UnmarshalOperationProcessingResult(reader io.Reader, consumer runtime.Consumer) (OperationProcessingResult, error) {
// we need to read this twice, so first into a buffer
data, err := ioutil.ReadAll(reader)
if err != nil {
return nil, err
}
return unmarshalOperationProcessingResult(data, consumer)
}
func unmarshalOperationProcessingResult(data []byte, consumer runtime.Consumer) (OperationProcessingResult, error) {
buf := bytes.NewBuffer(data)
buf2 := bytes.NewBuffer(data)
// the first time this is read is to fetch the value of the discriminator property.
var getType struct {
Discriminator string `json:"discriminator"`
}
if err := consumer.Consume(buf, &getType); err != nil {
return nil, err
}
if err := validate.RequiredString("discriminator", "body", getType.Discriminator); err != nil {
return nil, err
}
// The value of discriminator is used to determine which type to create and unmarshal the data into
switch getType.Discriminator {
case "TopicDetectionResultV2":
var result TopicDetectionResultV2
if err := consumer.Consume(buf2, &result); err != nil {
return nil, err
}
return &result, nil
}
return nil, errors.New(422, "invalid discriminator value: %q", getType.Discriminator)
}