Skip to content

Commit

Permalink
Add support for linked-hash-map (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
msrd0 authored Jan 1, 2022
1 parent 95c2aa2 commit 925df1b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ include = ["src/**/*", "LICENSE", "crates-io.md"]

[dependencies]
indexmap = "1.7"
linked-hash-map = "0.5.4"
openapi_type_derive = { path = "./derive", version = "0.2.4" }
openapiv3 = "=0.4.0"
serde_json = "1.0"
Expand Down
4 changes: 3 additions & 1 deletion src/impls.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{OpenapiSchema, OpenapiType};
use indexmap::{IndexMap, IndexSet};
use linked_hash_map::LinkedHashMap;
use openapiv3::{
AdditionalProperties, ArrayType, IntegerType, NumberFormat, NumberType, ObjectType, ReferenceOr, SchemaKind,
StringFormat, StringType, Type, VariantOrUnknownOrEmpty
Expand Down Expand Up @@ -228,7 +229,8 @@ fn map_schema<K: OpenapiType, T: OpenapiType>() -> OpenapiSchema {

impl_openapi_type!(
BTreeMap<K: OpenapiType, T: OpenapiType>,
HashMap<K: OpenapiType, T: OpenapiType, S: BuildHasher>,
IndexMap<K: OpenapiType, T: OpenapiType>,
HashMap<K: OpenapiType, T: OpenapiType, S: BuildHasher>
LinkedHashMap<K: OpenapiType, T: OpenapiType, S: BuildHasher>
=> map_schema::<K, T>()
);
27 changes: 17 additions & 10 deletions tests/std_types.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use indexmap::{IndexMap, IndexSet};
use linked_hash_map::LinkedHashMap;
use openapi_type::OpenapiType;
use serde_json::Value;
use std::{
collections::{BTreeMap, BTreeSet, HashMap, HashSet},
num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize}
};

macro_rules! test_type {
($($($ty:ident)::+ $(<$($($generic:ident)::+),+>)?),* = $json:tt) => {
paste::paste! {
Expand Down Expand Up @@ -211,15 +213,20 @@ test_type!(BTreeSet<String>, IndexSet<String>, HashSet<String> = {
"uniqueItems": true
});

test_type!(BTreeMap<isize, String>, IndexMap<isize, String>, HashMap<isize, String> = {
"type": "object",
"properties": {
"default": {
"type": "integer"
test_type!(
BTreeMap<isize, String>,
HashMap<isize, String>,
IndexMap<isize, String>,
LinkedHashMap<isize, String> = {
"type": "object",
"properties": {
"default": {
"type": "integer"
}
},
"required": ["default"],
"additionalProperties": {
"type": "string"
}
},
"required": ["default"],
"additionalProperties": {
"type": "string"
}
});
);

0 comments on commit 925df1b

Please sign in to comment.