oa-ref.js 872 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * Create Reference Object.
  3. *
  4. * Example 1:
  5. *
  6. * ```js
  7. * oaRef('User');
  8. * // {"$ref": "#/components/schemas/User"}
  9. * ```
  10. *
  11. * Example 2:
  12. *
  13. * ```js
  14. * oaRef('Error', 'responses');
  15. * // {"$ref": "#/components/responses/Error"}
  16. * ```
  17. *
  18. * Example 3:
  19. *
  20. * ```js
  21. * builder.defineOperation({
  22. * path: '/users',
  23. * method: 'get',
  24. * operation: {
  25. * responses: {
  26. * 200: {
  27. * description: 'List of users',
  28. * content: {
  29. * 'application/json': {
  30. * schema: {
  31. * type: 'array',
  32. * items: oaRef('User'), // <=
  33. * },
  34. * },
  35. * },
  36. * },
  37. * },
  38. * },
  39. * });
  40. * ```
  41. *
  42. * @param {string} name
  43. * @param {string} [type]
  44. * @returns {object}
  45. */
  46. export function oaRef(name, type = 'schemas') {
  47. return {$ref: `#/components/${type}/${name}`};
  48. }