Set "required" schema attribute
This commit is contained in:
parent
6b64cedb91
commit
998e6c9f0f
7 changed files with 68 additions and 21 deletions
|
@ -3,6 +3,7 @@ use crate::{MakeSchema, MakeSchemaError, Result};
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use std::collections::BTreeMap as Map;
|
||||
use std::collections::BTreeSet as Set;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, MakeSchema)]
|
||||
#[serde(untagged)]
|
||||
|
@ -30,13 +31,13 @@ impl From<SchemaRef> for Schema {
|
|||
}
|
||||
}
|
||||
|
||||
fn extend<A, E: Extend<A>>(mut a: E, b: impl IntoIterator<Item = A>) -> E {
|
||||
a.extend(b);
|
||||
a
|
||||
}
|
||||
|
||||
impl Schema {
|
||||
pub fn flatten(self, other: Self) -> Result {
|
||||
fn extend<A, E: Extend<A>>(mut a: E, b: impl IntoIterator<Item = A>) -> E {
|
||||
a.extend(b);
|
||||
a
|
||||
}
|
||||
|
||||
let s1 = self.ensure_flattenable()?;
|
||||
let s2 = other.ensure_flattenable()?;
|
||||
Ok(Schema::Object(SchemaObject {
|
||||
|
@ -112,8 +113,8 @@ pub struct SchemaObject {
|
|||
pub items: Option<SingleOrVec<Schema>>,
|
||||
#[serde(skip_serializing_if = "Map::is_empty")]
|
||||
pub properties: Map<String, Schema>,
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
pub required: Vec<String>,
|
||||
#[serde(skip_serializing_if = "Set::is_empty")]
|
||||
pub required: Set<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub all_of: Option<Vec<Schema>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
|
|
@ -12,5 +12,10 @@
|
|||
"new_name_2": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"camelCase",
|
||||
"new_name_1",
|
||||
"new_name_2"
|
||||
]
|
||||
}
|
|
@ -22,6 +22,13 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"inner",
|
||||
"t",
|
||||
"u",
|
||||
"v",
|
||||
"w"
|
||||
],
|
||||
"definitions": {
|
||||
"another-new-name": {
|
||||
"type": "object"
|
||||
|
|
|
@ -22,6 +22,13 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"inner",
|
||||
"t",
|
||||
"u",
|
||||
"v",
|
||||
"w"
|
||||
],
|
||||
"definitions": {
|
||||
"MySimpleStruct": {
|
||||
"type": "object"
|
||||
|
|
|
@ -151,7 +151,10 @@
|
|||
"$ref": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"$ref"
|
||||
]
|
||||
},
|
||||
"SingleOrVec_For_InstanceType": {
|
||||
"anyOf": [
|
||||
|
|
|
@ -187,7 +187,10 @@
|
|||
"$ref": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"$ref"
|
||||
]
|
||||
},
|
||||
"SingleOrVec_For_InstanceType": {
|
||||
"anyOf": [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue