dynamo_protocols/schema.rs
1// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Schema-only placeholders for async-openai types that lack schema support.
5//!
6//! These placeholders let Dynamo-owned types derive `ToSchema` without
7//! requiring `async-openai/protocol-schema`. Field-level `schema(value_type = ...)`
8//! annotations select them for schema generation only; runtime field types and
9//! Serde behavior remain unchanged.
10//!
11//! Each placeholder preserves the upstream type's identity through an
12//! `x-dynamo-schema-import` marker, but does not describe its detailed shape.
13//! Consumers must resolve these markers against version-aligned upstream
14//! schemas before claiming complete coverage. This module does not perform
15//! that resolution or merge specifications.
16//!
17//! Once native upstream schema support is integrated, the corresponding
18//! placeholders and field overrides can be removed.
19
20macro_rules! imports {
21 ($($name:ident),* $(,)?) => {$(
22 pub struct $name;
23
24 impl utoipa::PartialSchema for $name {
25 fn schema() -> utoipa::openapi::RefOr<utoipa::openapi::Schema> {
26 use utoipa::openapi::schema::{ObjectBuilder, SchemaType, Type};
27 ObjectBuilder::new()
28 // These imported Rust types are non-Option. Excluding null
29 // prevents overlap with utoipa's Option<T> oneOf null arm.
30 .schema_type(SchemaType::Array(vec![
31 Type::Object, Type::Array, Type::String,
32 Type::Number, Type::Boolean,
33 ]))
34 .extensions(Some([(
35 "x-dynamo-schema-import",
36 serde_json::json!({"crate": "async-openai", "type": stringify!($name)}),
37 )].into_iter().collect()))
38 .into()
39 }
40 }
41
42 impl utoipa::ToSchema for $name {
43 fn name() -> std::borrow::Cow<'static, str> {
44 concat!("async_openai.", stringify!($name)).into()
45 }
46 }
47 )*};
48}
49
50imports!(
51 FunctionType,
52 ImageDetail,
53 TopLogprobs,
54 ChatCompletionRequestMessageContentPartText,
55 ChatCompletionRequestMessageContentPartAudio,
56 ChatCompletionRequestSystemMessageContent,
57 ChatCompletionRequestAssistantMessageContent,
58 ChatCompletionRequestAssistantMessageAudio,
59 ChatCompletionRequestDeveloperMessage,
60 ChatCompletionRequestFunctionMessage,
61 Role,
62 ChatCompletionResponseMessageAudio,
63 ResponseModalities,
64 PredictionContent,
65 ChatCompletionAudio,
66 ResponseFormat,
67 ServiceTier,
68 ChatCompletionFunctionCall,
69 ChatCompletionFunctions,
70 WebSearchOptions,
71 FinishReason,
72 CompletionUsage,
73 Prompt,
74);