Skip to content

Commit f452435

Browse files
authored
Fallback to another protocol when the primary protocol is not supported (#2007)
Skip service generation for smithy-rpc-v2-cbor
1 parent ffb3914 commit f452435

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/Definition/ServiceDefinition.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
class ServiceDefinition
1717
{
18+
private const SUPPORTED_PROTOCOLS = ['json', 'rest-json', 'query', 'rest-xml'];
19+
1820
/**
1921
* @var string
2022
*/
@@ -150,7 +152,19 @@ public function getJsonVersion(): float
150152

151153
public function getProtocol(): string
152154
{
153-
return $this->definition['metadata']['protocol'];
155+
$protocol = $this->definition['metadata']['protocol'];
156+
if (\in_array($protocol, self::SUPPORTED_PROTOCOLS, true)) {
157+
return $protocol;
158+
}
159+
160+
$protocols = $this->definition['metadata']['protocols'] ?? [];
161+
foreach (self::SUPPORTED_PROTOCOLS as $supportedProtocol) {
162+
if (\in_array($supportedProtocol, $protocols, true)) {
163+
return $supportedProtocol;
164+
}
165+
}
166+
167+
return $protocol;
154168
}
155169

156170
public function getApiReferenceUrl(): string

0 commit comments

Comments
 (0)