Skip to content

Commit

Permalink
fix(Rust bindings): Use Boolean for consistency with schema.org
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome committed Jun 4, 2021
1 parent fa939cd commit c754d33
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions rust/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub use std::sync::Arc;
#[serde(untagged)]
pub enum Primitive {
Null,
Bool(Bool),
Boolean(Boolean),
Integer(Integer),
Number(Number),
String(String),
Expand All @@ -19,7 +19,7 @@ pub enum Primitive {
}

/// A boolean value
pub type Bool = bool;
pub type Boolean = bool;

/// An integer value
///
Expand Down
20 changes: 10 additions & 10 deletions rust/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,7 @@ pub struct ArrayValidator {
pub min_items: Option<Number>,

/// A flag to indicate that each value in the array should be unique.
pub unique_items: Option<Bool>,
pub unique_items: Option<Boolean>,
}
impl_type!(ArrayValidator);

Expand Down Expand Up @@ -2124,7 +2124,7 @@ pub struct ListItem {
pub images: Option<Vec<ThingImages>>,

/// A flag to indicate if this list item is checked.
pub is_checked: Option<Bool>,
pub is_checked: Option<Boolean>,

/// The item represented by this list item.
#[serde(skip)]
Expand Down Expand Up @@ -2456,7 +2456,7 @@ pub struct Variable {
pub id: Option<String>,

/// Whether or not a property is mutable. Default is false.
pub is_readonly: Option<Bool>,
pub is_readonly: Option<Boolean>,

/// Metadata associated with this item.
pub meta: Option<Object>,
Expand Down Expand Up @@ -2491,16 +2491,16 @@ pub struct Parameter {
pub id: Option<String>,

/// Indicates that this parameter is variadic and can accept multiple named arguments.
pub is_extensible: Option<Bool>,
pub is_extensible: Option<Boolean>,

/// Whether or not a property is mutable. Default is false.
pub is_readonly: Option<Bool>,
pub is_readonly: Option<Boolean>,

/// Is this parameter required, if not it should have a default or default is assumed to be null.
pub is_required: Option<Bool>,
pub is_required: Option<Boolean>,

/// Indicates that this parameter is variadic and can accept multiple arguments.
pub is_variadic: Option<Bool>,
pub is_variadic: Option<Boolean>,

/// Metadata associated with this item.
pub meta: Option<Object>,
Expand Down Expand Up @@ -4419,7 +4419,7 @@ pub enum ProductLogo {
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PropertyValueValue {
Bool(Bool),
Boolean(Boolean),
Integer(Integer),
Number(Number),
String(String),
Expand Down Expand Up @@ -4934,7 +4934,7 @@ pub enum InlineContent {
Superscript(Superscript),
VideoObject(VideoObject),
Null,
Bool(Bool),
Boolean(Boolean),
Integer(Integer),
Number(Number),
Array(Array),
Expand Down Expand Up @@ -5058,7 +5058,7 @@ pub enum Node {
VideoObject(VideoObject),
VolumeMount(VolumeMount),
Null,
Bool(Bool),
Boolean(Boolean),
Integer(Integer),
Number(Number),
String(String),
Expand Down
16 changes: 8 additions & 8 deletions rust/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ fn primitives_deserialize() -> Result<()> {
assert!(matches!(null, Primitive::Null));

let bool: Primitive = serde_json::from_str("true")?;
assert!(matches!(bool, Primitive::Bool(_)));
assert!(matches!(bool, Primitive::Boolean(_)));

let bool: Primitive = serde_json::from_str("false")?;
assert!(matches!(bool, Primitive::Bool(_)));
assert!(matches!(bool, Primitive::Boolean(_)));

let integer: Primitive = serde_json::from_str("42")?;
assert!(matches!(integer, Primitive::Integer(_)));
Expand All @@ -32,7 +32,7 @@ fn primitives_deserialize() -> Result<()> {
let array: Primitive = serde_json::from_str(r#"[null, false, 42, 3.14, "string"]"#)?;
if let Primitive::Array(array) = array {
assert!(matches!(array[0], Primitive::Null));
assert!(matches!(array[1], Primitive::Bool(false)));
assert!(matches!(array[1], Primitive::Boolean(false)));
assert!(matches!(array[2], Primitive::Integer(_)));
assert!(matches!(array[3], Primitive::Number(_)));
assert!(matches!(array[4], Primitive::String(_)));
Expand All @@ -51,7 +51,7 @@ fn primitives_deserialize() -> Result<()> {
)?;
if let Primitive::Object(object) = object {
assert!(matches!(object["a"], Primitive::Null));
assert!(matches!(object["b"], Primitive::Bool(false)));
assert!(matches!(object["b"], Primitive::Boolean(false)));
assert!(matches!(object["c"], Primitive::Integer(_)));
assert!(matches!(object["d"], Primitive::Number(_)));
assert!(matches!(object["e"], Primitive::String(_)));
Expand All @@ -67,10 +67,10 @@ fn primitives_serialize() -> Result<()> {
let null = Primitive::Null;
assert_eq!(serde_json::to_string(&null)?, "null");

let bool = Primitive::Bool(true);
let bool = Primitive::Boolean(true);
assert_eq!(serde_json::to_string(&bool)?, "true");

let bool = Primitive::Bool(false);
let bool = Primitive::Boolean(false);
assert_eq!(serde_json::to_string(&bool)?, "false");

let integer = Primitive::Integer(42);
Expand All @@ -84,7 +84,7 @@ fn primitives_serialize() -> Result<()> {

let array = Primitive::Array(vec![
Primitive::Null,
Primitive::Bool(false),
Primitive::Boolean(false),
Primitive::Integer(42),
Primitive::Number(3.14),
Primitive::String("string".to_string()),
Expand All @@ -96,7 +96,7 @@ fn primitives_serialize() -> Result<()> {

let object = Primitive::Object(btreemap! {
"a".to_string() => Primitive::Null,
"b".to_string() => Primitive::Bool(false),
"b".to_string() => Primitive::Boolean(false),
"c".to_string() => Primitive::Integer(42),
"d".to_string() => Primitive::Number(3.14),
"e".to_string() => Primitive::String("string".to_string())
Expand Down
2 changes: 1 addition & 1 deletion ts/bindings/rust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ function schemaToType(schema: JsonSchema, context: Context): string {
if (schema.enum !== undefined) return enumToEnum(schema.enum, context)

if (type === 'null') return 'Null'
if (type === 'boolean') return 'Bool'
if (type === 'boolean') return 'Boolean'
if (type === 'number') return 'Number'
if (type === 'integer') return 'Integer'
if (type === 'string') return 'String'
Expand Down

0 comments on commit c754d33

Please sign in to comment.