Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.89 KB | None | 0 0
  1. swagger: "2.0"
  2. info:
  3. version: "1.1.0"
  4. title: User Manager
  5. description: >
  6. This is a sample API for managing a database of users. User accounts can be created, deleted, edited, and retrieved.
  7. Users can also log-in, which will create a session cookie. Logging out will delete the cookie.
  8.  
  9. host: localhost:3000
  10. consumes:
  11. - application/json
  12. produces:
  13. - application/json
  14.  
  15. definitions:
  16. # A simple username/password combo for logging in
  17. login:
  18. required: [username, password]
  19. properties:
  20. username:
  21. type: string
  22. minLength: 1
  23. password:
  24. type: string
  25. minLength: 1
  26.  
  27. # The user schema is defined in the "user.yaml" file.
  28. # Swagger-Server will automatically convert the user.yaml
  29. # file to JSON format
  30. user:
  31. # this is not a complete swagger spec. it's just a json schema (in yaml format)
  32. # that's referenced by the "users.yaml" spec using "$ref: http://localhost:3000/users.json"
  33. #
  34. # note that swagger-server will automatically convert the yaml to json when serving
  35. # the file. if you prefer to author the file in json instead of yaml, then that's ok too.
  36.  
  37. description: a registered user
  38. required: [username, password, name]
  39. properties:
  40. username:
  41. type: string
  42. minlength: 4
  43. maxlength: 20
  44. pattern: "^\\w+$" # only allows alphanumeric characters
  45. description: username must be unique
  46. password:
  47. type: string
  48. minlength: 4
  49. description: a super-secure, four-character password :)
  50. name:
  51. type: object
  52. description: the user's real name
  53. required: [firstname]
  54. properties:
  55. firstname:
  56. type: string
  57. minlength: 1
  58. lastname:
  59. type: string
  60. email:
  61. type: string
  62. telephone:
  63. type: integer
  64. minimum: 1000000000
  65. lastlogindate:
  66. type: string
  67. format: date-time
  68. description: when the user last logged in (set by the server)
  69. readonly: true
  70. example:
  71. username: jdoe
  72. name:
  73. firstname: john
  74. lastname: doe
  75. email: john.doe@abc.com
  76. telephone: 5551234567
  77. lastlogindate: 2015-05-11t14-00-32z
  78.  
  79.  
  80. # NOTE: This does NOT set global parameters for all operations.
  81. # It just defines parameter templates that can be referenced by operations (i.e. it saves typing)
  82. parameters:
  83. sessionCookie: &sessionCookie
  84. name: Cookie
  85. in: header
  86. required: true
  87. type: string
  88. description: The session cookie
  89.  
  90. username: &username
  91. name: username
  92. in: path
  93. required: true
  94. type: string
  95. description: This is the {username} path parameter
  96.  
  97. userData: &userData
  98. name: body
  99. in: body
  100. required: true
  101. schema:
  102. $ref: user
  103. description: The user data for create/update operations
  104.  
  105.  
  106. paths:
  107. /users:
  108. get:
  109. summary: Returns all users in the database.
  110. description: Only the "admin" user can access this.
  111. responses:
  112. 200:
  113. description: Returns the list of users
  114. schema:
  115. type: array
  116. items:
  117. $ref: user
  118. 401:
  119. description: Hey! You're not the "admin" user!
  120.  
  121. post:
  122. summary: Creates a new user
  123. description: Only the "admin" user can create users.
  124. parameters:
  125. - name: body
  126. in: body
  127. required: true
  128. schema:
  129. $ref: user
  130. description: The user account to create
  131. responses:
  132. 201:
  133. description: New user was created successfully
  134. schema:
  135. $ref: user
  136. headers:
  137. Location:
  138. type: string
  139. description: The Server returns the URL of the new user
  140. 400:
  141. description: Bad JSON formatting in the request
  142.  
  143.  
  144. /users/{username}:
  145. get:
  146. summary: Retrieves a user
  147. description: >
  148. users can only retrieve their own account, not other users'. Except for the "admin" user, who can retrieve anyone.
  149. parameters:
  150. - *username
  151. - *sessionCookie
  152. responses:
  153. 200:
  154. description: Returns the user's data
  155. schema:
  156. $ref: user
  157. 401:
  158. description: You tried to retrieve someone else's account, and you're not the "admin" user.
  159. 404:
  160. description: The {username} was not found
  161.  
  162. post:
  163. summary: Edits a user
  164. description: >
  165. Users can only edit their own account, not other users'. Except for the "admin" user, who can edit anyone.
  166. parameters:
  167. - *username
  168. - *userData
  169. - *sessionCookie
  170. responses:
  171. 200:
  172. description: User data was saved successfully
  173. schema:
  174. $ref: user
  175. 400:
  176. description: Bad JSON formatting in the request
  177. 401:
  178. description: You tried to edit someone else's account, and you're not the "admin" user.
  179. 404:
  180. description: The {username} was not found
  181.  
  182. delete:
  183. summary: Deletes a user
  184. description: >
  185. Users can only delete their own account, not other users'. Except for the "admin" user, who can delete anyone.
  186. parameters:
  187. - *username
  188. - *sessionCookie
  189. responses:
  190. 204:
  191. description: User account was deleted
  192. 401:
  193. description: You tried to edit someone else's account, and you're not the "admin" user.
  194. 404:
  195. description: The {username} was not found
  196.  
  197.  
  198. /users/login:
  199. post:
  200. summary: Logs in
  201. description: |
  202. Try logging in with username "jdoe" and password "jdoe".
  203. Then try logging in with username "admin" and password "admin".
  204. parameters:
  205. - name: body
  206. in: body
  207. required: true
  208. description: The login credentials
  209. schema:
  210. $ref: login
  211. responses:
  212. 200:
  213. description: Login was successful
  214. schema:
  215. $ref: user
  216. headers:
  217. Set-Cookie:
  218. type: string
  219. description: The session cookie
  220. default: demo-session-id=123456789012345678901234567890
  221.  
  222.  
  223. /users/{username}/logout:
  224. post:
  225. summary: Logs out the given user
  226. description: >
  227. Users can only log themselves out, not other users. Except the "admin" user, who can log-out anyone.
  228. parameters:
  229. - *username
  230. - *sessionCookie
  231. responses:
  232. 204:
  233. description: Logout was successful
  234. headers:
  235. Set-Cookie:
  236. type: string
  237. description: Deletes the session cookie (by making expire in the past)
  238. default: demo-session-id=deleted; Expires=Thu, 01-Jan-1970 00:00:01 GMT; Path=/
  239. 401:
  240. description: You tried to log someone else out, and you're not the "admin" user.
  241. 404:
  242. description: The {username} was not found
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement