Skip to content

Commit 6181a61

Browse files
authored
Make linked-hash-map an optional dependency (#23)
1 parent b43f2c4 commit 6181a61

File tree

6 files changed

+37
-24
lines changed

6 files changed

+37
-24
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ include = ["src/**/*", "LICENSE", "crates-io.md"]
1818

1919
[dependencies]
2020
indexmap = "1.7"
21-
linked-hash-map = "0.5.4"
2221
openapi_type_derive = { path = "./derive", version = "0.2.5" }
2322
openapiv3 = "=1.0.0"
2423
serde_json = "1.0"
2524

2625
# optional dependencies / features
2726
chrono = { version = "0.4.19", default-features = false, optional = true }
27+
linked-hash-map = { version = "0.5.4", optional = true }
2828
time = { version = "0.3.4", features = ["serde-human-readable"], optional = true }
2929
uuid = { version = "0.8.2", optional = true }
3030

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ This repository contains the following crates:
2929

3030
# openapi_type
3131

32-
This crate gives static type information for primitives and commonly used types from the standard library and a few other commonly used libraries like `chrono`, `time` and `uuid`. Also, it provides a derive macro for structs and enums to gain access to their static type information at runtime.
32+
This crate gives static type information for primitives and commonly used types from the standard library and other commonly used libraries `chrono`, `indexmap`, `linked-hash-map`, `time` and `uuid` when the according feature is enabled. Also, it provides a derive macro for structs and enums to gain access to their static type information at runtime.
3333

3434
The core of this crate is the [`OpenapiType`][__link0] trait. It has one static function, [`schema`][__link1], which returns an [`OpenapiSchema`][__link2]. This assembles the static type information in a way that is convenient to use for a generated OpenAPI specification, but can also be utilized in other use cases as well.
3535

crates-io.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# openapi_type [![Rust 1.56+](https://img.shields.io/badge/rustc-1.56+-orange.svg)](https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html) [![License Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0) [![GitHub](https://img.shields.io/badge/Code-On%20Github-blue?logo=GitHub)](https://github.com/msrd0/openapi_type)
22

3-
This crate gives static type information for primitives and commonly used types from the standard library and a few other commonly used libraries like `chrono`, `time` and `uuid`. Also, it provides a derive macro for structs and enums to gain access to their static type information at runtime.
3+
This crate gives static type information for primitives and commonly used types from the standard library and other commonly used libraries `chrono`, `indexmap`, `linked-hash-map`, `time` and `uuid` when the according feature is enabled. Also, it provides a derive macro for structs and enums to gain access to their static type information at runtime.
44

55
The core of this crate is the [`OpenapiType`][__link0] trait. It has one static function, [`schema`][__link1], which returns an [`OpenapiSchema`][__link2]. This assembles the static type information in a way that is convenient to use for a generated OpenAPI specification, but can also be utilized in other use cases as well.
66

src/impls.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::{OpenapiSchema, OpenapiType};
22
use indexmap::{IndexMap, IndexSet};
3-
use linked_hash_map::LinkedHashMap;
43
use openapiv3::{
54
AdditionalProperties, ArrayType, IntegerType, NumberFormat, NumberType, ObjectType, ReferenceOr, SchemaKind,
65
StringFormat, StringType, Type, VariantOrUnknownOrEmpty
@@ -230,7 +229,12 @@ fn map_schema<K: OpenapiType, T: OpenapiType>() -> OpenapiSchema {
230229
impl_openapi_type!(
231230
BTreeMap<K: OpenapiType, T: OpenapiType>,
232231
HashMap<K: OpenapiType, T: OpenapiType, S: BuildHasher>,
233-
IndexMap<K: OpenapiType, T: OpenapiType>,
234-
LinkedHashMap<K: OpenapiType, T: OpenapiType, S: BuildHasher>
232+
IndexMap<K: OpenapiType, T: OpenapiType>
233+
=> map_schema::<K, T>()
234+
);
235+
236+
#[cfg(feature = "linked-hash-map")]
237+
impl_openapi_type!(
238+
linked_hash_map::LinkedHashMap<K: OpenapiType, T: OpenapiType, S: BuildHasher>
235239
=> map_schema::<K, T>()
236240
);

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
#![cfg_attr(feature = "cargo-clippy", allow(clippy::tabs_in_doc_comments))]
55
#![doc = r##"
66
This crate gives static type information for primitives and commonly used types from the standard
7-
library and a few other commonly used libraries like `chrono`, `time` and `uuid`. Also, it provides
8-
a derive macro for structs and enums to gain access to their static type information at runtime.
7+
library and other commonly used libraries `chrono`, `indexmap`, `linked-hash-map`, `time` and
8+
`uuid` when the according feature is enabled. Also, it provides a derive macro for structs and
9+
enums to gain access to their static type information at runtime.
910
1011
The core of this crate is the [`OpenapiType`] trait. It has one static function,
1112
[`schema`](OpenapiType::schema), which returns an [`OpenapiSchema`]. This assembles the static

tests/std_types.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use indexmap::{IndexMap, IndexSet};
2-
use linked_hash_map::LinkedHashMap;
32
use openapi_type::OpenapiType;
43
use serde_json::Value;
54
use std::{
@@ -213,20 +212,29 @@ test_type!(BTreeSet<String>, IndexSet<String>, HashSet<String> = {
213212
"uniqueItems": true
214213
});
215214

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"
215+
test_type!(BTreeMap<isize, String>, HashMap<isize, String>, IndexMap<isize, String> = {
216+
"type": "object",
217+
"properties": {
218+
"default": {
219+
"type": "integer"
230220
}
221+
},
222+
"required": ["default"],
223+
"additionalProperties": {
224+
"type": "string"
231225
}
232-
);
226+
});
227+
228+
#[cfg(feature = "linked-hash-map")]
229+
test_type!(linked_hash_map::LinkedHashMap<isize, String> = {
230+
"type": "object",
231+
"properties": {
232+
"default": {
233+
"type": "integer"
234+
}
235+
},
236+
"required": ["default"],
237+
"additionalProperties": {
238+
"type": "string"
239+
}
240+
});

0 commit comments

Comments
 (0)