Skip to content

Commit 0bc450f

Browse files
authored
Fix ClientRegistry, BamlPdf and BamlVideo in openapi generator (#2170)
<!-- ELLIPSIS_HIDDEN --> > [!IMPORTANT] > Fix OpenAPI generator by adding `BamlPdf` and `BamlVideo` types, correcting `ClientRegistry` reference, and updating `AnyValue` handling. > > - **Behavior**: > - Add `BamlPdf` and `BamlVideo` types as unions in `builtin_schemas.rs`. > - Correct reference from `ClientRegistry` to `ClientProperty` in `builtin_schemas.rs`. > - Update `AnyValue` type in `type.rs` to include `type` and `additionalProperties` fields. > - Modify `openapi.yaml` to reflect changes in `AnyValue` handling. > - **Misc**: > - Add `UV_PYTHON` environment variable in `flake.nix`. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup> for cd1e8d2. You can [customize](https://app.ellipsis.dev/BoundaryML/settings/summaries) this summary. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
1 parent ec170db commit 0bc450f

4 files changed

Lines changed: 156 additions & 19 deletions

File tree

engine/generators/languages/openapi/src/builtin_schemas.rs

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,86 @@ pub fn builtin_schemas() -> IndexMap<TypeName, TypeOpenApi> {
8282
meta: OpenApiMeta::default(),
8383
},
8484
),
85+
(
86+
TypeName("BamlPdf".to_string()),
87+
TypeOpenApi::Union {
88+
one_of: vec![
89+
TypeOpenApi::Inline {
90+
r#type: TypePrimitive::Object {
91+
properties: IndexMap::from_iter(vec![
92+
("base64".to_string(), type_string()),
93+
("media_type".to_string(), type_string()),
94+
]),
95+
required: IndexSet::from_iter(vec!["base64".to_string()]),
96+
additional_properties: AdditionalProperties::Closed,
97+
},
98+
meta: OpenApiMeta {
99+
title: Some("BamlPdfBase64".to_string()),
100+
..OpenApiMeta::default()
101+
},
102+
},
103+
TypeOpenApi::Inline {
104+
r#type: TypePrimitive::Object {
105+
properties: IndexMap::from_iter(vec![
106+
("url".to_string(), type_string()),
107+
("media_type".to_string(), type_string()),
108+
]),
109+
required: IndexSet::from_iter(vec!["url".to_string()]),
110+
additional_properties: AdditionalProperties::Closed,
111+
},
112+
meta: OpenApiMeta {
113+
title: Some("BamlPdfUrl".to_string()),
114+
..OpenApiMeta::default()
115+
},
116+
},
117+
],
118+
meta: OpenApiMeta::default(),
119+
},
120+
),
121+
(
122+
TypeName("BamlVideo".to_string()),
123+
TypeOpenApi::Union {
124+
one_of: vec![
125+
TypeOpenApi::Inline {
126+
r#type: TypePrimitive::Object {
127+
properties: IndexMap::from_iter(vec![
128+
("base64".to_string(), type_string()),
129+
("media_type".to_string(), type_string()),
130+
]),
131+
required: IndexSet::from_iter(vec!["base64".to_string()]),
132+
additional_properties: AdditionalProperties::Closed,
133+
},
134+
meta: OpenApiMeta {
135+
title: Some("BamlVideoBase64".to_string()),
136+
..OpenApiMeta::default()
137+
},
138+
},
139+
TypeOpenApi::Inline {
140+
r#type: TypePrimitive::Object {
141+
properties: IndexMap::from_iter(vec![
142+
("url".to_string(), type_string()),
143+
("media_type".to_string(), type_string()),
144+
]),
145+
required: IndexSet::from_iter(vec!["url".to_string()]),
146+
additional_properties: AdditionalProperties::Closed,
147+
},
148+
meta: OpenApiMeta {
149+
title: Some("BamlVideoUrl".to_string()),
150+
..OpenApiMeta::default()
151+
},
152+
},
153+
],
154+
meta: OpenApiMeta::default(),
155+
},
156+
),
85157
(
86158
TypeName("BamlOptions".to_string()),
87159
TypeOpenApi::Inline {
88160
r#type: TypePrimitive::Object {
89161
properties: IndexMap::from_iter(vec![(
90162
"client_registry".to_string(),
91163
TypeOpenApi::Ref {
92-
r#ref: "#/components/schemas/ClientRegistry".to_string(),
164+
r#ref: "#/components/schemas/ClientProperty".to_string(),
93165
meta: OpenApiMeta::default(),
94166
},
95167
)]),

engine/generators/languages/openapi/src/type.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ pub enum TypeOpenApi {
3838
AnyValue {
3939
#[serde(flatten)]
4040
meta: OpenApiMeta,
41-
#[serde(rename = "AnyValue")]
42-
any_value: IndexMap<String, TypeOpenApi>,
41+
#[serde(rename = "type")]
42+
type_: String,
43+
#[serde(rename = "additionalProperties")]
44+
additional_properties: bool,
4345
},
4446
}
4547

@@ -256,8 +258,9 @@ pub fn convert_ir_type(ir: &IntermediateRepr, ty: &TypeNonStreaming) -> TypeOpen
256258
},
257259
TypeNonStreaming::Tuple(..) => panic!("Tuple types are not supported in code generation"),
258260
TypeNonStreaming::RecursiveTypeAlias { .. } => TypeOpenApi::AnyValue {
259-
any_value: IndexMap::new(),
261+
type_: "object".to_string(),
260262
meta: meta_copy,
263+
additional_properties: true,
261264
},
262265
};
263266

@@ -594,8 +597,13 @@ mod tests {
594597
let openapi_recursive = convert_ir_type(&ir, &recursive_type);
595598

596599
match openapi_recursive {
597-
TypeOpenApi::AnyValue { any_value, .. } => {
598-
assert!(any_value.is_empty());
600+
TypeOpenApi::AnyValue {
601+
type_,
602+
additional_properties,
603+
..
604+
} => {
605+
assert_eq!(type_, "object");
606+
assert!(additional_properties);
599607
}
600608
_ => panic!("Expected AnyValue type for recursive type alias"),
601609
}

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@
328328
PATH="${clang}/bin:$PATH";
329329
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc;
330330
LIBCLANG_PATH = pkgs.libclang.lib + "/lib/";
331+
UV_PYTHON = "${pythonEnv}/bin/python3";
331332
BINDGEN_EXTRA_CLANG_ARGS = if pkgs.stdenv.isDarwin then
332333
"" # Rely on default includes provided by stdenv.cc + libclang
333334
else

integ-tests/openapi/baml_client/openapi.yaml

Lines changed: 69 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)