/samples/client/petstore/typescript-angular/API/Client/PetApi.ts

https://gitlab.com/akkhil2012/swagger-codegen · TypeScript · 382 lines · 241 code · 73 blank · 68 comment · 36 complexity · 4f2b04a6b52a2849ab72efe452c8b7dd MD5 · raw file

  1. /// <reference path="api.d.ts" />
  2. /* tslint:disable:no-unused-variable member-ordering */
  3. namespace API.Client {
  4. 'use strict';
  5. export class PetApi {
  6. protected basePath = 'http://petstore.swagger.io/v2';
  7. public defaultHeaders : any = {};
  8. static $inject: string[] = ['$http', '$httpParamSerializer'];
  9. constructor(protected $http: ng.IHttpService, protected $httpParamSerializer?: (d: any) => any, basePath?: string) {
  10. if (basePath) {
  11. this.basePath = basePath;
  12. }
  13. }
  14. private extendObj<T1,T2>(objA: T1, objB: T2) {
  15. for(let key in objB){
  16. if(objB.hasOwnProperty(key)){
  17. objA[key] = objB[key];
  18. }
  19. }
  20. return <T1&T2>objA;
  21. }
  22. /**
  23. * Add a new pet to the store
  24. *
  25. * @param body Pet object that needs to be added to the store
  26. */
  27. public addPet (body?: Pet, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
  28. const localVarPath = this.basePath + '/pet';
  29. let queryParameters: any = {};
  30. let headerParams: any = this.extendObj({}, this.defaultHeaders);
  31. let httpRequestParams: any = {
  32. method: 'POST',
  33. url: localVarPath,
  34. json: true,
  35. data: body,
  36. params: queryParameters,
  37. headers: headerParams
  38. };
  39. if (extraHttpRequestParams) {
  40. httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
  41. }
  42. return this.$http(httpRequestParams);
  43. }
  44. /**
  45. * Fake endpoint to test byte array in body parameter for adding a new pet to the store
  46. *
  47. * @param body Pet object in the form of byte array
  48. */
  49. public addPetUsingByteArray (body?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
  50. const localVarPath = this.basePath + '/pet?testing_byte_array=true';
  51. let queryParameters: any = {};
  52. let headerParams: any = this.extendObj({}, this.defaultHeaders);
  53. let httpRequestParams: any = {
  54. method: 'POST',
  55. url: localVarPath,
  56. json: true,
  57. data: body,
  58. params: queryParameters,
  59. headers: headerParams
  60. };
  61. if (extraHttpRequestParams) {
  62. httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
  63. }
  64. return this.$http(httpRequestParams);
  65. }
  66. /**
  67. * Deletes a pet
  68. *
  69. * @param petId Pet id to delete
  70. * @param apiKey
  71. */
  72. public deletePet (petId: number, apiKey?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
  73. const localVarPath = this.basePath + '/pet/{petId}'
  74. .replace('{' + 'petId' + '}', String(petId));
  75. let queryParameters: any = {};
  76. let headerParams: any = this.extendObj({}, this.defaultHeaders);
  77. // verify required parameter 'petId' is set
  78. if (!petId) {
  79. throw new Error('Missing required parameter petId when calling deletePet');
  80. }
  81. headerParams['api_key'] = apiKey;
  82. let httpRequestParams: any = {
  83. method: 'DELETE',
  84. url: localVarPath,
  85. json: true,
  86. params: queryParameters,
  87. headers: headerParams
  88. };
  89. if (extraHttpRequestParams) {
  90. httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
  91. }
  92. return this.$http(httpRequestParams);
  93. }
  94. /**
  95. * Finds Pets by status
  96. * Multiple status values can be provided with comma separated strings
  97. * @param status Status values that need to be considered for query
  98. */
  99. public findPetsByStatus (status?: Array<string>, extraHttpRequestParams?: any ) : ng.IHttpPromise<Array<Pet>> {
  100. const localVarPath = this.basePath + '/pet/findByStatus';
  101. let queryParameters: any = {};
  102. let headerParams: any = this.extendObj({}, this.defaultHeaders);
  103. if (status !== undefined) {
  104. queryParameters['status'] = status;
  105. }
  106. let httpRequestParams: any = {
  107. method: 'GET',
  108. url: localVarPath,
  109. json: true,
  110. params: queryParameters,
  111. headers: headerParams
  112. };
  113. if (extraHttpRequestParams) {
  114. httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
  115. }
  116. return this.$http(httpRequestParams);
  117. }
  118. /**
  119. * Finds Pets by tags
  120. * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
  121. * @param tags Tags to filter by
  122. */
  123. public findPetsByTags (tags?: Array<string>, extraHttpRequestParams?: any ) : ng.IHttpPromise<Array<Pet>> {
  124. const localVarPath = this.basePath + '/pet/findByTags';
  125. let queryParameters: any = {};
  126. let headerParams: any = this.extendObj({}, this.defaultHeaders);
  127. if (tags !== undefined) {
  128. queryParameters['tags'] = tags;
  129. }
  130. let httpRequestParams: any = {
  131. method: 'GET',
  132. url: localVarPath,
  133. json: true,
  134. params: queryParameters,
  135. headers: headerParams
  136. };
  137. if (extraHttpRequestParams) {
  138. httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
  139. }
  140. return this.$http(httpRequestParams);
  141. }
  142. /**
  143. * Find pet by ID
  144. * Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions
  145. * @param petId ID of pet that needs to be fetched
  146. */
  147. public getPetById (petId: number, extraHttpRequestParams?: any ) : ng.IHttpPromise<Pet> {
  148. const localVarPath = this.basePath + '/pet/{petId}'
  149. .replace('{' + 'petId' + '}', String(petId));
  150. let queryParameters: any = {};
  151. let headerParams: any = this.extendObj({}, this.defaultHeaders);
  152. // verify required parameter 'petId' is set
  153. if (!petId) {
  154. throw new Error('Missing required parameter petId when calling getPetById');
  155. }
  156. let httpRequestParams: any = {
  157. method: 'GET',
  158. url: localVarPath,
  159. json: true,
  160. params: queryParameters,
  161. headers: headerParams
  162. };
  163. if (extraHttpRequestParams) {
  164. httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
  165. }
  166. return this.$http(httpRequestParams);
  167. }
  168. /**
  169. * Fake endpoint to test inline arbitrary object return by &#39;Find pet by ID&#39;
  170. * Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions
  171. * @param petId ID of pet that needs to be fetched
  172. */
  173. public getPetByIdInObject (petId: number, extraHttpRequestParams?: any ) : ng.IHttpPromise<InlineResponse200> {
  174. const localVarPath = this.basePath + '/pet/{petId}?response=inline_arbitrary_object'
  175. .replace('{' + 'petId' + '}', String(petId));
  176. let queryParameters: any = {};
  177. let headerParams: any = this.extendObj({}, this.defaultHeaders);
  178. // verify required parameter 'petId' is set
  179. if (!petId) {
  180. throw new Error('Missing required parameter petId when calling getPetByIdInObject');
  181. }
  182. let httpRequestParams: any = {
  183. method: 'GET',
  184. url: localVarPath,
  185. json: true,
  186. params: queryParameters,
  187. headers: headerParams
  188. };
  189. if (extraHttpRequestParams) {
  190. httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
  191. }
  192. return this.$http(httpRequestParams);
  193. }
  194. /**
  195. * Fake endpoint to test byte array return by &#39;Find pet by ID&#39;
  196. * Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions
  197. * @param petId ID of pet that needs to be fetched
  198. */
  199. public petPetIdtestingByteArraytrueGet (petId: number, extraHttpRequestParams?: any ) : ng.IHttpPromise<string> {
  200. const localVarPath = this.basePath + '/pet/{petId}?testing_byte_array=true'
  201. .replace('{' + 'petId' + '}', String(petId));
  202. let queryParameters: any = {};
  203. let headerParams: any = this.extendObj({}, this.defaultHeaders);
  204. // verify required parameter 'petId' is set
  205. if (!petId) {
  206. throw new Error('Missing required parameter petId when calling petPetIdtestingByteArraytrueGet');
  207. }
  208. let httpRequestParams: any = {
  209. method: 'GET',
  210. url: localVarPath,
  211. json: true,
  212. params: queryParameters,
  213. headers: headerParams
  214. };
  215. if (extraHttpRequestParams) {
  216. httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
  217. }
  218. return this.$http(httpRequestParams);
  219. }
  220. /**
  221. * Update an existing pet
  222. *
  223. * @param body Pet object that needs to be added to the store
  224. */
  225. public updatePet (body?: Pet, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
  226. const localVarPath = this.basePath + '/pet';
  227. let queryParameters: any = {};
  228. let headerParams: any = this.extendObj({}, this.defaultHeaders);
  229. let httpRequestParams: any = {
  230. method: 'PUT',
  231. url: localVarPath,
  232. json: true,
  233. data: body,
  234. params: queryParameters,
  235. headers: headerParams
  236. };
  237. if (extraHttpRequestParams) {
  238. httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
  239. }
  240. return this.$http(httpRequestParams);
  241. }
  242. /**
  243. * Updates a pet in the store with form data
  244. *
  245. * @param petId ID of pet that needs to be updated
  246. * @param name Updated name of the pet
  247. * @param status Updated status of the pet
  248. */
  249. public updatePetWithForm (petId: string, name?: string, status?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
  250. const localVarPath = this.basePath + '/pet/{petId}'
  251. .replace('{' + 'petId' + '}', String(petId));
  252. let queryParameters: any = {};
  253. let headerParams: any = this.extendObj({}, this.defaultHeaders);
  254. let formParams: any = {};
  255. // verify required parameter 'petId' is set
  256. if (!petId) {
  257. throw new Error('Missing required parameter petId when calling updatePetWithForm');
  258. }
  259. headerParams['Content-Type'] = 'application/x-www-form-urlencoded';
  260. formParams['name'] = name;
  261. formParams['status'] = status;
  262. let httpRequestParams: any = {
  263. method: 'POST',
  264. url: localVarPath,
  265. json: false,
  266. data: this.$httpParamSerializer(formParams),
  267. params: queryParameters,
  268. headers: headerParams
  269. };
  270. if (extraHttpRequestParams) {
  271. httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
  272. }
  273. return this.$http(httpRequestParams);
  274. }
  275. /**
  276. * uploads an image
  277. *
  278. * @param petId ID of pet to update
  279. * @param additionalMetadata Additional data to pass to server
  280. * @param file file to upload
  281. */
  282. public uploadFile (petId: number, additionalMetadata?: string, file?: any, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
  283. const localVarPath = this.basePath + '/pet/{petId}/uploadImage'
  284. .replace('{' + 'petId' + '}', String(petId));
  285. let queryParameters: any = {};
  286. let headerParams: any = this.extendObj({}, this.defaultHeaders);
  287. let formParams: any = {};
  288. // verify required parameter 'petId' is set
  289. if (!petId) {
  290. throw new Error('Missing required parameter petId when calling uploadFile');
  291. }
  292. headerParams['Content-Type'] = 'application/x-www-form-urlencoded';
  293. formParams['additionalMetadata'] = additionalMetadata;
  294. formParams['file'] = file;
  295. let httpRequestParams: any = {
  296. method: 'POST',
  297. url: localVarPath,
  298. json: false,
  299. data: this.$httpParamSerializer(formParams),
  300. params: queryParameters,
  301. headers: headerParams
  302. };
  303. if (extraHttpRequestParams) {
  304. httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
  305. }
  306. return this.$http(httpRequestParams);
  307. }
  308. }
  309. }