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
1 change: 1 addition & 0 deletions .changepacks/changepack_log_FHWJJPPxJTLxVPGXE7Tf3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"changes":{"Cargo.toml":"Patch"},"note":"Fix schema_type has_one","date":"2026-04-01T14:13:09.811093500Z"}
10 changes: 7 additions & 3 deletions crates/vespera_macro/src/schema_macro/type_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ pub const PRIMITIVE_TYPE_NAMES: &[&str] = &[
"f64", "bool", "String", "Decimal",
];

/// Normalize a `TokenStream` or `Type` to a compact string by removing spaces.
/// Normalize a `TokenStream` or `Type` to a compact string by removing all whitespace.
///
/// This replaces the common `.to_string().replace(' ', "")` pattern used throughout
/// the codebase to produce deterministic path strings for comparison and cache keys.
///
/// Removes spaces, newlines, and carriage returns — `proc_macro2`'s `Display` impl
/// may insert newlines when token sequences exceed an internal line-length threshold,
/// which would break substring checks like `contains("HasOne<")`.
#[inline]
pub fn normalize_token_str(displayable: &impl std::fmt::Display) -> String {
let s = displayable.to_string();
if s.contains(' ') {
s.replace(' ', "")
if s.contains(|c: char| c.is_ascii_whitespace()) {
s.replace(|c: char| c.is_ascii_whitespace(), "")
} else {
s
}
Expand Down
12 changes: 12 additions & 0 deletions examples/axum-example/models/single.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://raw.githubusercontent.com/dev-five-git/vespertide/refs/heads/main/schemas/model.schema.json",
"name": "single",
"columns": [
{
"name": "username",
"type": { "kind": "varchar", "length": 32 },
"nullable": false,
"primary_key": true
}
]
}
17 changes: 17 additions & 0 deletions examples/axum-example/models/single_rel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://raw.githubusercontent.com/dev-five-git/vespertide/refs/heads/main/schemas/model.schema.json",
"name": "single_rel",
"columns": [
{
"name": "username",
"type": { "kind": "varchar", "length": 32 },
"nullable": false,
"primary_key": true,
"foreign_key": {
"ref_table": "single",
"ref_columns": ["username"],
"on_delete": "cascade"
}
}
]
}
54 changes: 54 additions & 0 deletions examples/axum-example/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3467,6 +3467,60 @@
"createdAt"
]
},
"SingleRelSchema": {
"type": "object",
"properties": {
"single": {
"$ref": "#/components/schemas/SingleRelSchema_Single"
},
"username": {
"type": "string",
"default": ""
}
},
"required": [
"username",
"single"
]
},
"SingleRelSchema_Single": {
"type": "object",
"properties": {
"username": {
"type": "string"
}
},
"required": [
"username"
]
},
"SingleSchema": {
"type": "object",
"properties": {
"singleRel": {
"$ref": "#/components/schemas/SingleSchema_SingleRel",
"nullable": true
},
"username": {
"type": "string",
"default": ""
}
},
"required": [
"username"
]
},
"SingleSchema_SingleRel": {
"type": "object",
"properties": {
"username": {
"type": "string"
}
},
"required": [
"username"
]
},
"SkipResponse": {
"type": "object",
"properties": {
Expand Down
2 changes: 2 additions & 0 deletions examples/axum-example/src/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub mod config;
pub mod memo;
pub mod memo_comment;
pub mod single;
pub mod single_rel;
pub mod user;
pub mod uuid_item;
15 changes: 15 additions & 0 deletions examples/axum-example/src/models/single.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![allow(dead_code)]
use sea_orm::entity::prelude::*;

#[sea_orm::model]
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "single")]
pub struct Model {
#[sea_orm(primary_key)]
pub username: String,
#[sea_orm(has_one)]
pub single_rel: HasOne<crate::models::single_rel::Entity>,
}

vespera::schema_type!(Schema from Model, name = "SingleSchema");
impl ActiveModelBehavior for ActiveModel {}
15 changes: 15 additions & 0 deletions examples/axum-example/src/models/single_rel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![allow(dead_code)]
use sea_orm::entity::prelude::*;

#[sea_orm::model]
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "single_rel")]
pub struct Model {
#[sea_orm(primary_key)]
pub username: String,
#[sea_orm(belongs_to, from = "username", to = "username")]
pub single: HasOne<crate::models::single::Entity>,
}

vespera::schema_type!(Schema from Model, name = "SingleRelSchema");
impl ActiveModelBehavior for ActiveModel {}
Original file line number Diff line number Diff line change
Expand Up @@ -3471,6 +3471,60 @@ expression: "std::fs::read_to_string(\"openapi.json\").unwrap()"
"createdAt"
]
},
"SingleRelSchema": {
"type": "object",
"properties": {
"single": {
"$ref": "#/components/schemas/SingleRelSchema_Single"
},
"username": {
"type": "string",
"default": ""
}
},
"required": [
"username",
"single"
]
},
"SingleRelSchema_Single": {
"type": "object",
"properties": {
"username": {
"type": "string"
}
},
"required": [
"username"
]
},
"SingleSchema": {
"type": "object",
"properties": {
"singleRel": {
"$ref": "#/components/schemas/SingleSchema_SingleRel",
"nullable": true
},
"username": {
"type": "string",
"default": ""
}
},
"required": [
"username"
]
},
"SingleSchema_SingleRel": {
"type": "object",
"properties": {
"username": {
"type": "string"
}
},
"required": [
"username"
]
},
"SkipResponse": {
"type": "object",
"properties": {
Expand Down
54 changes: 54 additions & 0 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3467,6 +3467,60 @@
"createdAt"
]
},
"SingleRelSchema": {
"type": "object",
"properties": {
"single": {
"$ref": "#/components/schemas/SingleRelSchema_Single"
},
"username": {
"type": "string",
"default": ""
}
},
"required": [
"username",
"single"
]
},
"SingleRelSchema_Single": {
"type": "object",
"properties": {
"username": {
"type": "string"
}
},
"required": [
"username"
]
},
"SingleSchema": {
"type": "object",
"properties": {
"singleRel": {
"$ref": "#/components/schemas/SingleSchema_SingleRel",
"nullable": true
},
"username": {
"type": "string",
"default": ""
}
},
"required": [
"username"
]
},
"SingleSchema_SingleRel": {
"type": "object",
"properties": {
"username": {
"type": "string"
}
},
"required": [
"username"
]
},
"SkipResponse": {
"type": "object",
"properties": {
Expand Down