Add default, deprecated, readOnly, writeOnly properties
This commit is contained in:
parent
f38f58d1e8
commit
68ddfa310f
4 changed files with 68 additions and 22 deletions
|
@ -40,10 +40,21 @@ impl_merge!(SchemaObject {
|
|||
or: format const_value reference,
|
||||
});
|
||||
|
||||
impl_merge!(Metadata {
|
||||
merge: definitions,
|
||||
or: schema id title description,
|
||||
});
|
||||
impl Merge for Metadata {
|
||||
fn merge(self, other: Self) -> Self {
|
||||
Metadata {
|
||||
definitions: self.definitions.merge(other.definitions),
|
||||
schema: self.schema.or(other.schema),
|
||||
id: self.id.or(other.id),
|
||||
title: self.title.or(other.title),
|
||||
description: self.description.or(other.description),
|
||||
default: self.default.or(other.default),
|
||||
deprecated: self.deprecated || other.deprecated,
|
||||
read_only: self.read_only || other.read_only,
|
||||
write_only: self.write_only || other.write_only,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_merge!(SubschemaValidation {
|
||||
or: all_of any_of one_of not if_schema then_schema else_schema,
|
||||
|
|
|
@ -126,6 +126,19 @@ pub struct Metadata {
|
|||
pub description: Option<String>,
|
||||
#[serde(alias = "$defs", skip_serializing_if = "Map::is_empty")]
|
||||
pub definitions: Map<String, Schema>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub default: Option<Value>,
|
||||
#[serde(skip_serializing_if = "is_false")]
|
||||
pub deprecated: bool,
|
||||
#[serde(skip_serializing_if = "is_false")]
|
||||
pub read_only: bool,
|
||||
#[serde(skip_serializing_if = "is_false")]
|
||||
pub write_only: bool,
|
||||
}
|
||||
|
||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
||||
fn is_false(b: &bool) -> bool {
|
||||
!b
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema)]
|
||||
|
|
|
@ -1,14 +1,6 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Schema",
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/SchemaObject"
|
||||
}
|
||||
],
|
||||
"definitions": {
|
||||
"InstanceType": {
|
||||
"enum": [
|
||||
|
@ -96,12 +88,18 @@
|
|||
],
|
||||
"nullable": true
|
||||
},
|
||||
"default": {
|
||||
"nullable": true
|
||||
},
|
||||
"definitions": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"$ref": "#/components/schemas/Schema"
|
||||
}
|
||||
},
|
||||
"deprecated": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"description": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
|
@ -251,6 +249,9 @@
|
|||
],
|
||||
"nullable": true
|
||||
},
|
||||
"readOnly": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"required": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
|
@ -289,9 +290,20 @@
|
|||
"uniqueItems": {
|
||||
"type": "boolean",
|
||||
"nullable": true
|
||||
},
|
||||
"writeOnly": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/SchemaObject"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,14 +1,6 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Schema",
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/SchemaObject"
|
||||
}
|
||||
],
|
||||
"definitions": {
|
||||
"InstanceType": {
|
||||
"enum": [
|
||||
|
@ -101,12 +93,16 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"default": true,
|
||||
"definitions": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"$ref": "#/definitions/Schema"
|
||||
}
|
||||
},
|
||||
"deprecated": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"description": {
|
||||
"type": [
|
||||
"string",
|
||||
|
@ -280,6 +276,9 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"readOnly": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"required": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
|
@ -317,6 +316,9 @@
|
|||
"boolean",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"writeOnly": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"additionalProperties": true
|
||||
|
@ -347,5 +349,13 @@
|
|||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/SchemaObject"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue