/
principal_role.go
170 lines (138 loc) · 4.45 KB
/
principal_role.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
// Code generated by go-swagger; DO NOT EDIT.
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"
"context"
"encoding/json"
"io"
"io/ioutil"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/validate"
)
// PrincipalRole PrincipalRole
//
// A representation of a user or group.
//
// swagger:discriminator PrincipalRole A representation of a user or group.
type PrincipalRole interface {
runtime.Validatable
runtime.ContextValidatable
// The email of the user or name of the group.
// Example: administrator@vmware.com
// Required: true
Email() *string
SetEmail(*string)
// Role of this member. Currently supported 'member', 'viewer' and 'administrator'.
// Example: member
Role() string
SetRole(string)
// Type of the principal. Currently supported 'user' (default) and 'group'.
// Example: user
Type() string
SetType(string)
// AdditionalProperties in base type shoud be handled just like regular properties
// At this moment, the base type property is pushed down to the subtype
}
type principalRole struct {
emailField *string
roleField string
typeField string
}
// Email gets the email of this polymorphic type
func (m *principalRole) Email() *string {
return m.emailField
}
// SetEmail sets the email of this polymorphic type
func (m *principalRole) SetEmail(val *string) {
m.emailField = val
}
// Role gets the role of this polymorphic type
func (m *principalRole) Role() string {
return m.roleField
}
// SetRole sets the role of this polymorphic type
func (m *principalRole) SetRole(val string) {
m.roleField = val
}
// Type gets the type of this polymorphic type
func (m *principalRole) Type() string {
return m.typeField
}
// SetType sets the type of this polymorphic type
func (m *principalRole) SetType(val string) {
m.typeField = val
}
// UnmarshalPrincipalRoleSlice unmarshals polymorphic slices of PrincipalRole
func UnmarshalPrincipalRoleSlice(reader io.Reader, consumer runtime.Consumer) ([]PrincipalRole, error) {
var elements []json.RawMessage
if err := consumer.Consume(reader, &elements); err != nil {
return nil, err
}
var result []PrincipalRole
for _, element := range elements {
obj, err := unmarshalPrincipalRole(element, consumer)
if err != nil {
return nil, err
}
result = append(result, obj)
}
return result, nil
}
// UnmarshalPrincipalRole unmarshals polymorphic PrincipalRole
func UnmarshalPrincipalRole(reader io.Reader, consumer runtime.Consumer) (PrincipalRole, error) {
// we need to read this twice, so first into a buffer
data, err := ioutil.ReadAll(reader)
if err != nil {
return nil, err
}
return unmarshalPrincipalRole(data, consumer)
}
func unmarshalPrincipalRole(data []byte, consumer runtime.Consumer) (PrincipalRole, error) {
buf := bytes.NewBuffer(data)
buf2 := bytes.NewBuffer(data)
// the first time this is read is to fetch the value of the A representation of a user or group. property.
var getType struct {
ARepresentationOfaUserOrGroup string `json:"A representation of a user or group."`
}
if err := consumer.Consume(buf, &getType); err != nil {
return nil, err
}
if err := validate.RequiredString("A representation of a user or group.", "body", getType.ARepresentationOfaUserOrGroup); err != nil {
return nil, err
}
// The value of A representation of a user or group. is used to determine which type to create and unmarshal the data into
switch getType.ARepresentationOfaUserOrGroup {
case "PrincipalRole":
var result principalRole
if err := consumer.Consume(buf2, &result); err != nil {
return nil, err
}
return &result, nil
}
return nil, errors.New(422, "invalid A representation of a user or group. value: %q", getType.ARepresentationOfaUserOrGroup)
}
// Validate validates this principal role
func (m *principalRole) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateEmail(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *principalRole) validateEmail(formats strfmt.Registry) error {
if err := validate.Required("email", "body", m.Email()); err != nil {
return err
}
return nil
}
// ContextValidate validates this principal role based on context it is used
func (m *principalRole) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
return nil
}