forked from zircote/swagger-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpenApiSpec.php
110 lines (101 loc) · 2.65 KB
/
OpenApiSpec.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
namespace OpenApi\Examples\UsingRefs;
use OpenApi\Annotations as OA;
use OpenApi\Attributes as OAT;
/**
* @OA\Info(
* version="1.0.0",
* title="Example of using references in swagger-php",
* )
*/
class OpenApiSpec
{
}
/**
* You can define top-level parameters which can be references with $ref="#/components/parameters/[parameter-name]".
*
* The `ProductParameter` class is just used as a container to have some structural elements
* to associate the annotations with.
*/
abstract class ProductParameter
{
/**
* @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
* )
*/
/*
* Same using PHP attribute(s):
#[OAT\PathParameter(
parameter: 'product_id_in_path_required',
name: 'product_id',
description: 'The ID of the product',
schema: new OAT\Schema(type: 'integer', format: 'int64'),
required: true
)]
*/
public $product_id;
}
/**
* @OA\RequestBody(
* request="product_in_body",
* required=true,
* description="product_request",
* @OA\JsonContent(ref="#/components/schemas/Product")
* )
*/
class ProductRequestBody
{
}
/**
* You can define top-level responses which can be references with $ref="#/components/responses/response".
*
* I find it useful to add `@OA\Response(ref="#/components/responses/todo")` to the operations when i'm starting out with
* writing the swagger documentation.
* As it bypasses the `@OA\Get()` it 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.
*
* @OA\Response(
* response="product",
* description="All information about a product",
* @OA\JsonContent(ref="#/components/schemas/Product")
* )
*/
class ProductResponse
{
}
/**
* @OA\Response(
* response="todo",
* description="This API call has no documentated response (yet)",
* )
*/
class TodoResponse
{
}
/**
* 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.
*
* @OA\Schema(
* schema="product_status",
* type="string",
* description="The status of a product",
* enum={"available", "discontinued"},
* default="available"
* )
*/
class ProductStatus
{
}