Skip to content

Commit 145e887

Browse files
Use AnyValue: {} for the any type in OpenAPI (#1773)
Recursive type aliases [are broken](https://discord.com/channels/1119368998161752075/1359498024790917231) in OpenAPI. Use the [Any Type](https://swagger.io/docs/specification/v3_0/data-models/data-types/#any-type) to fix them. <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Replaces `anyOf` with `AnyValue` in OpenAPI to fix recursive type alias handling, updating both code generation and integration tests. > > - **Behavior**: > - Replaces `anyOf: []` with `AnyValue: {}` in `openapi.rs` and `openapi.yaml` to handle recursive type aliases in OpenAPI. > - Updates `TypeSpec::AnyValue` in `openapi.rs` to use `HashMap` for `any_value`. > - **Code Changes**: > - Modifies `ToTypeReferenceInTypeDefinition` for `FieldType::RecursiveTypeAlias` in `openapi.rs` to use `AnyValue`. > - Updates `TypeSpec` enum in `openapi.rs` to include `AnyValue` with `HashMap`. > - **Tests**: > - Updates `openapi.yaml` in `baml_client` integration tests to reflect changes from `anyOf` to `AnyValue` for various paths. > > <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 8da98aa. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
1 parent bd449f0 commit 145e887

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

engine/language_client_codegen/src/openapi.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::path::PathBuf;
1+
use std::{collections::HashMap, path::PathBuf};
22

33
use anyhow::{Context, Result};
44
use baml_types::{BamlMediaType, FieldType, LiteralValue, TypeValue};
@@ -558,7 +558,9 @@ impl<'ir> ToTypeReferenceInTypeDefinition<'ir> for FieldType {
558558
r#const: None,
559559
nullable: false,
560560
},
561-
type_spec: TypeSpec::AnyValue { any_of: vec![] },
561+
type_spec: TypeSpec::AnyValue {
562+
any_value: HashMap::new(),
563+
},
562564
},
563565
FieldType::Literal(v) => TypeSpecWithMeta {
564566
meta: TypeMetadata {
@@ -682,7 +684,9 @@ impl<'ir> ToTypeReferenceInTypeDefinition<'ir> for FieldType {
682684
}
683685
None => base.to_type_spec(_ir)?,
684686
},
685-
FieldType::Arrow(_) => todo!("Arrow types should not be used in generated type definitions"),
687+
FieldType::Arrow(_) => {
688+
todo!("Arrow types should not be used in generated type definitions")
689+
}
686690
})
687691
}
688692
}
@@ -732,9 +736,11 @@ enum TypeSpec {
732736
#[serde(rename = "oneOf", alias = "oneOf")]
733737
one_of: Vec<TypeSpecWithMeta>,
734738
},
739+
// Any Type in OpenAPI version 3.
740+
// https://swagger.io/docs/specification/v3_0/data-models/data-types/#any-type
735741
AnyValue {
736-
#[serde(rename = "anyOf", alias = "anyOf")]
737-
any_of: Vec<TypeSpecWithMeta>,
742+
#[serde(rename = "AnyValue", alias = "AnyValue")]
743+
any_value: HashMap<String, TypeSpecWithMeta>,
738744
},
739745
}
740746

integ-tests/openapi/baml_client/openapi.yaml

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

0 commit comments

Comments
 (0)