Exploring schema validation for nushell/http-nu
We want to validate records against a schema (like JSON Schema). Nushell already has type syntax for command signatures:
def foo []: record<
name: string,
age: int,
email?: string,
tags: list<string>,
address: record<city: string, zip: int>
> -> nothing { }This supports optional fields (?), nested records, lists, etc. But there's no first-class "type value" - it only exists in signatures.
Options for expressing schemas:
1. Command signature
def my-schema []: record<name: string, tags: list<string>, address: record<city: string>> -> nothing { }
# query via: help commands | where name == "my-schema" | get input_outputWorks today without changes.
2. Type string (parsed by nushell's parser)
"record<name: string, tags: list<string>, address: record<city: string>>" | validate $dataReuses existing nushell syntax.
3. Record-as-schema
{name: "string", tags: "list<string>", address: {city: "string"}} | validate $dataIt's a real record. Would need to define semantics for nested structures.
4. New type literal
let schema = type record<name: string, tags: list<string>, address: record<city: string>>
$data | validate $schemaFirst-class type values. Would require nushell changes: new Type value variant, parser support for type keyword, and plumbing through the value system.
Thoughts? Which feels most nushell-native?