From 5021204dfbf1da04fa87b2d9a8c4e0bba66fa802 Mon Sep 17 00:00:00 2001 From: Graham Esau Date: Thu, 9 Apr 2020 17:03:27 +0100 Subject: [PATCH] Add `examples` schema keyword --- schemars/src/flatten.rs | 1 + schemars/src/schema.rs | 5 +++++ schemars/tests/expected/schema-2019_09.json | 10 ++++++++++ schemars/tests/expected/schema-openapi3.json | 10 ++++++++++ schemars/tests/expected/schema.json | 10 ++++++++++ 5 files changed, 36 insertions(+) diff --git a/schemars/src/flatten.rs b/schemars/src/flatten.rs index d5e32a9..d3c777e 100644 --- a/schemars/src/flatten.rs +++ b/schemars/src/flatten.rs @@ -51,6 +51,7 @@ impl Merge for Metadata { deprecated: self.deprecated || other.deprecated, read_only: self.read_only || other.read_only, write_only: self.write_only || other.write_only, + examples: self.examples.merge(other.examples), } } } diff --git a/schemars/src/schema.rs b/schemars/src/schema.rs index 81763aa..cfbce53 100644 --- a/schemars/src/schema.rs +++ b/schemars/src/schema.rs @@ -261,6 +261,11 @@ pub struct Metadata { /// See [JSON Schema Validation 9.4. "readOnly" and "writeOnly"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-9.4). #[serde(skip_serializing_if = "is_false")] pub write_only: bool, + /// The `examples` keyword. + /// + /// See [JSON Schema Validation 9.5. "examples"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-9.5). + #[serde(skip_serializing_if = "Vec::is_empty")] + pub examples: Vec, } #[allow(clippy::trivially_copy_pass_by_ref)] diff --git a/schemars/tests/expected/schema-2019_09.json b/schemars/tests/expected/schema-2019_09.json index 9b67416..5592b53 100644 --- a/schemars/tests/expected/schema-2019_09.json +++ b/schemars/tests/expected/schema-2019_09.json @@ -121,6 +121,11 @@ ], "items": true }, + "examples": { + "description": "The `examples` keyword.\n\nSee [JSON Schema Validation 9.5. \"examples\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-9.5).", + "type": "array", + "items": true + }, "exclusiveMaximum": { "description": "The `exclusiveMaximum` keyword.\n\nSee [JSON Schema Validation 6.2.3. \"exclusiveMaximum\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.2.3).", "type": [ @@ -483,6 +488,11 @@ ], "items": true }, + "examples": { + "description": "The `examples` keyword.\n\nSee [JSON Schema Validation 9.5. \"examples\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-9.5).", + "type": "array", + "items": true + }, "exclusiveMaximum": { "description": "The `exclusiveMaximum` keyword.\n\nSee [JSON Schema Validation 6.2.3. \"exclusiveMaximum\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.2.3).", "type": [ diff --git a/schemars/tests/expected/schema-openapi3.json b/schemars/tests/expected/schema-openapi3.json index c1223c0..6da10c6 100644 --- a/schemars/tests/expected/schema-openapi3.json +++ b/schemars/tests/expected/schema-openapi3.json @@ -101,6 +101,11 @@ "items": {}, "nullable": true }, + "examples": { + "description": "The `examples` keyword.\n\nSee [JSON Schema Validation 9.5. \"examples\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-9.5).", + "type": "array", + "items": {} + }, "exclusiveMaximum": { "description": "The `exclusiveMaximum` keyword.\n\nSee [JSON Schema Validation 6.2.3. \"exclusiveMaximum\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.2.3).", "type": "number", @@ -405,6 +410,11 @@ "items": {}, "nullable": true }, + "examples": { + "description": "The `examples` keyword.\n\nSee [JSON Schema Validation 9.5. \"examples\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-9.5).", + "type": "array", + "items": {} + }, "exclusiveMaximum": { "description": "The `exclusiveMaximum` keyword.\n\nSee [JSON Schema Validation 6.2.3. \"exclusiveMaximum\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.2.3).", "type": "number", diff --git a/schemars/tests/expected/schema.json b/schemars/tests/expected/schema.json index 012ada0..8b0d4e0 100644 --- a/schemars/tests/expected/schema.json +++ b/schemars/tests/expected/schema.json @@ -121,6 +121,11 @@ ], "items": true }, + "examples": { + "description": "The `examples` keyword.\n\nSee [JSON Schema Validation 9.5. \"examples\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-9.5).", + "type": "array", + "items": true + }, "exclusiveMaximum": { "description": "The `exclusiveMaximum` keyword.\n\nSee [JSON Schema Validation 6.2.3. \"exclusiveMaximum\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.2.3).", "type": [ @@ -487,6 +492,11 @@ ], "items": true }, + "examples": { + "description": "The `examples` keyword.\n\nSee [JSON Schema Validation 9.5. \"examples\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-9.5).", + "type": "array", + "items": true + }, "exclusiveMaximum": { "description": "The `exclusiveMaximum` keyword.\n\nSee [JSON Schema Validation 6.2.3. \"exclusiveMaximum\"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.2.3).", "type": [