Skip to content

Commit 8480b59

Browse files
committed
[server] scope & error annotations support
1 parent a6aa337 commit 8480b59

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

generator/SmdToSwaggerConverter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// }
2020
// }
2121
//
22-
// Also we supporting @scope <name> & @error <code> <message> tags from PHP annotation.
22+
// Also we supporting @scope <name> & @code <code> <message> tags from PHP annotation.
2323
// Scope adds 401 Unauthorized error.
2424

2525

src/BaseJsonRpcServerSmd.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ public function GetServiceMap() {
182182
}
183183
};
184184

185+
// check auth scope
186+
if ( preg_match_all( '/@scope\s+([^\s]*)/', $docComment, $matches ) ) {
187+
$result['services'][$methodName]['scope'] = current( $matches[1] );
188+
}
189+
185190
// process params
186191
foreach ( $method->getParameters() as $parameter ) {
187192
$name = $parameter->getName();
@@ -202,6 +207,13 @@ public function GetServiceMap() {
202207
if ( $t ) {
203208
$result['services'][$methodName]['returns'] = self::getServiceMapReturnType( $t, $c );
204209
}
210+
211+
// set simple error codes
212+
if ( preg_match_all( '/@code\s+(\d+)\s+(.*)/', $docComment, $matches ) ) {
213+
foreach ( $matches[1] as $i => $code ) {
214+
$result['services'][$methodName]['errors'][$code] = $matches[2][$i];
215+
}
216+
}
205217
}
206218
}
207219

0 commit comments

Comments
 (0)