22
33namespace DoclerLabs \ApiClientGenerator \Entity ;
44
5+ use DoclerLabs \ApiClientGenerator \Input \InvalidSpecificationException ;
6+ use DoclerLabs \ApiClientGenerator \Output \Copy \Serializer \ContentType \FormUrlencodedContentTypeSerializer ;
7+ use DoclerLabs \ApiClientGenerator \Output \Copy \Serializer \ContentType \JsonContentTypeSerializer ;
8+ use DoclerLabs \ApiClientGenerator \Output \Copy \Serializer \ContentType \VdnApiJsonContentTypeSerializer ;
9+ use DoclerLabs \ApiClientGenerator \Output \Copy \Serializer \ContentType \XmlContentTypeSerializer ;
10+
511class Response
612{
13+ private const ALLOWED_CONTENT_TYPES = [
14+ JsonContentTypeSerializer::MIME_TYPE ,
15+ FormUrlencodedContentTypeSerializer::MIME_TYPE ,
16+ XmlContentTypeSerializer::MIME_TYPE ,
17+ VdnApiJsonContentTypeSerializer::MIME_TYPE ,
18+ ];
19+
720 private int $ statusCode ;
821 private ?Field $ body ;
22+ private array $ bodyContentTypes ;
923
10- public function __construct (int $ statusCode , Field $ body = null )
24+ public function __construct (int $ statusCode , Field $ body = null , array $ bodyContentTypes = [] )
1125 {
1226 $ this ->statusCode = $ statusCode ;
1327 $ this ->body = $ body ;
28+
29+ $ unsupportedContentTypes = array_diff ($ bodyContentTypes , static ::ALLOWED_CONTENT_TYPES );
30+ if (!empty ($ unsupportedContentTypes )) {
31+ throw new InvalidSpecificationException (
32+ sprintf ('Response content-type %s is not currently supported. ' , json_encode ($ unsupportedContentTypes ))
33+ );
34+ }
35+
36+ $ this ->bodyContentTypes = $ bodyContentTypes ;
1437 }
1538
1639 public function getStatusCode (): int
@@ -22,4 +45,9 @@ public function getBody(): ?Field
2245 {
2346 return $ this ->body ;
2447 }
48+
49+ public function getBodyContentTypes (): array
50+ {
51+ return $ this ->bodyContentTypes ;
52+ }
2553}
0 commit comments