-
-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add #[schemars(bound = ...)] attribute
Based on #162 Co-authored-by: teozkr <teo@nullable.se>
- Loading branch information
Showing
7 changed files
with
76 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
mod util; | ||
use std::marker::PhantomData; | ||
|
||
use schemars::JsonSchema; | ||
use util::*; | ||
|
||
struct MyIterator; | ||
|
||
impl Iterator for MyIterator { | ||
type Item = String; | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
// The default trait bounds would require T to implement JsonSchema, | ||
// which MyIterator does not. | ||
#[derive(JsonSchema)] | ||
#[schemars(bound = "T::Item: JsonSchema", rename = "MyContainer")] | ||
pub struct MyContainer<T> where T: Iterator { | ||
pub associated: T::Item, | ||
pub generic: PhantomData<T>, | ||
} | ||
|
||
#[test] | ||
fn manual_bound_set() -> TestResult { | ||
test_default_generated_schema::<MyContainer<MyIterator>>("bound") | ||
} |
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,17 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "MyContainer", | ||
"type": "object", | ||
"required": [ | ||
"associated", | ||
"generic" | ||
], | ||
"properties": { | ||
"associated": { | ||
"type": "string" | ||
}, | ||
"generic": { | ||
"type": "null" | ||
} | ||
} | ||
} |
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