2
2
3
3
namespace DoclerLabs \ApiClientGenerator \Entity ;
4
4
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
+
5
11
class Response
6
12
{
13
+ private const ALLOWED_CONTENT_TYPES = [
14
+ JsonContentTypeSerializer::MIME_TYPE ,
15
+ FormUrlencodedContentTypeSerializer::MIME_TYPE ,
16
+ XmlContentTypeSerializer::MIME_TYPE ,
17
+ VdnApiJsonContentTypeSerializer::MIME_TYPE ,
18
+ ];
19
+
7
20
private int $ statusCode ;
8
21
private ?Field $ body ;
22
+ private array $ bodyContentTypes ;
9
23
10
- public function __construct (int $ statusCode , Field $ body = null )
24
+ public function __construct (int $ statusCode , Field $ body = null , array $ bodyContentTypes = [] )
11
25
{
12
26
$ this ->statusCode = $ statusCode ;
13
27
$ 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 ;
14
37
}
15
38
16
39
public function getStatusCode (): int
@@ -22,4 +45,9 @@ public function getBody(): ?Field
22
45
{
23
46
return $ this ->body ;
24
47
}
48
+
49
+ public function getBodyContentTypes (): array
50
+ {
51
+ return $ this ->bodyContentTypes ;
52
+ }
25
53
}
0 commit comments