-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5407716
commit 8397d51
Showing
12 changed files
with
181 additions
and
32 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
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
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,71 @@ | ||
use std::collections::HashMap; | ||
|
||
use specta::{ts::ExportError, SerdeError, Type}; | ||
|
||
use crate::ts::{assert_ts, assert_ts_export}; | ||
|
||
#[derive(Type)] | ||
#[specta(export = false)] | ||
pub struct Recursive { | ||
demo: Box<Recursive>, | ||
} | ||
|
||
#[derive(Type)] | ||
#[specta(transparent, export = false)] | ||
pub struct RecursiveMapKeyTrick(RecursiveMapKey); | ||
|
||
#[derive(Type)] | ||
#[specta(export = false)] | ||
pub struct RecursiveMapKey { | ||
demo: HashMap<RecursiveMapKeyTrick, String>, | ||
} | ||
|
||
#[derive(Type)] | ||
#[specta(export = false)] | ||
pub struct RecursiveMapValue { | ||
demo: HashMap<String, RecursiveMapValue>, | ||
} | ||
|
||
#[derive(Type)] | ||
#[specta(export = false)] | ||
pub struct RecursiveInline { | ||
#[specta(flatten)] | ||
demo: Box<RecursiveInline>, | ||
} | ||
|
||
// #[derive(Type)] | ||
// #[specta(transparent, export = false)] | ||
// pub struct RecursiveTransparent(Box<RecursiveInline>); | ||
|
||
// #[derive(Type)] | ||
// #[specta(export = false)] | ||
// pub struct RecursiveMapKey(HashMap<RecursiveMapKey, ()>); | ||
|
||
#[test] | ||
fn test_recursive_types() { | ||
assert_ts!(Recursive, "{ demo: Recursive }"); | ||
assert_ts_export!(Recursive, "export type Recursive = { demo: Recursive }"); | ||
|
||
// Just check it doesn't overflow while doing this check | ||
assert_ts!(error; RecursiveMapKey, ExportError::Serde(SerdeError::InvalidMapKey)); | ||
assert_ts_export!( | ||
error; | ||
RecursiveMapKey, | ||
ExportError::Serde(SerdeError::InvalidMapKey) | ||
); | ||
|
||
assert_ts!( | ||
RecursiveMapValue, | ||
"{ demo: { [key in string]: RecursiveMapValue } }" | ||
); | ||
assert_ts_export!( | ||
RecursiveMapValue, | ||
"export type RecursiveMapValue = { demo: { [key in string]: RecursiveMapValue } }" | ||
); | ||
|
||
// assert_ts!(RecursiveInline, ""); | ||
// assert_ts_export!(RecursiveInline, ""); | ||
|
||
// assert_ts!(RecursiveTransparent, ""); | ||
// assert_ts_export!(RecursiveTransparent, ""); | ||
} |
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,28 @@ | ||
use specta::ts::{BigIntExportBehavior, ExportConfig}; | ||
|
||
use crate::ts::{assert_ts, assert_ts_export}; | ||
|
||
#[test] | ||
fn serde_json() { | ||
assert_eq!( | ||
specta::ts::inline::<serde_json::Number>( | ||
&ExportConfig::default().bigint(BigIntExportBehavior::Number) | ||
), | ||
Ok("number".into()) | ||
); | ||
assert_ts!(serde_json::Map<String, String>, "{ [key in string]: string }"); | ||
|
||
assert_eq!( | ||
specta::ts::inline::<serde_json::Value>( | ||
&ExportConfig::default().bigint(BigIntExportBehavior::Number) | ||
), | ||
Ok( | ||
// TODO: Can we have `#[specta(inline = false)]` for this so it's `JsonValue`??? | ||
"null | boolean | number | string | JsonValue[] | { [key in string]: JsonValue }" | ||
.into() | ||
) | ||
); | ||
|
||
// assert_ts!(serde_json::Value, ""); // TODO: This literally can't work | ||
// assert_ts_export!(serde_json::Value, ""); | ||
} |
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 |
---|---|---|
|
@@ -3,5 +3,6 @@ mod empty_enum; | |
mod empty_struct; | ||
mod externally_tagged; | ||
mod internally_tagged; | ||
mod json; | ||
mod skip; | ||
mod untagged; |
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