mirror of
https://github.com/openai/codex.git
synced 2026-06-01 19:02:59 +00:00
Support anyOf and enum in JsonSchema (#16875)
This brings us into better alignment with the JSON schema subset that is supported in <https://developers.openai.com/api/docs/guides/structured-outputs#supported-schemas>, and also allows us to render richer function signatures in code mode (e.g., anyOf{null, OtherObjectType})
This commit is contained in:
@@ -147,11 +147,11 @@ fn tool_search_payloads_roundtrip_as_tool_search_outputs() {
|
||||
description: String::new(),
|
||||
strict: false,
|
||||
defer_loading: Some(true),
|
||||
parameters: codex_tools::JsonSchema::Object {
|
||||
properties: Default::default(),
|
||||
required: None,
|
||||
additional_properties: None,
|
||||
},
|
||||
parameters: codex_tools::JsonSchema::object(
|
||||
/*properties*/ Default::default(),
|
||||
/*required*/ None,
|
||||
/*additional_properties*/ None,
|
||||
),
|
||||
output_schema: None,
|
||||
},
|
||||
)],
|
||||
|
||||
@@ -832,16 +832,15 @@ fn test_mcp_tool_property_missing_type_defaults_to_string() {
|
||||
tool.spec,
|
||||
ToolSpec::Function(ResponsesApiTool {
|
||||
name: "dash/search".to_string(),
|
||||
parameters: JsonSchema::Object {
|
||||
properties: BTreeMap::from([(
|
||||
parameters: JsonSchema::object(
|
||||
/*properties*/
|
||||
BTreeMap::from([(
|
||||
"query".to_string(),
|
||||
JsonSchema::String {
|
||||
description: Some("search query".to_string())
|
||||
}
|
||||
JsonSchema::string(Some("search query".to_string())),
|
||||
)]),
|
||||
required: None,
|
||||
additional_properties: None,
|
||||
},
|
||||
/*required*/ None,
|
||||
/*additional_properties*/ None
|
||||
),
|
||||
description: "Search docs".to_string(),
|
||||
strict: false,
|
||||
output_schema: Some(mcp_call_tool_result_output_schema(serde_json::json!({}))),
|
||||
@@ -851,7 +850,7 @@ fn test_mcp_tool_property_missing_type_defaults_to_string() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mcp_tool_integer_normalized_to_number() {
|
||||
fn test_mcp_tool_preserves_integer_schema() {
|
||||
let config = test_config();
|
||||
let model_info = construct_model_info_offline("gpt-5-codex", &config);
|
||||
let mut features = Features::with_defaults();
|
||||
@@ -890,14 +889,15 @@ fn test_mcp_tool_integer_normalized_to_number() {
|
||||
tool.spec,
|
||||
ToolSpec::Function(ResponsesApiTool {
|
||||
name: "dash/paginate".to_string(),
|
||||
parameters: JsonSchema::Object {
|
||||
properties: BTreeMap::from([(
|
||||
parameters: JsonSchema::object(
|
||||
/*properties*/
|
||||
BTreeMap::from([(
|
||||
"page".to_string(),
|
||||
JsonSchema::Number { description: None }
|
||||
JsonSchema::integer(/*description*/ None),
|
||||
)]),
|
||||
required: None,
|
||||
additional_properties: None,
|
||||
},
|
||||
/*required*/ None,
|
||||
/*additional_properties*/ None
|
||||
),
|
||||
description: "Pagination".to_string(),
|
||||
strict: false,
|
||||
output_schema: Some(mcp_call_tool_result_output_schema(serde_json::json!({}))),
|
||||
@@ -947,17 +947,18 @@ fn test_mcp_tool_array_without_items_gets_default_string_items() {
|
||||
tool.spec,
|
||||
ToolSpec::Function(ResponsesApiTool {
|
||||
name: "dash/tags".to_string(),
|
||||
parameters: JsonSchema::Object {
|
||||
properties: BTreeMap::from([(
|
||||
parameters: JsonSchema::object(
|
||||
/*properties*/
|
||||
BTreeMap::from([(
|
||||
"tags".to_string(),
|
||||
JsonSchema::Array {
|
||||
items: Box::new(JsonSchema::String { description: None }),
|
||||
description: None
|
||||
}
|
||||
JsonSchema::array(
|
||||
JsonSchema::string(/*description*/ None),
|
||||
/*description*/ None,
|
||||
),
|
||||
)]),
|
||||
required: None,
|
||||
additional_properties: None,
|
||||
},
|
||||
/*required*/ None,
|
||||
/*additional_properties*/ None
|
||||
),
|
||||
description: "Tags".to_string(),
|
||||
strict: false,
|
||||
output_schema: Some(mcp_call_tool_result_output_schema(serde_json::json!({}))),
|
||||
@@ -1008,14 +1009,21 @@ fn test_mcp_tool_anyof_defaults_to_string() {
|
||||
tool.spec,
|
||||
ToolSpec::Function(ResponsesApiTool {
|
||||
name: "dash/value".to_string(),
|
||||
parameters: JsonSchema::Object {
|
||||
properties: BTreeMap::from([(
|
||||
parameters: JsonSchema::object(
|
||||
/*properties*/
|
||||
BTreeMap::from([(
|
||||
"value".to_string(),
|
||||
JsonSchema::String { description: None }
|
||||
JsonSchema::any_of(
|
||||
vec![
|
||||
JsonSchema::string(/*description*/ None),
|
||||
JsonSchema::number(/*description*/ None),
|
||||
],
|
||||
/*description*/ None,
|
||||
),
|
||||
)]),
|
||||
required: None,
|
||||
additional_properties: None,
|
||||
},
|
||||
/*required*/ None,
|
||||
/*additional_properties*/ None
|
||||
),
|
||||
description: "AnyOf Value".to_string(),
|
||||
strict: false,
|
||||
output_schema: Some(mcp_call_tool_result_output_schema(serde_json::json!({}))),
|
||||
@@ -1082,50 +1090,51 @@ fn test_get_openai_tools_mcp_tools_with_additional_properties_schema() {
|
||||
tool.spec,
|
||||
ToolSpec::Function(ResponsesApiTool {
|
||||
name: "test_server/do_something_cool".to_string(),
|
||||
parameters: JsonSchema::Object {
|
||||
properties: BTreeMap::from([
|
||||
parameters: JsonSchema::object(
|
||||
/*properties*/
|
||||
BTreeMap::from([
|
||||
(
|
||||
"string_argument".to_string(),
|
||||
JsonSchema::String { description: None }
|
||||
JsonSchema::string(/*description*/ None),
|
||||
),
|
||||
(
|
||||
"number_argument".to_string(),
|
||||
JsonSchema::Number { description: None }
|
||||
JsonSchema::number(/*description*/ None),
|
||||
),
|
||||
(
|
||||
"object_argument".to_string(),
|
||||
JsonSchema::Object {
|
||||
properties: BTreeMap::from([
|
||||
JsonSchema::object(
|
||||
BTreeMap::from([
|
||||
(
|
||||
"string_property".to_string(),
|
||||
JsonSchema::String { description: None }
|
||||
JsonSchema::string(/*description*/ None),
|
||||
),
|
||||
(
|
||||
"number_property".to_string(),
|
||||
JsonSchema::Number { description: None }
|
||||
JsonSchema::number(/*description*/ None),
|
||||
),
|
||||
]),
|
||||
required: Some(vec![
|
||||
Some(vec![
|
||||
"string_property".to_string(),
|
||||
"number_property".to_string(),
|
||||
]),
|
||||
additional_properties: Some(
|
||||
JsonSchema::Object {
|
||||
properties: BTreeMap::from([(
|
||||
Some(
|
||||
JsonSchema::object(
|
||||
BTreeMap::from([(
|
||||
"addtl_prop".to_string(),
|
||||
JsonSchema::String { description: None }
|
||||
),]),
|
||||
required: Some(vec!["addtl_prop".to_string(),]),
|
||||
additional_properties: Some(false.into()),
|
||||
}
|
||||
.into()
|
||||
JsonSchema::string(/*description*/ None),
|
||||
)]),
|
||||
Some(vec!["addtl_prop".to_string()]),
|
||||
Some(false.into()),
|
||||
)
|
||||
.into(),
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
]),
|
||||
required: None,
|
||||
additional_properties: None,
|
||||
},
|
||||
/*required*/ None,
|
||||
/*additional_properties*/ None
|
||||
),
|
||||
description: "Do something cool".to_string(),
|
||||
strict: false,
|
||||
output_schema: Some(mcp_call_tool_result_output_schema(serde_json::json!({}))),
|
||||
|
||||
Reference in New Issue
Block a user