fix(schema): remove AddNullable from draft2020_12 settings (#664)
* fix(schema): remove AddNullable from draft2020_12 settings
The `nullable` keyword is an OpenAPI 3.0 extension, not part of
JSON Schema 2020-12. Using AddNullable with draft2020_12 settings
causes validation failures with strict JSON Schema validators.
JSON Schema 2020-12 represents nullable types using:
- {"type": ["string", "null"]} (type array with null)
- {"anyOf": [{"type": "string"}, {"type": "null"}]}
Fixes #663
* test(schema): update complex schema nullable expectation
* test(schema): align macro optional-field expectations with draft2020
This commit is contained in:
parent
3df4c5bf5f
commit
92b1459647
1 changed files with 24 additions and 21 deletions
|
|
@ -23,8 +23,10 @@ pub fn schema_for_type<T: JsonSchema + std::any::Any>() -> Arc<JsonObject> {
|
|||
} else {
|
||||
// explicitly to align json schema version to official specifications.
|
||||
// refer to https://github.com/modelcontextprotocol/modelcontextprotocol/pull/655 for details.
|
||||
let mut settings = SchemaSettings::draft2020_12();
|
||||
settings.transforms = vec![Box::new(schemars::transform::AddNullable::default())];
|
||||
let settings = SchemaSettings::draft2020_12();
|
||||
// Note: AddNullable is intentionally NOT used here because the `nullable` keyword
|
||||
// is an OpenAPI 3.0 extension, not part of JSON Schema 2020-12. Using it would
|
||||
// cause validation failures with strict JSON Schema validators.
|
||||
let generator = settings.into_generator();
|
||||
let schema = generator.into_root_schema_for::<T>();
|
||||
let object = serde_json::to_value(schema).expect("failed to serialize schema");
|
||||
|
|
|
|||
Loading…
Reference in a new issue