Skip to main content

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    FunctionObject,
55    ChatCompletionRequestMessageContentPartText,
56    ChatCompletionRequestMessageContentPartAudio,
57    ChatCompletionRequestSystemMessageContent,
58    ChatCompletionRequestAssistantMessageContent,
59    ChatCompletionRequestAssistantMessageAudio,
60    ChatCompletionRequestDeveloperMessage,
61    ChatCompletionRequestFunctionMessage,
62    Role,
63    ChatCompletionResponseMessageAudio,
64    ResponseModalities,
65    PredictionContent,
66    ChatCompletionAudio,
67    ResponseFormat,
68    ServiceTier,
69    ChatCompletionFunctionCall,
70    ChatCompletionFunctions,
71    WebSearchOptions,
72    FinishReason,
73    CompletionUsage,
74    Prompt,
75);