api-spec.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @SWG\Info(
  4. * version="1.0.0",
  5. * title="Example of using references in swagger-php",
  6. * )
  7. */
  8. ?>
  9. You can define top-level parameters which can be references with $ref="#/parameters/$parameter"
  10. <?php
  11. /**
  12. * @SWG\Parameter(
  13. * parameter="product_id_in_path_required",
  14. * name="product_id",
  15. * description="The ID of the product",
  16. * type="integer",
  17. * format="int64",
  18. * in="path",
  19. * required=true
  20. * )
  21. *
  22. * @SWG\Parameter(
  23. * parameter="product_in_body",
  24. * in="body",
  25. * name="product",
  26. * @SWG\Schema(ref="#/definitions/Product")
  27. * )
  28. */
  29. ?>
  30. You can define top-level responses which can be references with $ref="#/responses/$response"
  31. I find it usefull to add @SWG\Response(ref="#/responses/todo") to the operations when i'm starting out with writting the swagger documentation.
  32. As it bypasses the "@SWG\Get() requires at least one @SWG\Response()" error and you'll get a nice list of the available api calls in swagger-ui.
  33. Then later, a search for '#/responses/todo' will reveal the operations I haven't documented yet.
  34. <?php
  35. /**
  36. * @SWG\Response(
  37. * response="product",
  38. * description="All information about a product",
  39. * @SWG\Schema(ref="#/definitions/Product")
  40. * )
  41. *
  42. * @SWG\Response(
  43. * response="todo",
  44. * description="This API call has no documentated response (yet)",
  45. * )
  46. */
  47. ?>
  48. And although definitions are generally used for model-level schema's' they can be used for smaller things as well.
  49. Like a @SWG\Schema, @SWG\Property or @SWG\Items that is uses multiple times.
  50. <?php
  51. /**
  52. * @SWG\Definition(
  53. * definition="product_status",
  54. * type="string",
  55. * description="The status of a product",
  56. * enum={"available", "discontinued"},
  57. * default="available"
  58. * )
  59. */