forked from GREsau/schemars
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Read #[validate(...)] attributes * Handle required flattened Option fields * Refactor out `add_schema_as_property` * Process validation attributes in newtype structs * Process validation attributes in tuple structs * Refactor out "local_id" for type definitions * Refactoring * Support inline regex * Allow setting validation attributes via #[schemars(...)] * Add some doc comments * Fix doc test * Emit compilation errors for duplicate validation attributes * Fix indexmap tests for rust 1.37 * upgrade diem dep (#1) * Update changelog and docs * Add newline to attributes docs * v0.8.4 * Allow empty #[validate] attributes. Fixes GREsau#109 * v0.8.5 * Use oneOf for enums when possible (GREsau#108) * v0.8.6 * Correct latest changelog entry * update diem dep * Implement JsonSchema on EnumSet type * update diem dep * Upgrade move deps (#3) * [deps] Upgrade move types dep. * Update examples after 0a1200b * Allow non-Serialize default values. Default values that don't implement Serialize are now ignored, rather than causing a compile error. This is done by simulating specialization using a technique copied from Rocket: https://github.com/SergioBenitez/Rocket/blob/5ebefa97c992c37bdc476299304a339d429a43fc/core/lib/src/sentinel.rs#L391-L445 Fixes GREsau#115 * v0.8.7 * update diem deps * Add example for optional dependency in readme Based on https://github.com/GREsau/schemars/pull/118/files * Add support for rust_decimal and bigdecimal (GREsau#101) * Document new optional dependencies * Internally tagged enums don't honor deny_unknown_fields as precisely as they might. flatten doesn't act quite as intended with regard to additional_properties * v0.8.8 * update diem deps to latest * update diem deps * Update dep * update diem deps * Update rust toolchain and dep * update diem dep * Update diem dep * [crypto] Update dependency crypto to use starcoinorg/starcoin-crypto repo (#5) * [crypto] Update dependency crypto to use starcoinorg/starcoin-crypto repo. * [deps] Update move-core-types to starcoinorg/move * Remove diem types Co-authored-by: Graham Esau <gesau@hotmail.co.uk> Co-authored-by: lerencao <funfriendcjf@gmail.com> Co-authored-by: Graham Esau <graham.esau@vonage.com> Co-authored-by: Adam Leventhal <adam.leventhal@gmail.com> Co-authored-by: Matt Campbell <mattcampbell@pobox.com> Co-authored-by: jolestar <jolestar@gmail.com> Co-authored-by: timando <github@timando.net> Co-authored-by: Adam H. Leventhal <ahl@oxide.computer>
- Loading branch information
1 parent
50cda49
commit 67897a7
Showing
73 changed files
with
2,190 additions
and
529 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ Cargo.lock | |
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ | |
}, | ||
"definitions": { | ||
"MyEnum": { | ||
"anyOf": [ | ||
"oneOf": [ | ||
{ | ||
"type": "object", | ||
"required": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ | |
}, | ||
"definitions": { | ||
"MyEnum": { | ||
"anyOf": [ | ||
"oneOf": [ | ||
{ | ||
"type": "object", | ||
"required": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use schemars::{schema_for, JsonSchema}; | ||
|
||
#[derive(JsonSchema)] | ||
pub struct MyStruct { | ||
#[validate(range(min = 1, max = 10))] | ||
pub my_int: i32, | ||
pub my_bool: bool, | ||
#[validate(required)] | ||
pub my_nullable_enum: Option<MyEnum>, | ||
} | ||
|
||
#[derive(JsonSchema)] | ||
pub enum MyEnum { | ||
StringNewType(#[validate(phone)] String), | ||
StructVariant { | ||
#[validate(length(min = 1, max = 100))] | ||
floats: Vec<f32>, | ||
}, | ||
} | ||
|
||
fn main() { | ||
let schema = schema_for!(MyStruct); | ||
println!("{}", serde_json::to_string_pretty(&schema).unwrap()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "MyStruct", | ||
"type": "object", | ||
"required": [ | ||
"my_bool", | ||
"my_int", | ||
"my_nullable_enum" | ||
], | ||
"properties": { | ||
"my_bool": { | ||
"type": "boolean" | ||
}, | ||
"my_int": { | ||
"type": "integer", | ||
"format": "int32", | ||
"maximum": 10.0, | ||
"minimum": 1.0 | ||
}, | ||
"my_nullable_enum": { | ||
"oneOf": [ | ||
{ | ||
"type": "object", | ||
"required": [ | ||
"StringNewType" | ||
], | ||
"properties": { | ||
"StringNewType": { | ||
"type": "string", | ||
"format": "phone" | ||
} | ||
}, | ||
"additionalProperties": false | ||
}, | ||
{ | ||
"type": "object", | ||
"required": [ | ||
"StructVariant" | ||
], | ||
"properties": { | ||
"StructVariant": { | ||
"type": "object", | ||
"required": [ | ||
"floats" | ||
], | ||
"properties": { | ||
"floats": { | ||
"type": "array", | ||
"items": { | ||
"type": "number", | ||
"format": "float" | ||
}, | ||
"maxItems": 100, | ||
"minItems": 1 | ||
} | ||
} | ||
} | ||
}, | ||
"additionalProperties": false | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.51.0 | ||
1.57.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.