Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
bb61c06
replace typify's type generation with the typespace crate
Sep 8, 2026
fc31b25
turn on typespace's typify compatibility mode
Sep 8, 2026
9a31beb
forward typify's requested traits and attributes into typespace
Sep 8, 2026
a0bde86
update tests
ahl Sep 8, 2026
91077f9
declare JsonSchema on the built-in natives that implement it
ahl Sep 9, 2026
e26b3cd
assume JsonSchema on consumer-named natives like the rest of the base…
ahl Sep 9, 2026
ca3be22
less is more
ahl Sep 10, 2026
e998b14
follow typespace's API to its current surface
ahl Sep 17, 2026
cdc8cd9
adapt the empty-anyOf test across the rebase
ahl Sep 19, 2026
8ff0b40
update deps
ahl Sep 20, 2026
9f27f56
mismerge
ahl Sep 20, 2026
3b6e590
rip out dead and dying code
ahl Sep 20, 2026
629f19c
remove default checking
ahl Sep 20, 2026
627e6b6
pruning and cleanup
ahl Sep 20, 2026
65593ff
add inserted_type
ahl Sep 20, 2026
2cfa644
clean up stale comments
ahl Sep 21, 2026
9e2c03f
hand rendering settings to typespace
ahl Sep 28, 2026
4cea6d3
update to typespace v0.0.1-alpha.2
ahl Sep 28, 2026
f0e7036
prepare for 0.10.0-alpha.1 release
ahl Sep 28, 2026
76c40c9
release typify 0.10.0-alpha.1
ahl Sep 28, 2026
4401293
use codespace to track crate dependencies (#1089)
ahl Oct 5, 2026
ba5ba82
prepare for 0.10.0-alpha.2 release
ahl Oct 5, 2026
bceff9a
release typify 0.10.0-alpha.2
ahl Oct 5, 2026
7cf5f96
leave a consumer-named type's other traits unknown (#1094)
ahl Oct 14, 2026
cdf8e31
prepare for 0.10.0-alpha.3 release
ahl Oct 14, 2026
046ce32
release typify 0.10.0-alpha.3
ahl Oct 14, 2026
7984748
update typespace to 0.1.0 (#1099)
ahl Nov 9, 2026
20bf98e
#1103 to v0_10 (#1104)
ahl Nov 15, 2026
a83d3c5
fix clippy warnings on v0_10 (#1105)
ahl Nov 15, 2026
2431c15
update to typespace 0.1.1; prepare for 0.10 release (#1106)
ahl Nov 16, 2026
7ac08dc
Merge remote-tracking branch 'origin/main' into v0_10
ahl Nov 16, 2026
6a4d8fb
nits
ahl Nov 16, 2026
587b56c
self-review
ahl Nov 16, 2026
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
68 changes: 67 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,73 @@

== Unreleased changes (release date TBD)

https://github.com/oxidecomputer/typify/compare/v0.8.0\...HEAD[Full list of commits]
https://github.com/oxidecomputer/typify/compare/v0.10.0-alpha.3\...HEAD[Full list of commits]

Type generation moves to the
https://github.com/oxidecomputer/typespace[typespace] crate.

*Builder API*

* `TypeSpaceSettings` retains settings that modify translation (`with_replacement`,
`with_patch`, `with_conversion`, `with_crate`, `with_unknown_crates`);
everything pertaining to rendering is specified in `typespace::Settings`
which can be reached through `map_typespace_settings`; `with_derive`,
`with_attr`, `with_struct_builder`, `with_map_type`, and `with_type_mod` are
gone, as is `MapType`
* `TypeSpace::to_stream` returns a `Result`; `to_codespace` gives the rendered
code as a `codespace::Codespace` and `to_typespace` produces the finished
`typespace::Typespace`
* The `Type`, `TypeDetails`, `TypeEnum`, `TypeStruct`, and `TypeNewtype` views
are gone; `TypeSpace::inserted_type` may be used for queries
* A derive name is parsed by `typespace`: a trait it models is handled as that
trait, any other path is a foreign derive written on every type; a bare name
that is neither is an error

*Generated code*

* Items are emitted in type-name order rather than in schema order
* Pattern checks compile the regex with the ECMA-262 `u` flag, as JSON Schema
specifies, so `\p{..}` and `\u{..}` escapes work; a pattern with an identity
escape the `u` flag forbids is now a generation error (#1103)
* A constrained string newtype does its validation in `TryFrom<&str>`, and a
non-string newtype no longer gets `TryFrom<&str>` or `TryFrom<String>`
(#1078, #1079)
* The `error` module and shared default functions are emitted only when
something references them (#1080, #1082)
* The 2024 keyword `gen` is no longer used as an identifier (#1074)
* An `anyOf` construction with mixed types that previously generated an
unusable type now results in an error

*Other*

* A type named through `replace`, `convert`, or `x-rust-type` is assumed to
implement whatever the compiler can check rather than failing generation
for a trait typify cannot see (#1094)
* The minimum supported Rust version is 1.97; edition is 2024

== 0.10.0-alpha.3 (released 2026-10-14)

https://github.com/oxidecomputer/typify/compare/v0.10.0-alpha.2\...v0.10.0-alpha.3[Full list of commits]

* A type named through `replace`, `convert`, or `x-rust-type` no longer
fails generation for a trait typify cannot see it implement, such as `Ord`
for a set element; the compiler checks the real type (#1094)
* Under `typify_compat`, a derive the consumer asks for is written on every
type rather than withheld with typify's own comparison derives (typespace
0.0.1-alpha.4)

== 0.10.0-alpha.2 (released 2026-10-05)

https://github.com/oxidecomputer/typify/compare/v0.8.0\...v0.10.0-alpha.2[Full list of commits]

**Big Release**

Type generation moves to the `typespace` crate. This impacts a lot of API
surface area for both builder and macro consumers including how settings are
configured and how rendered code is produced, including item ordering in the
rendered code.

Feedback is very welcome as we head to a proper release.

== 0.8.0 (released 2026-09-09)

Expand Down
79 changes: 75 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ members = [
resolver = "2"

[workspace.dependencies]
typify = { version = "0.8.0", path = "typify" }
typify-impl = { version = "0.8.0", path = "typify-impl" }
typify-macro = { version = "0.8.0", path = "typify-macro" }
typify = { version = "0.10.0-alpha.3", path = "typify" }
typify-impl = { version = "0.10.0-alpha.3", path = "typify-impl" }
typify-macro = { version = "0.10.0-alpha.3", path = "typify-macro" }

assert_cmd = "2.2.2"
chrono = { version = "0.4.45", features = ["serde"] }
Expand Down Expand Up @@ -43,5 +43,6 @@ syn = { version = "3.0.2", features = ["full"] }
tempfile = "3.27.0"
thiserror = "2.0.18"
trybuild = "1.0.116"
typespace = "0.1.1"
unicode-ident = "1.0.24"
uuid = "1.16.0"
5 changes: 3 additions & 2 deletions cargo-typify/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "cargo-typify"
version = "0.8.0"
edition = "2021"
version = "0.10.0"
edition = "2024"
license = "Apache-2.0"
description = "cargo command to generate Rust code from a JSON Schema"
repository = "https://github.com/oxidecomputer/typify"
Expand All @@ -12,6 +12,7 @@ categories = ["api-bindings", "compilers"]
default-run = "cargo-typify"

[dependencies]
syn = { workspace = true }
typify = { workspace = true }

clap = { workspace = true }
Expand Down
64 changes: 43 additions & 21 deletions cargo-typify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
use std::path::PathBuf;

use clap::{ArgGroup, Args};
use color_eyre::eyre::{eyre, Context, Result};
use typify::{CrateVers, MapType, TypeSpace, TypeSpaceSettings, UnknownPolicy};
use color_eyre::eyre::{Context, Result, eyre};
use typify::typespace::settings::{ContainerType, TraitSpec};
use typify::{CrateVers, TypeSpace, TypeSpaceSettings, UnknownPolicy};

/// A CLI for the `typify` crate that converts JSON Schema files to Rust code.
#[derive(Args)]
Expand Down Expand Up @@ -139,21 +140,49 @@ impl std::str::FromStr for CrateSpec {
/// Generate Rust code for the selected JSON Schema.
pub fn convert(args: &CliArgs) -> Result<String> {
let content = std::fs::read_to_string(&args.input)
.wrap_err_with(|| format!("Failed to open input file: {}", &args.input.display()))?;
.wrap_err_with(|| format!("Failed to open input file: {}", args.input.display()))?;

let schema = serde_json::from_str::<schemars::schema::RootSchema>(&content)
.wrap_err("Failed to parse input file as JSON Schema")?;

let mut settings = TypeSpaceSettings::default();
settings.with_struct_builder(args.use_builder());

for derive in &args.additional_derives {
settings.with_derive(derive.clone());
}
// For JSON Schema, a map key is always string-like, so any type a path
// names can use the HashMap preset with the given type path. The parse is
// checked here so a bad path is a CLI error rather than a panic inside
// typespace.
let map_type = args
.map_type
.as_deref()
.map(|path| {
syn::parse_str::<syn::Type>(path)
.map(|_| ContainerType::hash_map().with_path(path))
.map_err(|err| eyre!("invalid map type {path:?}: {err}"))
})
.transpose()
.wrap_err("Invalid map type")?;

// A derive names a trait typespace models or a foreign one; typespace
// tells them apart. A bad name is a CLI error.
let derives = args
.additional_derives
.iter()
.map(|derive| TraitSpec::parse(derive).map_err(|err| eyre!("{err}")))
.collect::<Result<Vec<_>>>()
.wrap_err("Invalid derive")?;

for attr in &args.additional_attrs {
settings.with_attr(attr.clone());
}
let mut settings = TypeSpaceSettings::default();
settings.map_typespace_settings(|mut typespace| {
typespace = typespace.with_struct_builder(args.use_builder());
for derive in derives {
typespace = typespace.with_extra_required_trait(derive);
}
for attr in &args.additional_attrs {
typespace = typespace.with_attr(attr.clone());
}
if let Some(map_type) = map_type {
typespace = typespace.with_map_type(map_type);
}
typespace
});

for CrateSpec {
name,
Expand All @@ -164,14 +193,6 @@ pub fn convert(args: &CliArgs) -> Result<String> {
settings.with_crate(name, version.clone(), rename.as_ref());
}

if let Some(map_type) = &args.map_type {
let map_type = map_type
.parse::<MapType>()
.map_err(|msg| eyre!(msg))
.wrap_err("Invalid map type")?;
settings.with_map_type(map_type);
}

if let Some(unknown_crates) = &args.unknown_crates {
let unknown_crates = match unknown_crates.as_str() {
"generate" => UnknownPolicy::Generate,
Expand All @@ -193,7 +214,8 @@ pub fn convert(args: &CliArgs) -> Result<String> {
#![allow(clippy::clone_on_copy)]
";

let contents = format!("{intro}\n{}", type_space.to_stream());
let stream = type_space.to_stream().wrap_err("Type generation failed")?;
let contents = format!("{intro}\n{stream}");

let contents = rustfmt_wrapper::rustfmt(contents).wrap_err("Failed to format Rust code")?;

Expand Down
2 changes: 1 addition & 1 deletion cargo-typify/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2023 Oxide Computer Company

use cargo_typify::{convert, CliArgs};
use cargo_typify::{CliArgs, convert};
use clap::Parser;

use color_eyre::eyre::{Context, Result};
Expand Down
6 changes: 3 additions & 3 deletions cargo-typify/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn test_derive() {
input,
"--no-builder",
"--additional-derive",
"ExtraDerive",
"::extra::ExtraDerive",
"--output",
output_file.to_str().unwrap(),
])
Expand Down Expand Up @@ -141,9 +141,9 @@ fn test_multi_derive() {
input,
"--no-builder",
"--additional-derive",
"ExtraDerive",
"::extra::ExtraDerive",
"--additional-derive",
"AnotherDerive",
"::extra::AnotherDerive",
"--output",
output_file.to_str().unwrap(),
])
Expand Down
Loading
Loading