api-spec.php 1.8 KB

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