Skip to content
Open
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
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ jobs:
strategy:
matrix:
rust:
- 1.74.0
- 1.79.0
- stable
- beta
- nightly
include:
- rust: 1.74.0
- rust: 1.79.0
allow_failure: false
- rust: stable
allow_failure: false
Expand All @@ -27,7 +27,7 @@ jobs:
steps:
- uses: actions/checkout@v5
- name: Downgrade packages for MSRV
if: matrix.rust == '1.74.0'
if: matrix.rust == '1.79.0'
run: |
cargo add --dev garde --git https://github.com/jprochazk/garde.git --rev be00ddddf8de14530ee890ccfdbaf0b13fb32852
cargo add --dev validator@0.19
Expand All @@ -40,15 +40,17 @@ jobs:
continue-on-error: ${{ matrix.allow_failure }}
working-directory: ./schemars
- name: Run tests
if: matrix.rust != '1.79.0'
run: cargo test --verbose --all-features --no-fail-fast
continue-on-error: ${{ matrix.allow_failure }}
working-directory: ./schemars
- name: Run derive tests
if: matrix.rust != '1.79.0'
run: cargo test --verbose --all-features --no-fail-fast
continue-on-error: ${{ matrix.allow_failure }}
working-directory: ./schemars_derive
- name: Check with latest dependency versions
if: matrix.rust != '1.74.0'
if: matrix.rust != '1.79.0'
run: |
cargo update
cargo check --all-features --verbose --example main
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Added

- Add monostate1 feature (https://github.com/GREsau/schemars/pull/508)

## [1.2.2] - 2026-07-27

- Update to syn 3 in schemars_derive
Expand Down
23 changes: 23 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Crates.io](https://img.shields.io/crates/v/schemars)](https://crates.io/crates/schemars)
[![API Docs](https://img.shields.io/docsrs/schemars/latest?label=API%20docs)](https://docs.rs/schemars/latest)
[![Usage Docs](https://img.shields.io/badge/Usage%20docs-graham.cool%2Fschemars-blue)](https://graham.cool/schemars)
[![MSRV 1.74+](https://img.shields.io/badge/msrv-1.74-blue)](https://blog.rust-lang.org/2023/11/16/Rust-1.74.0/)
[![MSRV 1.79+](https://img.shields.io/badge/msrv-1.79-blue)](https://blog.rust-lang.org/2024/06/13/Rust-1.79.0/)

Generate JSON Schema documents from Rust code

Expand Down
5 changes: 3 additions & 2 deletions schemars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ license = "MIT"
readme = "README.md"
keywords = ["rust", "json-schema", "serde"]
categories = ["encoding", "no-std"]
rust-version = "1.74"
rust-version = "1.79"

[dependencies]
schemars_derive = { version = "=1.2.2", optional = true, path = "../schemars_derive" }
serde = { version = "1.0.194", default-features = false, features = ["alloc"] }
serde = { version = "1.0.222", default-features = false, features = ["alloc"] }
serde_json = { version = "1.0.127", default-features = false, features = ["alloc"] }
dyn-clone = "1.0.17"
ref-cast = "1.0.22"
Expand All @@ -27,6 +27,7 @@ chrono04 = { version = "0.4.39", default-features = false, optional = true, pack
either1 = { version = "1.3", default-features = false, optional = true, package = "either" }
indexmap2 = { version = "2.2.3", default-features = false, optional = true, package = "indexmap" }
jiff02 = { version = "0.2", default-features = false, optional = true, package = "jiff" }
monostate1 = { version = "1.0", default-features = false, optional = true, package = "monostate" }
rust_decimal1 = { version = "1.13", default-features = false, optional = true, package = "rust_decimal" }
semver1 = { version = "1.0.9", default-features = false, optional = true, package = "semver" }
smallvec1 = { version = "1.0", default-features = false, optional = true, package = "smallvec" }
Expand Down
3 changes: 3 additions & 0 deletions schemars/src/json_schema_impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ mod indexmap2;
#[cfg(feature = "jiff02")]
mod jiff02;

#[cfg(feature = "monostate1")]
mod monostate1;

#[cfg(feature = "semver1")]
mod semver1;

Expand Down
57 changes: 57 additions & 0 deletions schemars/src/json_schema_impls/monostate1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use crate::*;
use std::{borrow::Cow, format};

macro_rules! impls {
($($ident:ident<const V: $ty:ident>),* $(,)?) => {$(
impl<const V: $ty> JsonSchema for monostate1::$ident<V> {
fn schema_name() -> Cow<'static, str> {
Cow::Owned(format!("{}<{}>", stringify!($ident), V))
}
fn json_schema(_: &mut SchemaGenerator) -> Schema {
json_schema!({
"const": V,
})
}
fn inline_schema() -> bool {
true
}
fn schema_id() -> Cow<'static, str> {
Cow::Owned(format!("monostate::{}", Self::schema_name()))
}
}
)*};
}

impls! {
MustBeBool<const V: bool>,
MustBeChar<const V: char>,

MustBeI8<const V: i8>,
MustBeI16<const V: i16>,
MustBeI32<const V: i32>,
MustBeI64<const V: i64>,
MustBeI128<const V: i128>,

MustBeU8<const V: u8>,
MustBeU16<const V: u16>,
MustBeU32<const V: u32>,
MustBeU64<const V: u64>,
MustBeU128<const V: u128>,
}

impl<V: monostate1::ConstStr> JsonSchema for monostate1::MustBeStr<V> {
fn schema_name() -> Cow<'static, str> {
Cow::Owned(format!("{}<{}>", stringify!($ident), V::VALUE))
}
fn json_schema(_: &mut SchemaGenerator) -> Schema {
json_schema!({
"const": V::VALUE,
})
}
fn inline_schema() -> bool {
true
}
fn schema_id() -> Cow<'static, str> {
Cow::Owned(format!("monostate::{}", Self::schema_name()))
}
}
2 changes: 1 addition & 1 deletion schemars_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = "MIT"
readme = "README.md"
keywords = ["rust", "json-schema", "serde"]
categories = ["encoding", "no-std"]
rust-version = "1.74"
rust-version = "1.79"

[lib]
proc-macro = true
Expand Down