/samples/server/petstore/aspnet5/src/IO.Swagger/Controllers/PetApi.cs

https://gitlab.com/akkhil2012/swagger-codegen · C# · 212 lines · 108 code · 28 blank · 76 comment · 4 complexity · de76614f09876468dfa347d29ffd144e MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.ComponentModel;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Net;
  8. using System.Threading.Tasks;
  9. using Microsoft.AspNet.Mvc;
  10. using Newtonsoft.Json;
  11. using Swashbuckle.SwaggerGen.Annotations;
  12. using IO.Swagger.Models;
  13. namespace IO.Swagger.Controllers
  14. {
  15. /// <summary>
  16. ///
  17. /// </summary>
  18. public class PetApiController : Controller
  19. {
  20. /// <summary>
  21. /// Update an existing pet
  22. /// </summary>
  23. /// <remarks></remarks>
  24. /// <param name="body">Pet object that needs to be added to the store</param>
  25. /// <response code="400">Invalid ID supplied</response>
  26. /// <response code="404">Pet not found</response>
  27. /// <response code="405">Validation exception</response>
  28. [HttpPut]
  29. [Route("/pet")]
  30. [SwaggerOperation("UpdatePet")]
  31. public void UpdatePet([FromBody]Pet body)
  32. {
  33. throw new NotImplementedException();
  34. }
  35. /// <summary>
  36. /// Add a new pet to the store
  37. /// </summary>
  38. /// <remarks></remarks>
  39. /// <param name="body">Pet object that needs to be added to the store</param>
  40. /// <response code="405">Invalid input</response>
  41. [HttpPost]
  42. [Route("/pet")]
  43. [SwaggerOperation("AddPet")]
  44. public void AddPet([FromBody]Pet body)
  45. {
  46. throw new NotImplementedException();
  47. }
  48. /// <summary>
  49. /// Finds Pets by status
  50. /// </summary>
  51. /// <remarks>Multiple status values can be provided with comma seperated strings</remarks>
  52. /// <param name="status">Status values that need to be considered for filter</param>
  53. /// <response code="200">successful operation</response>
  54. /// <response code="400">Invalid status value</response>
  55. [HttpGet]
  56. [Route("/pet/findByStatus")]
  57. [SwaggerOperation("FindPetsByStatus")]
  58. [SwaggerResponse(200, type: typeof(List<Pet>))]
  59. public IActionResult FindPetsByStatus([FromQuery]List<string> status)
  60. {
  61. string exampleJson = null;
  62. var example = exampleJson != null
  63. ? JsonConvert.DeserializeObject<List<Pet>>(exampleJson)
  64. : default(List<Pet>);
  65. return new ObjectResult(example);
  66. }
  67. /// <summary>
  68. /// Finds Pets by tags
  69. /// </summary>
  70. /// <remarks>Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.</remarks>
  71. /// <param name="tags">Tags to filter by</param>
  72. /// <response code="200">successful operation</response>
  73. /// <response code="400">Invalid tag value</response>
  74. [HttpGet]
  75. [Route("/pet/findByTags")]
  76. [SwaggerOperation("FindPetsByTags")]
  77. [SwaggerResponse(200, type: typeof(List<Pet>))]
  78. public IActionResult FindPetsByTags([FromQuery]List<string> tags)
  79. {
  80. string exampleJson = null;
  81. var example = exampleJson != null
  82. ? JsonConvert.DeserializeObject<List<Pet>>(exampleJson)
  83. : default(List<Pet>);
  84. return new ObjectResult(example);
  85. }
  86. /// <summary>
  87. /// Find pet by ID
  88. /// </summary>
  89. /// <remarks>Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions</remarks>
  90. /// <param name="petId">ID of pet that needs to be fetched</param>
  91. /// <response code="200">successful operation</response>
  92. /// <response code="400">Invalid ID supplied</response>
  93. /// <response code="404">Pet not found</response>
  94. [HttpGet]
  95. [Route("/pet/{petId}")]
  96. [SwaggerOperation("GetPetById")]
  97. [SwaggerResponse(200, type: typeof(Pet))]
  98. public IActionResult GetPetById([FromRoute]long? petId)
  99. {
  100. string exampleJson = null;
  101. var example = exampleJson != null
  102. ? JsonConvert.DeserializeObject<Pet>(exampleJson)
  103. : default(Pet);
  104. return new ObjectResult(example);
  105. }
  106. /// <summary>
  107. /// Updates a pet in the store with form data
  108. /// </summary>
  109. /// <remarks></remarks>
  110. /// <param name="petId">ID of pet that needs to be updated</param>
  111. /// <param name="name">Updated name of the pet</param>
  112. /// <param name="status">Updated status of the pet</param>
  113. /// <response code="405">Invalid input</response>
  114. [HttpPost]
  115. [Route("/pet/{petId}")]
  116. [SwaggerOperation("UpdatePetWithForm")]
  117. public void UpdatePetWithForm([FromRoute]string petId, [FromForm]string name, [FromForm]string status)
  118. {
  119. throw new NotImplementedException();
  120. }
  121. /// <summary>
  122. /// Deletes a pet
  123. /// </summary>
  124. /// <remarks></remarks>
  125. /// <param name="petId">Pet id to delete</param>
  126. /// <param name="apiKey"></param>
  127. /// <response code="400">Invalid pet value</response>
  128. [HttpDelete]
  129. [Route("/pet/{petId}")]
  130. [SwaggerOperation("DeletePet")]
  131. public void DeletePet([FromRoute]long? petId, [FromHeader]string apiKey)
  132. {
  133. throw new NotImplementedException();
  134. }
  135. /// <summary>
  136. /// uploads an image
  137. /// </summary>
  138. /// <remarks></remarks>
  139. /// <param name="petId">ID of pet to update</param>
  140. /// <param name="additionalMetadata">Additional data to pass to server</param>
  141. /// <param name="file">file to upload</param>
  142. /// <response code="0">successful operation</response>
  143. [HttpPost]
  144. [Route("/pet/{petId}/uploadImage")]
  145. [SwaggerOperation("UploadFile")]
  146. public void UploadFile([FromRoute]long? petId, [FromForm]string additionalMetadata, [FromForm]Stream file)
  147. {
  148. throw new NotImplementedException();
  149. }
  150. /// <summary>
  151. /// Fake endpoint to test byte array return by &#39;Find pet by ID&#39;
  152. /// </summary>
  153. /// <remarks>Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions</remarks>
  154. /// <param name="petId">ID of pet that needs to be fetched</param>
  155. /// <response code="200">successful operation</response>
  156. /// <response code="400">Invalid ID supplied</response>
  157. /// <response code="404">Pet not found</response>
  158. [HttpGet]
  159. [Route("/pet/{petId}/testing_byte_array=true")]
  160. [SwaggerOperation("GetPetByIdWithByteArray")]
  161. [SwaggerResponse(200, type: typeof(byte[]))]
  162. public IActionResult GetPetByIdWithByteArray([FromRoute]long? petId)
  163. {
  164. string exampleJson = null;
  165. var example = exampleJson != null
  166. ? JsonConvert.DeserializeObject<byte[]>(exampleJson)
  167. : default(byte[]);
  168. return new ObjectResult(example);
  169. }
  170. /// <summary>
  171. /// Fake endpoint to test byte array in body parameter for adding a new pet to the store
  172. /// </summary>
  173. /// <remarks></remarks>
  174. /// <param name="body">Pet object in the form of byte array</param>
  175. /// <response code="405">Invalid input</response>
  176. [HttpPost]
  177. [Route("/pet/testing_byte_array=true")]
  178. [SwaggerOperation("AddPetUsingByteArray")]
  179. public void AddPetUsingByteArray([FromBody]byte[] body)
  180. {
  181. throw new NotImplementedException();
  182. }
  183. }
  184. }