Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions typify-impl/src/type_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1806,7 +1806,9 @@ impl TypeEntry {
if key_ty.details == TypeEntryDetails::String
&& value_ty.details == TypeEntryDetails::JsonValue
{
quote! { ::serde_json::Map<::std::string::String, ::serde_json::Value> }
quote! {
::serde_json::Map<::std::string::String, ::serde_json::Value>
}
} else {
let key_ident = key_ty.type_ident(type_space, type_mod);
let value_ident = value_ty.type_ident(type_space, type_mod);
Expand All @@ -1824,7 +1826,7 @@ impl TypeEntry {
let item = inner_ty.type_ident(type_space, type_mod);
// TODO we'll want this to be a Set of some kind, but we need
// to get the derives right first.
quote! { Vec<#item> }
quote! { ::std::vec::Vec<#item> }
}

TypeEntryDetails::Tuple(items) => {
Expand Down
12 changes: 10 additions & 2 deletions typify/tests/schemas/arrays-and-tuples.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@
"array-sans-items": {
"type": "array",
"minItems": 1,
"uniqueItems": true
"uniqueItems": false
},
"set-avec-item": {
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": {
"type": "string"
}
}
}
}
}
48 changes: 41 additions & 7 deletions typify/tests/schemas/arrays-and-tuples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@ pub mod error {
#[doc = "{"]
#[doc = " \"type\": \"array\","]
#[doc = " \"minItems\": 1,"]
#[doc = " \"uniqueItems\": true"]
#[doc = " \"uniqueItems\": false"]
#[doc = "}"]
#[doc = r" ```"]
#[doc = r" </details>"]
#[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug)]
#[serde(transparent)]
pub struct ArraySansItems(pub Vec<::serde_json::Value>);
pub struct ArraySansItems(pub ::std::vec::Vec<::serde_json::Value>);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that this is (and was) wrong: we're not enforcing the minItems constraint

impl ::std::ops::Deref for ArraySansItems {
type Target = Vec<::serde_json::Value>;
fn deref(&self) -> &Vec<::serde_json::Value> {
type Target = ::std::vec::Vec<::serde_json::Value>;
fn deref(&self) -> &::std::vec::Vec<::serde_json::Value> {
&self.0
}
}
impl ::std::convert::From<ArraySansItems> for Vec<::serde_json::Value> {
impl ::std::convert::From<ArraySansItems> for ::std::vec::Vec<::serde_json::Value> {
fn from(value: ArraySansItems) -> Self {
value.0
}
}
impl ::std::convert::From<Vec<::serde_json::Value>> for ArraySansItems {
fn from(value: Vec<::serde_json::Value>) -> Self {
impl ::std::convert::From<::std::vec::Vec<::serde_json::Value>> for ArraySansItems {
fn from(value: ::std::vec::Vec<::serde_json::Value>) -> Self {
Self(value)
}
}
Expand Down Expand Up @@ -98,6 +98,40 @@ impl ::std::convert::From<(::std::string::String, ::std::string::String)> for Le
Self(value)
}
}
#[doc = "`SetAvecItem`"]
#[doc = r""]
#[doc = r" <details><summary>JSON schema</summary>"]
#[doc = r""]
#[doc = r" ```json"]
#[doc = "{"]
#[doc = " \"type\": \"array\","]
#[doc = " \"items\": {"]
#[doc = " \"type\": \"string\""]
#[doc = " },"]
#[doc = " \"minItems\": 1,"]
#[doc = " \"uniqueItems\": true"]
#[doc = "}"]
#[doc = r" ```"]
#[doc = r" </details>"]
#[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug)]
#[serde(transparent)]
pub struct SetAvecItem(pub ::std::vec::Vec<::std::string::String>);
impl ::std::ops::Deref for SetAvecItem {
type Target = ::std::vec::Vec<::std::string::String>;
fn deref(&self) -> &::std::vec::Vec<::std::string::String> {
&self.0
}
}
impl ::std::convert::From<SetAvecItem> for ::std::vec::Vec<::std::string::String> {
fn from(value: SetAvecItem) -> Self {
value.0
}
}
impl ::std::convert::From<::std::vec::Vec<::std::string::String>> for SetAvecItem {
fn from(value: ::std::vec::Vec<::std::string::String>) -> Self {
Self(value)
}
}
#[doc = "`SimpleTwoArray`"]
#[doc = r""]
#[doc = r" <details><summary>JSON schema</summary>"]
Expand Down
Loading