Resolver error in reponse struct wth macro Schema
#7
-
|
Hello . Testing the framework, at the moment a like it. One Problem. I have the following response struct: use chrono::{DateTime, Utc};
use rustapi_rs::prelude::*;
use serde::{Deserialize, Serialize};
use sqlx::FromRow;
use uuid::Uuid;
#[derive(Debug, Clone, Serialize, FromRow, Schema)]
pub struct Tag {
pub id: Uuid,
pub tag: String,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}On the docs page i get the following error: I looked to the Utopia documentation, but don't found any solution. Can you help? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Hi! 👋 Thanks a lot for testing RustAPIreally glad to hear you like it so far. You’re absolutely right, and thanks for reporting this. What you’re seeing is a known limitation in the current OpenAPI / schema generation. 🔍 What’s happening?Types like:
are external types, and at the moment RustAPI does not automatically register them under Because of that, the spec ends up referencing: but those schemas are never defined, which leads to the resolver errors you’re seeing in the docs page. ✅ Current WorkaroundsOption 1: Map to OpenAPI primitives (recommended for now)OpenAPI represents these types as strings, so you can adjust your response struct like this: #[derive(Debug, Clone, Serialize, FromRow, Schema)]
pub struct Tag {
pub id: String, // UUID as string
pub tag: String,
pub created_at: String, // ISO 8601 date-time
pub updated_at: String,
}This matches the OpenAPI formats:
Option 2: Newtype wrappersYou can also wrap external types and derive #[derive(Serialize, Schema)]
pub struct ApiUuid(pub Uuid);
#[derive(Serialize, Schema)]
pub struct ApiDateTime(pub DateTime<Utc>);and then use 🛠 Roadmap / FixProper support for common external types (
I’ll open an issue for this so it’s tracked and fixed properly. Thanks again for the feedback — this kind of report really helps improve the framework. 🚀 |
Beta Was this translation helpful? Give feedback.
Hi! 👋
Thanks a lot for testing RustAPIreally glad to hear you like it so far.
You’re absolutely right, and thanks for reporting this. What you’re seeing is a known limitation in the current OpenAPI / schema generation.
🔍 What’s happening?
Types like:
chrono::DateTime<Utc>uuid::Uuidare external types, and at the moment RustAPI does not automatically register them under
components/schemaswhen generating the OpenAPI document.Because of that, the spec ends up referencing:
but those schemas are never defined, which leads to the resolver errors you’re seeing in the docs page.
✅ Current Workarounds
Option 1: Map to OpenAPI primitives …