55namespace FlixTech \SchemaRegistryApi ;
66
77use Assert \Assert ;
8+ use FlixTech \SchemaRegistryApi \Schema \AvroReference ;
89use GuzzleHttp \Psr7 \Request ;
910use GuzzleHttp \Psr7 \Utils ;
1011use Psr \Http \Message \RequestInterface ;
@@ -19,7 +20,7 @@ public static function allSubjectsRequest(): RequestInterface
1920 {
2021 return new Request (
2122 'GET ' ,
22- '/ subjects ' ,
23+ 'subjects ' ,
2324 Constants::ACCEPT_HEADER
2425 );
2526 }
@@ -28,7 +29,7 @@ public static function allSubjectVersionsRequest(string $subjectName): RequestIn
2829 {
2930 return new Request (
3031 'GET ' ,
31- Utils::uriFor ("/ subjects/$ subjectName/versions " ),
32+ Utils::uriFor ("subjects/ $ subjectName/versions " ),
3233 Constants::ACCEPT_HEADER
3334 );
3435 }
@@ -37,37 +38,37 @@ public static function singleSubjectVersionRequest(string $subjectName, string $
3738 {
3839 return new Request (
3940 'GET ' ,
40- Utils::uriFor ("/ subjects/$ subjectName/versions/ $ versionId " ),
41+ Utils::uriFor ("subjects/ $ subjectName/versions/ $ versionId " ),
4142 Constants::ACCEPT_HEADER
4243 );
4344 }
4445
45- public static function prepareJsonSchemaForTransfer (string $ schema ): string
46+ public static function prepareJsonSchemaForTransfer (string $ schema, AvroReference ... $ references ): string
4647 {
47- $ decoded = Json::decode ($ schema );
48-
49- if (is_array ($ decoded ) && array_key_exists ('schema ' , $ decoded )) {
50- return Json::encode ($ decoded );
51- }
48+ $ return = [
49+ 'schema ' => $ schema
50+ ];
5251
53- return Json::encode (['schema ' => Json::encode ($ decoded )]);
52+ return !$ references
53+ ? Json::encode ($ return )
54+ : Json::encode (array_merge ($ return , ['references ' => $ references ]));
5455 }
5556
56- public static function registerNewSchemaVersionWithSubjectRequest (string $ schema , string $ subjectName ): RequestInterface
57+ public static function registerNewSchemaVersionWithSubjectRequest (string $ schema , string $ subjectName, AvroReference ... $ references ): RequestInterface
5758 {
5859 return new Request (
5960 'POST ' ,
60- Utils::uriFor ("/ subjects/$ subjectName/versions " ),
61+ Utils::uriFor ("subjects/ $ subjectName/versions " ),
6162 Constants::CONTENT_TYPE_HEADER + Constants::ACCEPT_HEADER ,
62- self ::prepareJsonSchemaForTransfer (Json::validateStringAsJson ($ schema ))
63+ self ::prepareJsonSchemaForTransfer (Json::validateStringAsJson ($ schema ), ... $ references ),
6364 );
6465 }
6566
6667 public static function checkSchemaCompatibilityAgainstVersionRequest (string $ schema , string $ subjectName , string $ versionId ): RequestInterface
6768 {
6869 return new Request (
6970 'POST ' ,
70- Utils::uriFor ("/ compatibility/subjects/$ subjectName/versions/ $ versionId " ),
71+ Utils::uriFor ("compatibility/subjects/ $ subjectName/versions/ $ versionId " ),
7172 Constants::CONTENT_TYPE_HEADER + Constants::ACCEPT_HEADER ,
7273 self ::prepareJsonSchemaForTransfer (Json::validateStringAsJson ($ schema ))
7374 );
@@ -77,7 +78,7 @@ public static function checkIfSubjectHasSchemaRegisteredRequest(string $subjectN
7778 {
7879 return new Request (
7980 'POST ' ,
80- Utils::uriFor ("/ subjects/$ subjectName " ),
81+ Utils::uriFor ("subjects/ $ subjectName " ),
8182 Constants::CONTENT_TYPE_HEADER + Constants::ACCEPT_HEADER ,
8283 self ::prepareJsonSchemaForTransfer (Json::validateStringAsJson ($ schema ))
8384 );
@@ -87,7 +88,7 @@ public static function schemaRequest(string $id): RequestInterface
8788 {
8889 return new Request (
8990 'GET ' ,
90- Utils::uriFor ("/ schemas/ids/$ id " ),
91+ Utils::uriFor ("schemas/ids/ $ id " ),
9192 Constants::ACCEPT_HEADER
9293 );
9394 }
@@ -96,7 +97,7 @@ public static function defaultCompatibilityLevelRequest(): RequestInterface
9697 {
9798 return new Request (
9899 'GET ' ,
99- '/ config ' ,
100+ 'config ' ,
100101 Constants::ACCEPT_HEADER
101102 );
102103 }
@@ -130,7 +131,7 @@ public static function changeDefaultCompatibilityLevelRequest(string $level): Re
130131 {
131132 return new Request (
132133 'PUT ' ,
133- '/ config ' ,
134+ 'config ' ,
134135 Constants::ACCEPT_HEADER ,
135136 self ::prepareCompatibilityLevelForTransport (self ::validateCompatibilityLevel ($ level ))
136137 );
@@ -140,7 +141,7 @@ public static function subjectCompatibilityLevelRequest(string $subjectName): Re
140141 {
141142 return new Request (
142143 'GET ' ,
143- Utils::uriFor ("/ config/$ subjectName " ),
144+ Utils::uriFor ("config/ $ subjectName " ),
144145 Constants::ACCEPT_HEADER
145146 );
146147 }
@@ -149,7 +150,7 @@ public static function changeSubjectCompatibilityLevelRequest(string $subjectNam
149150 {
150151 return new Request (
151152 'PUT ' ,
152- Utils::uriFor ("/ config/$ subjectName " ),
153+ Utils::uriFor ("config/ $ subjectName " ),
153154 Constants::ACCEPT_HEADER ,
154155 self ::prepareCompatibilityLevelForTransport (self ::validateCompatibilityLevel ($ level ))
155156 );
@@ -194,7 +195,7 @@ public static function deleteSubjectRequest(string $subjectName, bool $permanent
194195
195196 return new Request (
196197 'DELETE ' ,
197- Utils::uriFor ("/ subjects/$ subjectName?permanent= $ query " ),
198+ Utils::uriFor ("subjects/ $ subjectName?permanent= $ query " ),
198199 Constants::ACCEPT_HEADER
199200 );
200201 }
@@ -211,7 +212,7 @@ public static function deleteSubjectVersionRequest(string $subjectName, string $
211212
212213 return new Request (
213214 'DELETE ' ,
214- Utils::uriFor ("/ subjects/$ subjectName/versions/ $ versionId?permanent= $ query " ),
215+ Utils::uriFor ("subjects/ $ subjectName/versions/ $ versionId?permanent= $ query " ),
215216 Constants::ACCEPT_HEADER
216217 );
217218 }
0 commit comments