@@ -41,7 +41,8 @@ SchemaAPIClient::SchemaAPIClient(const SchemaAPIConfig &a_config)
4141 curl_easy_setopt (m_curl, CURLOPT_CAINFO , m_config.ca_cert_path .c_str ());
4242
4343 // ── Timeouts ──────────────────────────────────────────────────────────
44- curl_easy_setopt (m_curl, CURLOPT_CONNECTTIMEOUT , m_config.connect_timeout_sec );
44+ curl_easy_setopt (m_curl, CURLOPT_CONNECTTIMEOUT ,
45+ m_config.connect_timeout_sec );
4546 curl_easy_setopt (m_curl, CURLOPT_TIMEOUT , m_config.request_timeout_sec );
4647}
4748
@@ -50,6 +51,15 @@ SchemaAPIClient::~SchemaAPIClient() {
5051 curl_easy_cleanup (m_curl);
5152}
5253
54+ // ── Custom Headers ──────────────────────────────────────────────────────────
55+
56+ void SchemaAPIClient::setCustomHeaders (
57+ const std::map<std::string, std::string> &a_headers) {
58+ m_custom_headers = a_headers;
59+ }
60+
61+ void SchemaAPIClient::clearCustomHeaders () { m_custom_headers.clear (); }
62+
5363// ── Low-level CURL ──────────────────────────────────────────────────────────
5464
5565nlohmann::json SchemaAPIClient::curlPerform (const std::string &a_method,
@@ -74,13 +84,20 @@ nlohmann::json SchemaAPIClient::curlPerform(const std::string &a_method,
7484 headers = curl_slist_append (headers, " Accept: application/json" );
7585
7686 if (m_config.hasAuth ()) {
77- std::string auth = " Authorization: Bearer " + m_config.bearer_token ;
78- headers = curl_slist_append (headers, auth.c_str ());
87+ std::string auth = " Authorization: Bearer " + m_config.bearer_token ;
88+ headers = curl_slist_append (headers, auth.c_str ());
7989 }
8090
8191 std::string corr_header = " x-correlation-id: " + log_context.correlation_id ;
8292 headers = curl_slist_append (headers, corr_header.c_str ());
8393
94+ // Append any custom headers (used by integration tests for Prism's
95+ // Prefer header, etc.)
96+ for (const auto &[name, value] : m_custom_headers) {
97+ std::string h = name + " : " + value;
98+ headers = curl_slist_append (headers, h.c_str ());
99+ }
100+
84101 curl_easy_setopt (m_curl, CURLOPT_HTTPHEADER , headers);
85102
86103 if (a_body && !a_body->empty ()) {
@@ -125,8 +142,8 @@ nlohmann::json SchemaAPIClient::curlPerform(const std::string &a_method,
125142nlohmann::json SchemaAPIClient::httpGet (const std::string &a_path,
126143 LogContext log_context) {
127144 long code = 0 ;
128- auto result =
129- curlPerform ( " GET " , m_config. base_url + a_path, nullptr , code, log_context);
145+ auto result = curlPerform ( " GET " , m_config. base_url + a_path, nullptr , code,
146+ log_context);
130147 if (code == 404 )
131148 EXCEPT_PARAM (BAD_REQUEST , " SchemaAPI: not found: " << a_path);
132149 if (code < 200 || code >= 300 )
@@ -139,17 +156,17 @@ nlohmann::json SchemaAPIClient::httpPost(const std::string &a_path,
139156 long &a_http_code,
140157 LogContext log_context) {
141158 std::string body_str = a_body.dump ();
142- return curlPerform (" POST" , m_config.base_url + a_path, &body_str, a_http_code,
143- log_context);
159+ return curlPerform (" POST" , m_config.base_url + a_path, &body_str,
160+ a_http_code, log_context);
144161}
145162
146163nlohmann::json SchemaAPIClient::httpPut (const std::string &a_path,
147164 const nlohmann::json &a_body,
148165 LogContext log_context) {
149166 long code = 0 ;
150167 std::string body_str = a_body.dump ();
151- auto result =
152- curlPerform ( " PUT " , m_config. base_url + a_path, &body_str, code, log_context);
168+ auto result = curlPerform ( " PUT " , m_config. base_url + a_path, &body_str, code,
169+ log_context);
153170 if (code < 200 || code >= 300 )
154171 EXCEPT_PARAM (SERVICE_ERROR , " SchemaAPI PUT failed, HTTP " << code);
155172 return result;
@@ -160,8 +177,8 @@ nlohmann::json SchemaAPIClient::httpPatch(const std::string &a_path,
160177 LogContext log_context) {
161178 long code = 0 ;
162179 std::string body_str = a_body.dump ();
163- auto result =
164- curlPerform ( " PATCH " , m_config. base_url + a_path, &body_str, code, log_context);
180+ auto result = curlPerform ( " PATCH " , m_config. base_url + a_path, &body_str,
181+ code, log_context);
165182 if (code == 404 )
166183 EXCEPT_PARAM (BAD_REQUEST , " SchemaAPI: not found for PATCH" );
167184 if (code < 200 || code >= 300 )
@@ -172,7 +189,8 @@ nlohmann::json SchemaAPIClient::httpPatch(const std::string &a_path,
172189void SchemaAPIClient::httpDelete (const std::string &a_path,
173190 LogContext log_context) {
174191 long code = 0 ;
175- curlPerform (" DELETE" , m_config.base_url + a_path, nullptr , code, log_context);
192+ curlPerform (" DELETE" , m_config.base_url + a_path, nullptr , code,
193+ log_context);
176194 if (code != 204 && code != 404 )
177195 EXCEPT_PARAM (SERVICE_ERROR , " SchemaAPI DELETE failed, HTTP " << code);
178196}
@@ -182,31 +200,48 @@ void SchemaAPIClient::httpDelete(const std::string &a_path,
182200void SchemaAPIClient::putSchema (const std::string &a_id,
183201 const std::string &a_name,
184202 const std::string &a_description,
203+ const std::string &a_schema_format,
204+ const std::string &a_engine,
185205 const std::string &a_content,
206+ const std::string &a_version,
186207 LogContext log_context) {
187208 nlohmann::json body;
188- body[ " id " ] = a_id;
209+ // Required fields per SchemaReplace
189210 body[" name" ] = a_name;
211+ body[" schema_format" ] = a_schema_format;
212+ body[" engine" ] = a_engine;
190213 body[" content" ] = a_content;
214+
215+ // Optional fields — only include when non-empty
191216 if (!a_description.empty ())
192217 body[" description" ] = a_description;
218+ if (!a_version.empty ())
219+ body[" version" ] = a_version;
193220
194221 httpPut (" /schemas/" + a_id, body, log_context);
195222}
196223
197- void SchemaAPIClient::patchSchema (const std::string &a_id,
198- const std::optional<std::string> &a_name,
199- const std::optional<std::string> &a_description,
200- const std::optional<std::string> &a_content,
201- LogContext log_context) {
202- nlohmann::json body;
203- body[" id" ] = a_id;
224+ void SchemaAPIClient::patchSchema (
225+ const std::string &a_id, const std::optional<std::string> &a_name,
226+ const std::optional<std::string> &a_description,
227+ const std::optional<std::string> &a_schema_format,
228+ const std::optional<std::string> &a_engine,
229+ const std::optional<std::string> &a_content,
230+ const std::optional<std::string> &a_version, LogContext log_context) {
231+ nlohmann::json body = nlohmann::json::object ();
232+
204233 if (a_name)
205234 body[" name" ] = *a_name;
206235 if (a_description)
207236 body[" description" ] = *a_description;
237+ if (a_schema_format)
238+ body[" schema_format" ] = *a_schema_format;
239+ if (a_engine)
240+ body[" engine" ] = *a_engine;
208241 if (a_content)
209242 body[" content" ] = *a_content;
243+ if (a_version)
244+ body[" version" ] = *a_version;
210245
211246 httpPatch (" /schemas/" + a_id, body, log_context);
212247}
@@ -254,7 +289,6 @@ bool SchemaAPIClient::validateMetadata(const std::string &a_schema_id,
254289 std::string &a_warnings,
255290 LogContext log_context) {
256291 nlohmann::json body;
257- body[" id" ] = a_schema_id;
258292 body[" metadata_format" ] = a_metadata_format;
259293 body[" engine" ] = a_engine;
260294 body[" content" ] = a_metadata_content;
0 commit comments