Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fix-v2-pricing-validation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@adcp/client": patch
---

Fix schema validation for v2 pricing options in get_products responses

When servers return v2-style pricing options (rate, is_fixed, price_guidance.floor), schema validation now normalizes them to v3 format (fixed_price, floor_price) before validation. This ensures v2 server responses pass validation against v3 schemas.
28 changes: 27 additions & 1 deletion src/lib/core/TaskExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ProtocolClient } from '../protocols';
import type { Storage } from '../storage/interfaces';
import { responseValidator } from './ResponseValidator';
import { unwrapProtocolResponse } from '../utils/response-unwrapper';
import { normalizeGetProductsResponse } from '../utils/pricing-adapter';
import type {
Message,
InputRequest,
Expand Down Expand Up @@ -1045,6 +1046,24 @@ export class TaskExecutor {
});
}

/**
* Normalize response data for schema validation
*
* Converts v2-style responses to v3 format before validation.
* This ensures validation passes for both v2 and v3 server responses.
*/
private normalizeResponseForValidation(response: any, taskName: string): any {
if (!response) return response;

switch (taskName) {
case 'get_products':
// Normalize v2 pricing options to v3 format
return normalizeGetProductsResponse(response);
default:
return response;
}
}

/**
* Validate response against AdCP schema and log any violations
*
Expand All @@ -1061,7 +1080,14 @@ export class TaskExecutor {
const logViolations = this.config.logSchemaViolations !== false; // Default: true

try {
const validationResult = responseValidator.validate(response, taskName, { validateSchema: true, strict: false });
// Normalize response to v3 format before validation
// This ensures v2 server responses pass validation against v3 schemas
const normalizedResponse = this.normalizeResponseForValidation(response, taskName);

const validationResult = responseValidator.validate(normalizedResponse, taskName, {
validateSchema: true,
strict: false,
});

if (!validationResult.valid) {
// Log to debug logs if enabled
Expand Down