| 1 | use crate::SchemaGenerator; |
| 2 | use crate::_alloc_prelude::*; |
| 3 | use crate::{json_schema, JsonSchema, Schema}; |
| 4 | use alloc::borrow::Cow; |
| 5 | use serde_json::json; |
| 6 | use std::ffi::{CStr, CString, OsStr, OsString}; |
| 7 | |
| 8 | impl JsonSchema for OsString { |
| 9 | fn schema_name() -> Cow<'static, str> { |
| 10 | "OsString".into() |
| 11 | } |
| 12 | |
| 13 | fn schema_id() -> Cow<'static, str> { |
| 14 | "std::ffi::OsString".into() |
| 15 | } |
| 16 | |
| 17 | fn json_schema(generator: &mut SchemaGenerator) -> Schema { |
| 18 | json_schema!({ |
| 19 | "oneOf": [ |
| 20 | { |
| 21 | "type": "object", |
| 22 | "properties": { |
| 23 | "Unix": <Vec<u8>>::json_schema(generator) |
| 24 | }, |
| 25 | "required": ["Unix"] |
| 26 | }, |
| 27 | { |
| 28 | "type": "object", |
| 29 | "properties": { |
| 30 | "Windows": <Vec<u16>>::json_schema(generator) |
| 31 | }, |
| 32 | "required": ["Windows"] |
| 33 | }, |
| 34 | ] |
| 35 | }) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | forward_impl!(OsStr => OsString); |
| 40 | |
| 41 | impl JsonSchema for CString { |
| 42 | fn schema_name() -> Cow<'static, str> { |
| 43 | "CString".into() |
| 44 | } |
| 45 | |
| 46 | fn schema_id() -> Cow<'static, str> { |
| 47 | "std::ffi::CString".into() |
| 48 | } |
| 49 | |
| 50 | fn json_schema(generator: &mut SchemaGenerator) -> Schema { |
| 51 | let ty = if generator.contract().is_deserialize() { |
| 52 | json!(["array", "string"]) |
| 53 | } else { |
| 54 | json!("array") |
| 55 | }; |
| 56 | |
| 57 | json_schema!({ |
| 58 | "type": ty, |
| 59 | "items": { |
| 60 | "type": "integer", |
| 61 | "minimum": 1, |
| 62 | "maximum": 255 |
| 63 | }, |
| 64 | }) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | forward_impl!(CStr => CString); |