@unkey/api
Version:
Developer-friendly & type-safe Typescript SDK specifically catered to leverage *@unkey/api* API.
55 lines (50 loc) • 2.03 kB
text/typescript
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod/v3";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
/**
* Individual validation error details. Each validation error provides precise information about what failed, where it failed, and how to fix it, enabling efficient error resolution.
*/
export type ValidationError = {
/**
* JSON path indicating exactly where in the request the error occurred. This helps pinpoint the problematic field or parameter. Examples include:
*
* @remarks
* - 'body.name' (field in request body)
* - 'body.items[3].tags' (nested array element)
* - 'path.apiId' (path parameter)
* - 'query.limit' (query parameter)
* Use this location to identify exactly which part of your request needs correction.
*/
location: string;
/**
* Detailed error message explaining what validation rule was violated. This provides specific information about why the field or parameter was rejected, such as format errors, invalid values, or constraint violations.
*/
message: string;
/**
* A human-readable suggestion describing how to fix the error. This provides practical guidance on what changes would satisfy the validation requirements. Not all validation errors include fix suggestions, but when present, they offer specific remediation advice.
*/
fix?: string | undefined;
};
/** @internal */
export const ValidationError$inboundSchema: z.ZodType<
ValidationError,
z.ZodTypeDef,
unknown
> = z.object({
location: z.string(),
message: z.string(),
fix: z.string().optional(),
});
export function validationErrorFromJSON(
jsonString: string,
): SafeParseResult<ValidationError, SDKValidationError> {
return safeParse(
jsonString,
(x) => ValidationError$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'ValidationError' from JSON`,
);
}