Add default, deprecated, readOnly, writeOnly properties

This commit is contained in:
Graham Esau 2019-10-13 23:01:48 +01:00
parent f38f58d1e8
commit 68ddfa310f
4 changed files with 68 additions and 22 deletions

View file

@ -40,10 +40,21 @@ impl_merge!(SchemaObject {
or: format const_value reference, or: format const_value reference,
}); });
impl_merge!(Metadata { impl Merge for Metadata {
merge: definitions, fn merge(self, other: Self) -> Self {
or: schema id title description, 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 { impl_merge!(SubschemaValidation {
or: all_of any_of one_of not if_schema then_schema else_schema, or: all_of any_of one_of not if_schema then_schema else_schema,

View file

@ -126,6 +126,19 @@ pub struct Metadata {
pub description: Option<String>, pub description: Option<String>,
#[serde(alias = "$defs", skip_serializing_if = "Map::is_empty")] #[serde(alias = "$defs", skip_serializing_if = "Map::is_empty")]
pub definitions: Map<String, Schema>, 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)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema)]

View file

@ -1,14 +1,6 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
"title": "Schema", "title": "Schema",
"anyOf": [
{
"type": "boolean"
},
{
"$ref": "#/components/schemas/SchemaObject"
}
],
"definitions": { "definitions": {
"InstanceType": { "InstanceType": {
"enum": [ "enum": [
@ -96,12 +88,18 @@
], ],
"nullable": true "nullable": true
}, },
"default": {
"nullable": true
},
"definitions": { "definitions": {
"type": "object", "type": "object",
"additionalProperties": { "additionalProperties": {
"$ref": "#/components/schemas/Schema" "$ref": "#/components/schemas/Schema"
} }
}, },
"deprecated": {
"type": "boolean"
},
"description": { "description": {
"type": "string", "type": "string",
"nullable": true "nullable": true
@ -251,6 +249,9 @@
], ],
"nullable": true "nullable": true
}, },
"readOnly": {
"type": "boolean"
},
"required": { "required": {
"type": "array", "type": "array",
"items": { "items": {
@ -289,9 +290,20 @@
"uniqueItems": { "uniqueItems": {
"type": "boolean", "type": "boolean",
"nullable": true "nullable": true
},
"writeOnly": {
"type": "boolean"
} }
}, },
"additionalProperties": true "additionalProperties": true
} }
} },
"anyOf": [
{
"type": "boolean"
},
{
"$ref": "#/components/schemas/SchemaObject"
}
]
} }

View file

@ -1,14 +1,6 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
"title": "Schema", "title": "Schema",
"anyOf": [
{
"type": "boolean"
},
{
"$ref": "#/definitions/SchemaObject"
}
],
"definitions": { "definitions": {
"InstanceType": { "InstanceType": {
"enum": [ "enum": [
@ -101,12 +93,16 @@
} }
] ]
}, },
"default": true,
"definitions": { "definitions": {
"type": "object", "type": "object",
"additionalProperties": { "additionalProperties": {
"$ref": "#/definitions/Schema" "$ref": "#/definitions/Schema"
} }
}, },
"deprecated": {
"type": "boolean"
},
"description": { "description": {
"type": [ "type": [
"string", "string",
@ -280,6 +276,9 @@
} }
] ]
}, },
"readOnly": {
"type": "boolean"
},
"required": { "required": {
"type": "array", "type": "array",
"items": { "items": {
@ -317,6 +316,9 @@
"boolean", "boolean",
"null" "null"
] ]
},
"writeOnly": {
"type": "boolean"
} }
}, },
"additionalProperties": true "additionalProperties": true
@ -347,5 +349,13 @@
} }
] ]
} }
} },
"anyOf": [
{
"type": "boolean"
},
{
"$ref": "#/definitions/SchemaObject"
}
]
} }