github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/pkg/platform/api/mono/mono_models/device_code_complete.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 package mono_models 4 5 // This file was generated by the swagger tool. 6 // Editing this file might prove futile when you re-run the swagger generate command 7 8 import ( 9 "context" 10 "encoding/json" 11 12 "github.com/go-openapi/errors" 13 "github.com/go-openapi/strfmt" 14 "github.com/go-openapi/swag" 15 "github.com/go-openapi/validate" 16 ) 17 18 // DeviceCodeComplete device code complete 19 // 20 // swagger:model DeviceCodeComplete 21 type DeviceCodeComplete struct { 22 23 // API JWT access token 24 // Required: true 25 AccessToken *JWT `json:"access_token"` 26 27 // The lifetime in seconds of the access token. 28 ExpiresIn int64 `json:"expires_in,omitempty"` 29 30 // API key stored and use to get new JET access_tokens when they expire 31 RefreshToken *NewToken `json:"refresh_token,omitempty"` 32 33 // The type of the access_token as defined by https://datatracker.ietf.org/doc/html/rfc6749#section-7.1 34 // Required: true 35 // Enum: [bearer] 36 TokenType *string `json:"token_type"` 37 } 38 39 // Validate validates this device code complete 40 func (m *DeviceCodeComplete) Validate(formats strfmt.Registry) error { 41 var res []error 42 43 if err := m.validateAccessToken(formats); err != nil { 44 res = append(res, err) 45 } 46 47 if err := m.validateRefreshToken(formats); err != nil { 48 res = append(res, err) 49 } 50 51 if err := m.validateTokenType(formats); err != nil { 52 res = append(res, err) 53 } 54 55 if len(res) > 0 { 56 return errors.CompositeValidationError(res...) 57 } 58 return nil 59 } 60 61 func (m *DeviceCodeComplete) validateAccessToken(formats strfmt.Registry) error { 62 63 if err := validate.Required("access_token", "body", m.AccessToken); err != nil { 64 return err 65 } 66 67 if m.AccessToken != nil { 68 if err := m.AccessToken.Validate(formats); err != nil { 69 if ve, ok := err.(*errors.Validation); ok { 70 return ve.ValidateName("access_token") 71 } 72 return err 73 } 74 } 75 76 return nil 77 } 78 79 func (m *DeviceCodeComplete) validateRefreshToken(formats strfmt.Registry) error { 80 if swag.IsZero(m.RefreshToken) { // not required 81 return nil 82 } 83 84 if m.RefreshToken != nil { 85 if err := m.RefreshToken.Validate(formats); err != nil { 86 if ve, ok := err.(*errors.Validation); ok { 87 return ve.ValidateName("refresh_token") 88 } 89 return err 90 } 91 } 92 93 return nil 94 } 95 96 var deviceCodeCompleteTypeTokenTypePropEnum []interface{} 97 98 func init() { 99 var res []string 100 if err := json.Unmarshal([]byte(`["bearer"]`), &res); err != nil { 101 panic(err) 102 } 103 for _, v := range res { 104 deviceCodeCompleteTypeTokenTypePropEnum = append(deviceCodeCompleteTypeTokenTypePropEnum, v) 105 } 106 } 107 108 const ( 109 110 // DeviceCodeCompleteTokenTypeBearer captures enum value "bearer" 111 DeviceCodeCompleteTokenTypeBearer string = "bearer" 112 ) 113 114 // prop value enum 115 func (m *DeviceCodeComplete) validateTokenTypeEnum(path, location string, value string) error { 116 if err := validate.EnumCase(path, location, value, deviceCodeCompleteTypeTokenTypePropEnum, true); err != nil { 117 return err 118 } 119 return nil 120 } 121 122 func (m *DeviceCodeComplete) validateTokenType(formats strfmt.Registry) error { 123 124 if err := validate.Required("token_type", "body", m.TokenType); err != nil { 125 return err 126 } 127 128 // value enum 129 if err := m.validateTokenTypeEnum("token_type", "body", *m.TokenType); err != nil { 130 return err 131 } 132 133 return nil 134 } 135 136 // ContextValidate validate this device code complete based on the context it is used 137 func (m *DeviceCodeComplete) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 138 var res []error 139 140 if err := m.contextValidateAccessToken(ctx, formats); err != nil { 141 res = append(res, err) 142 } 143 144 if err := m.contextValidateRefreshToken(ctx, formats); err != nil { 145 res = append(res, err) 146 } 147 148 if len(res) > 0 { 149 return errors.CompositeValidationError(res...) 150 } 151 return nil 152 } 153 154 func (m *DeviceCodeComplete) contextValidateAccessToken(ctx context.Context, formats strfmt.Registry) error { 155 156 if m.AccessToken != nil { 157 if err := m.AccessToken.ContextValidate(ctx, formats); err != nil { 158 if ve, ok := err.(*errors.Validation); ok { 159 return ve.ValidateName("access_token") 160 } 161 return err 162 } 163 } 164 165 return nil 166 } 167 168 func (m *DeviceCodeComplete) contextValidateRefreshToken(ctx context.Context, formats strfmt.Registry) error { 169 170 if m.RefreshToken != nil { 171 if err := m.RefreshToken.ContextValidate(ctx, formats); err != nil { 172 if ve, ok := err.(*errors.Validation); ok { 173 return ve.ValidateName("refresh_token") 174 } 175 return err 176 } 177 } 178 179 return nil 180 } 181 182 // MarshalBinary interface implementation 183 func (m *DeviceCodeComplete) MarshalBinary() ([]byte, error) { 184 if m == nil { 185 return nil, nil 186 } 187 return swag.WriteJSON(m) 188 } 189 190 // UnmarshalBinary interface implementation 191 func (m *DeviceCodeComplete) UnmarshalBinary(b []byte) error { 192 var res DeviceCodeComplete 193 if err := swag.ReadJSON(b, &res); err != nil { 194 return err 195 } 196 *m = res 197 return nil 198 }