prisma-zod-generator
Version:
Prisma 2+ generator to emit Zod schemas from your Prisma schema
86 lines (85 loc) • 2.8 kB
TypeScript
/**
* PZG Pro - Contract Testing Generator
* DMMF-based implementation for API contract testing
*/
import { ProFeatureBase } from '../../core/ProFeatureBase';
export interface ContractTestConfig {
outputPath?: string;
providers?: string[];
consumers?: string[];
includeResponseValidation?: boolean;
includeRequestValidation?: boolean;
mockServer?: boolean;
wiremockConfig?: WiremockConfig;
}
export interface WiremockConfig {
port?: number;
host?: string;
mappingsPath?: string;
standalone?: boolean;
}
export interface ContractDefinition {
provider: string;
consumer: string;
interactions: Interaction[];
}
export interface Interaction {
description: string;
request: {
method: string;
path: string;
headers?: Record<string, string>;
body?: unknown;
query?: Record<string, string>;
};
response: {
status: number;
headers?: Record<string, string>;
body?: unknown;
};
}
export declare class ContractTestingGenerator extends ProFeatureBase {
private config;
constructor(context: any, config?: ContractTestConfig);
protected getFeatureName(): string;
protected generateFeature(): Promise<void>;
private generateContractDefinitions;
private generateModelInteractions;
private generateRequestSchema;
private generateResponseSchema;
private generateFieldExample;
private generatePactTests;
/**
* The provider half of the contract.
*
* The pack promised tests for "both sides" but only ever emitted the consumer
* pacts, so nothing verified that the provider actually satisfies them. Pact's
* Verifier replays the recorded pacts against a running provider.
*/
private generateProviderVerification;
private generatePactTestFile;
/**
* Express a body through Pact matchers rather than literal values.
*
* A pact built from literals only matches if the provider returns exactly those
* bytes, so a different id fails the contract test — it asserts the fixture
* instead of the contract. `eachLike` covers collections, `like` covers objects
* and scalars.
*/
private toPactMatcher;
private generatePactInteraction;
private generateMockServer;
private generateMockServerCode;
private generateMockEndpoint;
private generateWiremockMappings;
private generateWiremockMapping;
private generateValidationHelpers;
private generateValidationHelpersCode;
private generateModelValidationSchema;
private getZodType;
private generateContractDocumentation;
private generateDocumentationContent;
private generateAPIClient;
private generateAPIClientCode;
private generateModelClientMethods;
}