Guest User

Untitled

a guest
Apr 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. /updateuser/{userId}:
  2. x-swagger-router-controller: User
  3. put:
  4. tags:
  5. - User
  6. summary: Update User
  7. description: Update User
  8. operationId: updateUser
  9. parameters:
  10. - name: userId
  11. in: query
  12. description: userId for which subscription needs to be updated
  13. type: string
  14. required: true
  15. - name: subData
  16. in: body
  17. description: Subscription To be updated
  18. schema:
  19. type: array
  20. items:
  21. $ref: "#/definitions/userDataInput"
  22. responses:
  23. "200":
  24. description: Success
  25. schema:
  26. $ref: "#/definitions/Response"
  27. "500":
  28. description: Error
  29. schema:
  30. $ref: "#/definitions/ErrorResponse"
  31.  
  32.  
  33. definitions:
  34. userDataInput:
  35. required:
  36. - productId
  37. - subscriptionId
  38. properties:
  39. productId:
  40. type: string
  41. subscriptionId:
  42. type: string
  43.  
  44. var yaml = require('js-yaml')
  45. var fs = require('fs')
  46. var swaggerObject
  47. try {
  48. swaggerObject = yaml.safeLoad(fs.readFileSync('swagger.yaml'), 'utf8')
  49. } catch (err) {
  50. // Error here
  51. }
  52.  
  53. var Validator = require('swagger-model-validator')
  54. var validator = new Validator(swaggerObject)
  55. var validation = validator.swagger.validateModel('subData', body,
  56. false, true)
  57. if (validation.valid) {
  58. // logic here
  59. } else {
  60. // show error
  61. }
Add Comment
Please, Sign In to add comment