Skip to content

Commit

Permalink
Replace serde_yaml with serde_norway (#1056)
Browse files Browse the repository at this point in the history
  • Loading branch information
sycute authored Feb 13, 2025
1 parent d4f64fb commit 5e9c7ef
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ serde = "1"
serde_json = "1"
serde-xml-rs = "0.6"
serde_urlencoded = "0.7"
serde_yaml = "0.9"
serde_norway = "0.9"
serde_with = "3"
sha2 = "0.10"
smallvec = "1"
Expand Down
38 changes: 31 additions & 7 deletions crates/oapi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,30 @@ homepage = { workspace = true }
repository = { workspace = true }
keywords = ["http", "async", "salvo", "openapi", "swagger-ui"]
categories = ["network-programming", "asynchronous"]
authors = ["Juha Kukkonen <[email protected]>", "Chrislearn Young <[email protected]>"]
authors = [
"Juha Kukkonen <[email protected]>",
"Chrislearn Young <[email protected]>",
]

[features]
default = []
full = ["swagger-ui", "scalar", "rapidoc", "redoc", "chrono", "decimal", "url", "ulid", "uuid", "time", "smallvec", "indexmap", "yaml", "non-strict-integers", "compact_str"]
full = [
"swagger-ui",
"scalar",
"rapidoc",
"redoc",
"chrono",
"decimal",
"url",
"ulid",
"uuid",
"time",
"smallvec",
"indexmap",
"yaml",
"non-strict-integers",
"compact_str",
]
swagger-ui = ["dep:rust-embed"]
scalar = []
rapidoc = []
Expand All @@ -30,14 +49,16 @@ uuid = ["salvo-oapi-macros/uuid", "dep:uuid"]
time = ["salvo-oapi-macros/time", "dep:time"]
smallvec = ["salvo-oapi-macros/smallvec", "dep:smallvec"]
indexmap = ["salvo-oapi-macros/indexmap"]
yaml = ["dep:serde_yaml"]
yaml = ["dep:serde_norway"]
preserve-order = ["preserve-path-order", "preserve-prop-order"]
preserve-path-order = []
preserve-prop-order = []
compact_str = ["salvo-oapi-macros/compact_str", "dep:compact_str"]

[dependencies]
salvo_core = { workspace = true, default-features = false, features = ["cookie"] }
salvo_core = { workspace = true, default-features = false, features = [
"cookie",
] }
salvo-oapi-macros = { workspace = true, default-features = false }
base64 = { workspace = true }
thiserror = { workspace = true }
Expand All @@ -58,7 +79,7 @@ http = { workspace = true }
chrono = { workspace = true, optional = true }
rust_decimal = { workspace = true, optional = true }
rust-embed = { workspace = true, optional = true }
serde_yaml = { workspace = true, optional = true }
serde_norway = { workspace = true, optional = true }
smallvec = { workspace = true, optional = true }
time = { workspace = true, optional = true }
ulid = { workspace = true, optional = true }
Expand All @@ -75,7 +96,10 @@ rustdoc-args = ["--cfg", "docsrs"]

[dev-dependencies]
assert-json-diff = { workspace = true }
salvo_core = { workspace = true, default-features = false, features = ["cookie", "test"] }
salvo_core = { workspace = true, default-features = false, features = [
"cookie",
"test",
] }
serde_json = { workspace = true }
serde = { workspace = true }
smallvec = { workspace = true, features = ["serde"] }
Expand All @@ -85,4 +109,4 @@ time = { workspace = true, features = ["serde-human-readable"] }
compact_str = { workspace = true, features = ["serde"] }

[lints]
workspace = true
workspace = true
11 changes: 5 additions & 6 deletions crates/oapi/docs/lib.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ you can use to annotate your code to have items documented.

# Crate Features

- **`yaml`** Enables **serde_yaml** serialization of OpenAPI objects.
- **`yaml`** Enables **serde_norway** serialization of OpenAPI objects.

- **`chrono`** Add support for [chrono](https://crates.io/crates/chrono) `DateTime`, `Date`, `NaiveDate` and `Duration`
types. By default these types are parsed to `string` types with additional `format` information.
Expand All @@ -30,12 +30,11 @@ you can use to annotate your code to have items documented.

# Go beyond the surface

* Browse to [examples](https://github.com/salvo-rs/salvo/tree/master/examples) for more comprehensive examples.
* Check [`derive@ToResponses`] and [`derive@ToResponse`] for examples on deriving responses.
* More about OpenAPI security in [security documentation][security].
- Browse to [examples](https://github.com/salvo-rs/salvo/tree/master/examples) for more comprehensive examples.
- Check [`derive@ToResponses`] and [`derive@ToResponse`] for examples on deriving responses.
- More about OpenAPI security in [security documentation][security].

[path]: attr.path.html
[serde]: derive.ToSchema.html#partial-serde-attributes-support

[security]: openapi/security/index.html
[to_schema_derive]: derive.ToSchema.html
[to_schema_derive]: derive.ToSchema.html
6 changes: 3 additions & 3 deletions crates/oapi/src/openapi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ impl OpenApi {

cfg_feature! {
#![feature ="yaml"]
/// Converts this [`OpenApi`] to YAML String. This method essentially calls [`serde_yaml::to_string`] method.
pub fn to_yaml(&self) -> Result<String, serde_yaml::Error> {
serde_yaml::to_string(self)
/// Converts this [`OpenApi`] to YAML String. This method essentially calls [`serde_norway::to_string`] method.
pub fn to_yaml(&self) -> Result<String, serde_norway::Error> {
serde_norway::to_string(self)
}
}

Expand Down

0 comments on commit 5e9c7ef

Please sign in to comment.