@unkey/api
Version:
Developer-friendly & type-safe Typescript SDK specifically catered to leverage *@unkey/api* API.
82 lines (73 loc) • 2.18 kB
text/typescript
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
export type ValidationError = {
/**
* Where the error occurred, e.g. 'body.items[3].tags' or 'path.thing-id'
*/
location: string;
/**
* Error message text
*/
message: string;
/**
* A human-readable message describing how to fix the error.
*/
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(),
});
/** @internal */
export type ValidationError$Outbound = {
location: string;
message: string;
fix?: string | undefined;
};
/** @internal */
export const ValidationError$outboundSchema: z.ZodType<
ValidationError$Outbound,
z.ZodTypeDef,
ValidationError
> = z.object({
location: z.string(),
message: z.string(),
fix: z.string().optional(),
});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace ValidationError$ {
/** @deprecated use `ValidationError$inboundSchema` instead. */
export const inboundSchema = ValidationError$inboundSchema;
/** @deprecated use `ValidationError$outboundSchema` instead. */
export const outboundSchema = ValidationError$outboundSchema;
/** @deprecated use `ValidationError$Outbound` instead. */
export type Outbound = ValidationError$Outbound;
}
export function validationErrorToJSON(
validationError: ValidationError,
): string {
return JSON.stringify(ValidationError$outboundSchema.parse(validationError));
}
export function validationErrorFromJSON(
jsonString: string,
): SafeParseResult<ValidationError, SDKValidationError> {
return safeParse(
jsonString,
(x) => ValidationError$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'ValidationError' from JSON`,
);
}