Skip to content

Commit 925df1b

Browse files
authored
Add support for linked-hash-map (#22)
1 parent 95c2aa2 commit 925df1b

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ include = ["src/**/*", "LICENSE", "crates-io.md"]
1717

1818
[dependencies]
1919
indexmap = "1.7"
20+
linked-hash-map = "0.5.4"
2021
openapi_type_derive = { path = "./derive", version = "0.2.4" }
2122
openapiv3 = "=0.4.0"
2223
serde_json = "1.0"

src/impls.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{OpenapiSchema, OpenapiType};
22
use indexmap::{IndexMap, IndexSet};
3+
use linked_hash_map::LinkedHashMap;
34
use openapiv3::{
45
AdditionalProperties, ArrayType, IntegerType, NumberFormat, NumberType, ObjectType, ReferenceOr, SchemaKind,
56
StringFormat, StringType, Type, VariantOrUnknownOrEmpty
@@ -228,7 +229,8 @@ fn map_schema<K: OpenapiType, T: OpenapiType>() -> OpenapiSchema {
228229

229230
impl_openapi_type!(
230231
BTreeMap<K: OpenapiType, T: OpenapiType>,
232+
HashMap<K: OpenapiType, T: OpenapiType, S: BuildHasher>,
231233
IndexMap<K: OpenapiType, T: OpenapiType>,
232-
HashMap<K: OpenapiType, T: OpenapiType, S: BuildHasher>
234+
LinkedHashMap<K: OpenapiType, T: OpenapiType, S: BuildHasher>
233235
=> map_schema::<K, T>()
234236
);

tests/std_types.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use indexmap::{IndexMap, IndexSet};
2+
use linked_hash_map::LinkedHashMap;
23
use openapi_type::OpenapiType;
34
use serde_json::Value;
45
use std::{
56
collections::{BTreeMap, BTreeSet, HashMap, HashSet},
67
num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize}
78
};
9+
810
macro_rules! test_type {
911
($($($ty:ident)::+ $(<$($($generic:ident)::+),+>)?),* = $json:tt) => {
1012
paste::paste! {
@@ -211,15 +213,20 @@ test_type!(BTreeSet<String>, IndexSet<String>, HashSet<String> = {
211213
"uniqueItems": true
212214
});
213215

214-
test_type!(BTreeMap<isize, String>, IndexMap<isize, String>, HashMap<isize, String> = {
215-
"type": "object",
216-
"properties": {
217-
"default": {
218-
"type": "integer"
216+
test_type!(
217+
BTreeMap<isize, String>,
218+
HashMap<isize, String>,
219+
IndexMap<isize, String>,
220+
LinkedHashMap<isize, String> = {
221+
"type": "object",
222+
"properties": {
223+
"default": {
224+
"type": "integer"
225+
}
226+
},
227+
"required": ["default"],
228+
"additionalProperties": {
229+
"type": "string"
219230
}
220-
},
221-
"required": ["default"],
222-
"additionalProperties": {
223-
"type": "string"
224231
}
225-
});
232+
);

0 commit comments

Comments
 (0)