Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schemars compatibility #30

Merged
merged 4 commits into from
Jan 30, 2024
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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ keywords = ["currency", "iso", "iso-4217", "iso4217"]

[features]
default = []
with-serde = ["serde"]
iterator = ["strum"]
with-serde = ["dep:serde"]
iterator = ["dep:strum"]
with-schemars = ["dep:schemars", "with-serde"]

[dependencies]
iso_country = "0.1.4"
schemars = { version = "0.8.16", optional = true }
serde = { version = "1.0.127", optional = true, features = ["derive"] }
strum = {version = "0.26.1", optional = true, features = ["derive"] }

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The crate has only two optional features:

- `with-serde`
- `iterator`
- `with-schemars`

### with-serde

Expand All @@ -35,6 +36,12 @@ use iso_currency::IntoEnumIterator;
let mut iter = Currency::iter();
```

### with-schemars

If you need to generate a JSON schema for your project, you can use the `with-schemars` feature. This will derive [`schemars's`](https://crates.io/crates/schemars) `JsonSchema` trait on `Currency`.

**NOTE**: This feature enables `with-serde` as well.

## Examples

```rust
Expand Down
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ fn write_enum(file: &mut BufWriter<File>, data: &[IsoData]) {
let outline = quote! {
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "iterator", derive(EnumIter))]
#[cfg_attr(feature = "with-schemars", derive(JsonSchema))]
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum Currency {
#body
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub use iso_country::Country;
#[cfg_attr(docsrs, doc(cfg(feature = "with-serde")))]
use serde::{Deserialize, Serialize};

#[cfg(feature = "with-schemars")]
use schemars::JsonSchema;
#[cfg(feature = "iterator")]
#[cfg_attr(docsrs, doc(cfg(feature = "iterator")))]
use strum::EnumIter;
Expand Down
Loading