Repository navigation
Expand file tree
/
Copy pathswagger.api.php
More file actions
146 lines (141 loc) · 4.43 KB
/
Copy pathswagger.api.php
File metadata and controls
146 lines (141 loc) · 4.43 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/**
* @file
* API documentation for the swagger module.
*/
/**
* Alter an operation and its associated method.
*
* Alter an operation and its associated method before they are added to the
* pool of methods for a resource. If the url calculated by swagger_api_resource
* is incorrect, it should be fixed here before that path is used to key the
* method.
*
* @param array $method
* The method object that will be added to the list of methods for its
* resource, keyed by $method['path']. Does not contain the operations for
* the method.
* @param array $operation
* The operation object that will be appended to the methods operations
* property.
*/
function hook_swagger_api_operation_alter(array &$method, array &$operation) {
if ($method['path'] == '/node/{nid}.{format}' && $operation['method'] == 'GET') {
$operation['notes'] = '<p>Additional fields may be found depending on the bundle of the node being retrieved.</p>';
$operation['errorResponses'][] = array(
'code' => 406,
'message' => 'Error',
);
}
}
/**
* Alter the swagger output for an entire resource.
*
* Useful for adding models to existing resources without using
* hook_service_resource_alter.
*
* @param array $api_data
* The data for an entire resource, including methods, operations, and models.
*
* @see hook_service_resource_alter()
*/
function hook_swagger_api_alter(array &$api_data) {
if ($api_data['resourcePath'] == '/user') {
foreach ($api_data['apis'] as &$api) {
if ($api['path'] == '/user/{uid}.{format}') {
foreach ($api['operations'] as &$operation) {
switch ($operation['method']) {
// create_user
case 'GET':
$operation['type'] = 'user';
break;
// update_user
case 'PUT':
foreach ($operation['parameters'] as &$parameter) {
if ($parameter['name'] == 'data') {
$parameter['type'] = 'user';
}
}
break;
}
}
}
}
$api_data['models']['user'] = array(
'id' => 'user',
'required' => array(
'name', 'mail',
),
'properties' => array(
'uid' => array(
'type' => 'string',
'description' => 'The id of the user.',
),
'name' => array(
'type' => 'string',
'description' => 'The username of the user.',
),
'mail' => array(
'type' => 'string',
'description' => 'The email address of the user.',
),
'theme' => array(
'type' => 'string',
'description' => 'The user\'s theme.',
),
'signature' => array(
'type' => 'string',
'description' => 'The user\'s signature.',
),
'signature_format' => array(
'type' => 'string',
'description' => 'The user\'s signature format.',
),
'created' => array(
'type' => 'string',
'format' => 'date-time',
'description' => 'The unix timestamp when the user was created.',
),
'access' => array(
'type' => 'string',
'format' => 'date-time',
'description' => 'The unix timestamp when the user last accessed the system.',
),
'login' => array(
'type' => 'string',
'format' => 'date-time',
'description' => 'The unix timestamp when the user last logged in.',
),
'status' => array(
'type' => 'string',
'enum' => array('0', '1'),
'description' => 'The active/blocked status of the user.',
),
'timezone' => array(
'type' => 'string',
'description' => 'The user\'s timezone.',
),
'language' => array(
'type' => 'string',
'description' => 'The user\'s language.',
),
'picture' => array(
'type' => 'string',
'description' => 'The fid of the user\'s picture.',
),
'init' => array(
'type' => 'string',
'description' => 'The email address used to initially create the user.',
),
'data' => array(
'type' => 'string',
'description' => 'Serialized array of data stored with the user.',
),
'uri' => array(
'type' => 'string',
'description' => 'URI to fetch the user\'s data.',
),
),
);
}
}