github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/contributed-templates/stratoscale/client/pet/pet_client.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 package pet 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 "fmt" 11 12 "github.com/go-openapi/runtime" 13 14 strfmt "github.com/go-openapi/strfmt" 15 ) 16 17 //go:generate mockery --name API --keeptree --with-expecter --case underscore 18 19 // API is the interface of the pet client 20 type API interface { 21 /* 22 PetCreate adds a new pet to the store*/ 23 PetCreate(ctx context.Context, params *PetCreateParams) (*PetCreateCreated, error) 24 /* 25 PetDelete deletes a pet*/ 26 PetDelete(ctx context.Context, params *PetDeleteParams) (*PetDeleteNoContent, error) 27 /* 28 PetGet gets pet by it s ID*/ 29 PetGet(ctx context.Context, params *PetGetParams) (*PetGetOK, error) 30 /* 31 PetList lists pets*/ 32 PetList(ctx context.Context, params *PetListParams) (*PetListOK, error) 33 /* 34 PetUpdate updates an existing pet*/ 35 PetUpdate(ctx context.Context, params *PetUpdateParams) (*PetUpdateCreated, error) 36 /* 37 PetUploadImage uploads an image*/ 38 PetUploadImage(ctx context.Context, params *PetUploadImageParams) (*PetUploadImageOK, error) 39 } 40 41 // New creates a new pet API client. 42 func New(transport runtime.ClientTransport, formats strfmt.Registry, authInfo runtime.ClientAuthInfoWriter) *Client { 43 return &Client{ 44 transport: transport, 45 formats: formats, 46 authInfo: authInfo, 47 } 48 } 49 50 /* 51 Client for pet API 52 */ 53 type Client struct { 54 transport runtime.ClientTransport 55 formats strfmt.Registry 56 authInfo runtime.ClientAuthInfoWriter 57 } 58 59 /* 60 PetCreate adds a new pet to the store 61 */ 62 func (a *Client) PetCreate(ctx context.Context, params *PetCreateParams) (*PetCreateCreated, error) { 63 64 result, err := a.transport.Submit(&runtime.ClientOperation{ 65 ID: "PetCreate", 66 Method: "POST", 67 PathPattern: "/pet", 68 ProducesMediaTypes: []string{"application/json"}, 69 ConsumesMediaTypes: []string{"application/json"}, 70 Schemes: []string{"http"}, 71 Params: params, 72 Reader: &PetCreateReader{formats: a.formats}, 73 AuthInfo: a.authInfo, 74 Context: ctx, 75 Client: params.HTTPClient, 76 }) 77 if err != nil { 78 return nil, err 79 } 80 switch value := result.(type) { 81 case *PetCreateCreated: 82 return value, nil 83 case *PetCreateMethodNotAllowed: 84 return nil, runtime.NewAPIError("unsuccessful response", value, value.Code()) 85 } 86 // safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue 87 msg := fmt.Sprintf("unexpected success response for PetCreate: API contract not enforced by server. Client expected to get an error, but got: %T", result) 88 panic(msg) 89 } 90 91 /* 92 PetDelete deletes a pet 93 */ 94 func (a *Client) PetDelete(ctx context.Context, params *PetDeleteParams) (*PetDeleteNoContent, error) { 95 96 result, err := a.transport.Submit(&runtime.ClientOperation{ 97 ID: "PetDelete", 98 Method: "DELETE", 99 PathPattern: "/pet/{petId}", 100 ProducesMediaTypes: []string{"application/json"}, 101 ConsumesMediaTypes: []string{"application/json"}, 102 Schemes: []string{"http"}, 103 Params: params, 104 Reader: &PetDeleteReader{formats: a.formats}, 105 AuthInfo: a.authInfo, 106 Context: ctx, 107 Client: params.HTTPClient, 108 }) 109 if err != nil { 110 return nil, err 111 } 112 switch value := result.(type) { 113 case *PetDeleteNoContent: 114 return value, nil 115 case *PetDeleteBadRequest: 116 return nil, runtime.NewAPIError("unsuccessful response", value, value.Code()) 117 case *PetDeleteNotFound: 118 return nil, runtime.NewAPIError("unsuccessful response", value, value.Code()) 119 } 120 // safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue 121 msg := fmt.Sprintf("unexpected success response for PetDelete: API contract not enforced by server. Client expected to get an error, but got: %T", result) 122 panic(msg) 123 } 124 125 /* 126 PetGet gets pet by it s ID 127 */ 128 func (a *Client) PetGet(ctx context.Context, params *PetGetParams) (*PetGetOK, error) { 129 130 result, err := a.transport.Submit(&runtime.ClientOperation{ 131 ID: "PetGet", 132 Method: "GET", 133 PathPattern: "/pet/{petId}", 134 ProducesMediaTypes: []string{"application/json"}, 135 ConsumesMediaTypes: []string{"application/json"}, 136 Schemes: []string{"http"}, 137 Params: params, 138 Reader: &PetGetReader{formats: a.formats}, 139 AuthInfo: a.authInfo, 140 Context: ctx, 141 Client: params.HTTPClient, 142 }) 143 if err != nil { 144 return nil, err 145 } 146 switch value := result.(type) { 147 case *PetGetOK: 148 return value, nil 149 case *PetGetBadRequest: 150 return nil, runtime.NewAPIError("unsuccessful response", value, value.Code()) 151 case *PetGetNotFound: 152 return nil, runtime.NewAPIError("unsuccessful response", value, value.Code()) 153 } 154 // safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue 155 msg := fmt.Sprintf("unexpected success response for PetGet: API contract not enforced by server. Client expected to get an error, but got: %T", result) 156 panic(msg) 157 } 158 159 /* 160 PetList lists pets 161 */ 162 func (a *Client) PetList(ctx context.Context, params *PetListParams) (*PetListOK, error) { 163 164 result, err := a.transport.Submit(&runtime.ClientOperation{ 165 ID: "PetList", 166 Method: "GET", 167 PathPattern: "/pet", 168 ProducesMediaTypes: []string{"application/json"}, 169 ConsumesMediaTypes: []string{"application/json"}, 170 Schemes: []string{"http"}, 171 Params: params, 172 Reader: &PetListReader{formats: a.formats}, 173 AuthInfo: a.authInfo, 174 Context: ctx, 175 Client: params.HTTPClient, 176 }) 177 if err != nil { 178 return nil, err 179 } 180 switch value := result.(type) { 181 case *PetListOK: 182 return value, nil 183 case *PetListBadRequest: 184 return nil, runtime.NewAPIError("unsuccessful response", value, value.Code()) 185 } 186 // safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue 187 msg := fmt.Sprintf("unexpected success response for PetList: API contract not enforced by server. Client expected to get an error, but got: %T", result) 188 panic(msg) 189 } 190 191 /* 192 PetUpdate updates an existing pet 193 */ 194 func (a *Client) PetUpdate(ctx context.Context, params *PetUpdateParams) (*PetUpdateCreated, error) { 195 196 result, err := a.transport.Submit(&runtime.ClientOperation{ 197 ID: "PetUpdate", 198 Method: "PUT", 199 PathPattern: "/pet", 200 ProducesMediaTypes: []string{"application/json"}, 201 ConsumesMediaTypes: []string{"application/json"}, 202 Schemes: []string{"http"}, 203 Params: params, 204 Reader: &PetUpdateReader{formats: a.formats}, 205 AuthInfo: a.authInfo, 206 Context: ctx, 207 Client: params.HTTPClient, 208 }) 209 if err != nil { 210 return nil, err 211 } 212 switch value := result.(type) { 213 case *PetUpdateCreated: 214 return value, nil 215 case *PetUpdateBadRequest: 216 return nil, runtime.NewAPIError("unsuccessful response", value, value.Code()) 217 case *PetUpdateNotFound: 218 return nil, runtime.NewAPIError("unsuccessful response", value, value.Code()) 219 case *PetUpdateMethodNotAllowed: 220 return nil, runtime.NewAPIError("unsuccessful response", value, value.Code()) 221 } 222 // safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue 223 msg := fmt.Sprintf("unexpected success response for PetUpdate: API contract not enforced by server. Client expected to get an error, but got: %T", result) 224 panic(msg) 225 } 226 227 /* 228 PetUploadImage uploads an image 229 */ 230 func (a *Client) PetUploadImage(ctx context.Context, params *PetUploadImageParams) (*PetUploadImageOK, error) { 231 232 result, err := a.transport.Submit(&runtime.ClientOperation{ 233 ID: "PetUploadImage", 234 Method: "POST", 235 PathPattern: "/pet/{petId}/image", 236 ProducesMediaTypes: []string{"application/json"}, 237 ConsumesMediaTypes: []string{"application/json"}, 238 Schemes: []string{"http"}, 239 Params: params, 240 Reader: &PetUploadImageReader{formats: a.formats}, 241 AuthInfo: a.authInfo, 242 Context: ctx, 243 Client: params.HTTPClient, 244 }) 245 if err != nil { 246 return nil, err 247 } 248 switch value := result.(type) { 249 case *PetUploadImageOK: 250 return value, nil 251 } 252 // safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue 253 msg := fmt.Sprintf("unexpected success response for PetUploadImage: API contract not enforced by server. Client expected to get an error, but got: %T", result) 254 panic(msg) 255 }