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
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ If another instruction file (for example `.github/copilot-instructions.md`) conf

## Repository overview

ZodSharp is a high-performance schema validation library for C#, ported from TypeScript [Zod](https://github.com/colinhacks/zod). It uses struct-based rules and `Span<T>` to minimise allocations, and ships a compile-time source generator for maximum performance.
Purview.ZodSharp is a high-performance schema validation library for C#, ported from TypeScript [Zod](https://github.com/colinhacks/zod). It uses struct-based rules and `Span<T>` to minimise allocations, and ships a compile-time source generator for maximum performance.

- Fork of [guinhx/ZodSharp](https://github.com/guinhx/ZodSharp), maintained at `purview-dev/zodsharp`.
- Public API namespaces are `ZodSharp.*`; packages and assemblies are published under the `Purview.ZodSharp.*` package IDs.
Expand Down Expand Up @@ -102,7 +102,7 @@ Keep `purview-build.json`'s `PackValidation` requirements in sync with any packa

## Cross-platform fixtures

Schemas and fixtures shared between TypeScript/Zod and C#/ZodSharp live under `src/ts/`. The fixture generator (`bun run generate-fixtures`) writes JSON fixtures and a `manifest.json` that the C# tests consume; the C# cross-platform tests write output to `src/tests/cross-platform/output/`, which the vitest tests (`tests/ts/cross-platform.test.ts`) read. Keep the TS `UserSchema` and the C# `CrossPlatformUserSchema` in sync.
Schemas and fixtures shared between TypeScript/Zod and C#/Purview.ZodSharp live under `src/ts/`. The fixture generator (`bun run generate-fixtures`) writes JSON fixtures and a `manifest.json` that the C# tests consume; the C# cross-platform tests write output to `src/tests/cross-platform/output/`, which the vitest tests (`tests/ts/cross-platform.test.ts`) read. Keep the TS `UserSchema` and the C# `CrossPlatformUserSchema` in sync.

## Commit conventions

Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# ZodSharp
# Purview.ZodSharp

[![NuGet version](https://img.shields.io/nuget/v/Purview.ZodSharp.svg)](https://www.nuget.org/packages/Purview.ZodSharp)
[![Release](https://github.com/purview-dev/zodsharp/actions/workflows/release.yml/badge.svg)](https://github.com/purview-dev/zodsharp/actions/workflows/release.yml)

**ZodSharp** is a high-performance schema validation library for C#, ported from TypeScript [Zod](https://github.com/colinhacks/zod). It features zero-allocation validation, struct-based rules, fluent API, and source generator support for maximum performance.
**Purview.ZodSharp** is a high-performance schema validation library for C#, ported from TypeScript [Zod](https://github.com/colinhacks/zod). It features zero-allocation validation, struct-based rules, fluent API, and source generator support for maximum performance.

This project is a fork of [guinhx/ZodSharp](https://github.com/guinhx/ZodSharp), maintained at [github.com/purview-dev/zodsharp](https://github.com/purview-dev/zodsharp) under the `Purview.*` package IDs.

Expand Down Expand Up @@ -208,7 +208,7 @@ if (!result.IsSuccess)

## Performance

ZodSharp is designed for maximum performance with zero-allocation validation and struct-based rules. Here's what makes it fast:
Purview.ZodSharp is designed for maximum performance with zero-allocation validation and struct-based rules. Here's what makes it fast:

### Performance Characteristics

Expand Down Expand Up @@ -237,7 +237,7 @@ Full results for every suite are in the [performance README](src/src/Benchmarks/

### Performance Optimizations

ZodSharp implements several optimizations for maximum performance:
Purview.ZodSharp implements several optimizations for maximum performance:

#### 1. Zero-allocation Validation

Expand Down Expand Up @@ -373,7 +373,7 @@ var result = schema.Validate(null); // "unknown"

### JSON Integration

ZodSharp ships separate integration packages for the two major .NET JSON libraries.
Purview.ZodSharp ships separate integration packages for the two major .NET JSON libraries.

#### System.Text.Json (`Purview.ZodSharp.SystemTextJson`)

Expand Down Expand Up @@ -410,11 +410,11 @@ var converter = schema.CreateValidatingConverter();

### JSON Schema Interoperability

Share schemas between TypeScript (Zod) and C# (ZodSharp) using JSON Schema. This enables infinite interoperability, allowing you to define a schema in one language and reuse it in another.
Share schemas between TypeScript (Zod) and C# (Purview.ZodSharp) using JSON Schema. This enables infinite interoperability, allowing you to define a schema in one language and reuse it in another.

The export API (`Z.ToJsonSchema`) lives in the core `Purview.ZodSharp` package. The import API (`Z.FromJsonSchema`) is provided by the JSON integration package you choose — either `Purview.ZodSharp.SystemTextJson` or `Purview.ZodSharp.NewtonsoftJson`.

#### Export to JSON Schema (ZodSharp -> JSON Schema)
#### Export to JSON Schema (Purview.ZodSharp -> JSON Schema)

```csharp
var userSchema = Z.Object()
Expand All @@ -440,7 +440,7 @@ using ZodSharp.JsonSchema;
var newtonsoftJson = JsonConvert.SerializeObject(jsonSchema, JsonSchemaSerializerOptions.Default);
```

#### Import from JSON Schema (JSON Schema -> ZodSharp)
#### Import from JSON Schema (JSON Schema -> Purview.ZodSharp)

Add either `Purview.ZodSharp.SystemTextJson` or `Purview.ZodSharp.NewtonsoftJson` to your project, then:

Expand All @@ -454,7 +454,7 @@ var jsonSchemaString = @"{
""required"": [""name"", ""email""]
}";

// Parse into ZodSharp schema
// Parse into Purview.ZodSharp schema
var userSchema = Z.FromJsonSchema(jsonSchemaString);

// Validate data
Expand All @@ -478,7 +478,7 @@ const jsonSchema = z.toJSONSchema(UserSchema);
// Send jsonSchema to backend...
```

**Backend (C#/ZodSharp):**
**Backend (C#/Purview.ZodSharp):**

```csharp
// Receive jsonSchema...
Expand Down
2 changes: 1 addition & 1 deletion docs/wiki/AspNetCore-Integration.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ASP.NET Core Integration

The `Purview.ZodSharp.AspNetCore` package converts failed validation results into standard `ProblemDetails` / `HttpValidationProblemDetails` payloads while preserving the structured validation issues. It also registers ZodSharp schema resolution into your application's dependency injection container.
The `Purview.ZodSharp.AspNetCore` package converts failed validation results into standard `ProblemDetails` / `HttpValidationProblemDetails` payloads while preserving the structured validation issues. It also registers Purview.ZodSharp schema resolution into your application's dependency injection container.

## Install

Expand Down
4 changes: 2 additions & 2 deletions docs/wiki/Cross-Platform-Interop.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Cross-Platform Interop

ZodSharp ships a cross-platform fixture pipeline that proves the C# implementation agrees with TypeScript/Zod. The TypeScript side runs on [Bun](https://bun.sh); the C# side runs under the TUnit test suite.
Purview.ZodSharp ships a cross-platform fixture pipeline that proves the C# implementation agrees with TypeScript/Zod. The TypeScript side runs on [Bun](https://bun.sh); the C# side runs under the TUnit test suite.

## The schema

Both sides define the same user schema — TypeScript `UserSchema` in `src/ts/schema.ts` and the C# `CrossPlatformUserSchema` in `src/tests/SystemTextJson.UnitTests/CrossPlatformFixtures.cs` (mirrored by `NewtonsoftJson.UnitTests`):

| Field | Zod (TS) | ZodSharp (C#) |
| Field | Zod (TS) | Purview.ZodSharp (C#) |
|---|---|---|
| `name` | `z.string().min(1)` | min-length 1 |
| `age` | `z.number().int().min(0).max(120)` | `0..120` integer |
Expand Down
2 changes: 1 addition & 1 deletion docs/wiki/Dependency-Injection.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Dependency Injection

ZodSharp can resolve validators through an `IZodSchemaFactory` registry, and can validate options objects through `IValidateOptions<T>`.
Purview.ZodSharp can resolve validators through an `IZodSchemaFactory` registry, and can validate options objects through `IValidateOptions<T>`.

## IZodSchemaFactory

Expand Down
4 changes: 2 additions & 2 deletions docs/wiki/Home.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ZodSharp Wiki
# Purview.ZodSharp Wiki

ZodSharp is a high-performance schema validation library for C#, ported from TypeScript [Zod](https://github.com/colinhacks/zod). It uses struct-based rules and `Span<T>` to minimise allocations, ships a fluent API that mirrors Zod, exports and imports JSON Schema, and includes a compile-time source generator for maximum performance.
Purview.ZodSharp is a high-performance schema validation library for C#, ported from TypeScript [Zod](https://github.com/colinhacks/zod). It uses struct-based rules and `Span<T>` to minimise allocations, ships a fluent API that mirrors Zod, exports and imports JSON Schema, and includes a compile-time source generator for maximum performance.

This wiki is the project documentation hub for the core API, source generator, JSON integration packages, and the cross-platform TypeScript tooling. It is a fork of [guinhx/ZodSharp](https://github.com/guinhx/ZodSharp), maintained under the `Purview.*` package IDs.

Expand Down
4 changes: 2 additions & 2 deletions docs/wiki/JsonSchema-Export.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# JSON Schema Export

Export a ZodSharp schema to a JSON Schema (Draft 2020-12) definition with `Z.ToJsonSchema`, which lives in the core `Purview.ZodSharp` package.
Export a Purview.ZodSharp schema to a JSON Schema (Draft 2020-12) definition with `Z.ToJsonSchema`, which lives in the core `Purview.ZodSharp` package.

```csharp
using ZodSharp;
Expand Down Expand Up @@ -67,4 +67,4 @@ var json = JsonConvert.SerializeObject(jsonSchema, JsonSchemaSerializerOptions.D

## Round-trip

Import the exported definition back into ZodSharp with `Z.FromJsonSchema` from an integration package — see [JSON Schema Import](JsonSchema-Import.md) and the round-trip example in the example app (`JsonSchemaExamples`).
Import the exported definition back into Purview.ZodSharp with `Z.FromJsonSchema` from an integration package — see [JSON Schema Import](JsonSchema-Import.md) and the round-trip example in the example app (`JsonSchemaExamples`).
2 changes: 1 addition & 1 deletion docs/wiki/JsonSchema-Import.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# JSON Schema Import

Import a JSON Schema into a ZodSharp schema with `Z.FromJsonSchema`. This API is provided by the JSON integration packages — reference either `Purview.ZodSharp.SystemTextJson` or `Purview.ZodSharp.NewtonsoftJson` (both expose the same surface).
Import a JSON Schema into a Purview.ZodSharp schema with `Z.FromJsonSchema`. This API is provided by the JSON integration packages — reference either `Purview.ZodSharp.SystemTextJson` or `Purview.ZodSharp.NewtonsoftJson` (both expose the same surface).

```csharp
using ZodSharp;
Expand Down
2 changes: 1 addition & 1 deletion docs/wiki/Performance.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Performance

ZodSharp is designed for maximum performance: validation rules are `readonly record struct`s, hot paths use `Span<T>`, and the source generator emits direct typed codegen with no reflection. The committed BenchmarkDotNet suite measures every scenario.
Purview.ZodSharp is designed for maximum performance: validation rules are `readonly record struct`s, hot paths use `Span<T>`, and the source generator emits direct typed codegen with no reflection. The committed BenchmarkDotNet suite measures every scenario.

## Running the benchmarks

Expand Down
2 changes: 1 addition & 1 deletion docs/wiki/Release-Flow.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Release Flow

ZodSharp releases are driven by the shared [purview-dev/build](https://github.com/purview-dev/build) pipeline through the GitHub Actions workflows in `.github/workflows/`.
Purview.ZodSharp releases are driven by the shared [purview-dev/build](https://github.com/purview-dev/build) pipeline through the GitHub Actions workflows in `.github/workflows/`.

## Versioning

Expand Down
4 changes: 2 additions & 2 deletions src/src/Benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ZodSharp Performance Benchmarks
# Purview.ZodSharp Performance Benchmarks

BenchmarkDotNet performance suite for ZodSharp. This is a `net10.0` console application; every suite uses `[MemoryDiagnoser]` plus a `[SimpleJob]` profile so time and allocation data are captured together.
BenchmarkDotNet performance suite for Purview.ZodSharp. This is a `net10.0` console application; every suite uses `[MemoryDiagnoser]` plus a `[SimpleJob]` profile so time and allocation data are captured together.

## Structure

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<ItemGroup Label="Compiler Visible SDK Properties">
<CompilerVisibleProperty Include="DisableZodSharpSourceGenerator">
<Description>Specifies whether to disable ZodSharp source generators.</Description>
<Description>Specifies whether to disable Purview.ZodSharp source generators.</Description>
</CompilerVisibleProperty>
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions tests/ts/cross-platform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*
* These tests verify that:
* 1. Zod validates the shared fixtures correctly (produces a manifest).
* 2. JSON produced by ZodSharp (C#) can be parsed by Zod and vice-versa.
* 3. The validation outcomes match between Zod and ZodSharp for the same data.
* 2. JSON produced by Purview.ZodSharp (C#) can be parsed by Zod and vice-versa.
* 3. The validation outcomes match between Zod and Purview.ZodSharp for the same data.
*/
import { describe, it, expect } from "vitest";
import { readFileSync, readdirSync } from "node:fs";
Expand Down