forked from zircote/swagger-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi-spec.php
66 lines (61 loc) · 1.79 KB
/
api-spec.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* @OA\Info(
* version="1.0.0",
* title="Example of using references in swagger-php",
* )
*/
?>
You can define top-level parameters which can be references with $ref="#/components/parameters/$parameter"
<?php
/**
* @OA\Parameter(
* parameter="product_id_in_path_required",
* name="product_id",
* description="The ID of the product",
* @OA\Schema(
* type="integer",
* format="int64",
* ),
* in="path",
* required=true
* )
*
* @OA\RequestBody(
* request="product_in_body",
* required=true,
* description="product_request",
* @OA\JsonContent(ref="#/components/schemas/Product")
* )
*/
?>
You can define top-level responses which can be references with $ref="#/components/responses/$response"
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.
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.
Then later, a search for '#/components/responses/todo' will reveal the operations I haven't documented yet.
<?php
/**
* @OA\Response(
* response="product",
* description="All information about a product",
* @OA\JsonContent(ref="#/components/schemas/Product")
* )
*
* @OA\Response(
* response="todo",
* description="This API call has no documentated response (yet)",
* )
*/
?>
And although definitions are generally used for model-level schema's' they can be used for smaller things as well.
Like a @OA\Schema, @OA\Property or @OA\Items that is uses multiple times.
<?php
/**
* @OA\Schema(
* schema="product_status",
* type="string",
* description="The status of a product",
* enum={"available", "discontinued"},
* default="available"
* )
*/