Skip to content

Commit

Permalink
update changelog
Browse files Browse the repository at this point in the history
rustfmt
  • Loading branch information
sunli829 committed Nov 18, 2023
1 parent fa658fc commit 4dc9a6a
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 107 deletions.
5 changes: 5 additions & 0 deletions poem-openapi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

# [3.0.6] 2023-09-07

- add [`prost-wkt-types` crate](https://crates.io/crates/prost-wkt-types) support [#689](https://github.com/poem-web/poem/pull/689)
- add [`geo-types` crate](https://crates.io/crates/geo-types) support [#693](https://github.com/poem-web/poem/pull/693)
- count string length correctly in OpenAPI validators [#666](https://github.com/poem-web/poem/pull/666)
- Support for custom hash functions for HashMap/HashSet [#654](https://github.com/poem-web/poem/pull/654)
- Misplaced `</html>`` in swagger_ui HTML template [#660](https://github.com/poem-web/poem/issues/660)
- for `read-only` properties, can use `default` to specify a function for creating a default value. [#647](https://github.com/poem-web/poem/issues/647)

```rust
Expand Down
37 changes: 19 additions & 18 deletions poem-openapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,25 @@ important business implementations.

To avoid compiling unused dependencies, Poem gates certain features, some of which are disabled by default:

| Feature | Description |
|------------------|----------------------------------------------------------------------------------|
| chrono | Integrate with the [`chrono` crate](https://crates.io/crates/chrono). |
| time | Integrate with the [`time` crate](https://crates.io/crates/time). |
| humantime | Integrate with the [`humantime` crate](https://crates.io/crates/humantime) |
| openapi-explorer | Add OpenAPI Explorer support |
| swagger-ui | Add swagger UI support |
| rapidoc | Add RapiDoc UI support |
| redoc | Add Redoc UI support |
| email | Support for email address string |
| hostname | Support for hostname string |
| uuid | Integrate with the [`uuid` crate](https://crates.io/crates/uuid) |
| url | Integrate with the [`url` crate](https://crates.io/crates/url) |
| geo | Integrate with the [`geo-types` crate](https://crates.io/crates/geo-types) |
| bson | Integrate with the [`bson` crate](https://crates.io/crates/bson) |
| rust_decimal | Integrate with the [`rust_decimal` crate](https://crates.io/crates/rust_decimal) |
| static-files | Support for static file response |
| websocket | Support for websocket |
| Feature | Description |
|------------------|----------------------------------------------------------------------------------------|
| chrono | Integrate with the [`chrono` crate](https://crates.io/crates/chrono). |
| time | Integrate with the [`time` crate](https://crates.io/crates/time). |
| humantime | Integrate with the [`humantime` crate](https://crates.io/crates/humantime) |
| openapi-explorer | Add OpenAPI Explorer support |
| swagger-ui | Add swagger UI support |
| rapidoc | Add RapiDoc UI support |
| redoc | Add Redoc UI support |
| email | Support for email address string |
| hostname | Support for hostname string |
| uuid | Integrate with the [`uuid` crate](https://crates.io/crates/uuid) |
| url | Integrate with the [`url` crate](https://crates.io/crates/url) |
| geo | Integrate with the [`geo-types` crate](https://crates.io/crates/geo-types) |
| bson | Integrate with the [`bson` crate](https://crates.io/crates/bson) |
| rust_decimal | Integrate with the [`rust_decimal` crate](https://crates.io/crates/rust_decimal) |
| prost-wkt-types | Integrate with the [`prost-wkt-types` crate](https://crates.io/crates/prost-wkt-types) |
| static-files | Support for static file response |
| websocket | Support for websocket |

## Safety

Expand Down
35 changes: 19 additions & 16 deletions poem-openapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,25 @@
//! To avoid compiling unused dependencies, Poem gates certain features, some of
//! which are disabled by default:
//!
//! | Feature | Description |
//! |------------|-----------------------------------------------------------------------|
//! | chrono | Integrate with the [`chrono` crate](https://crates.io/crates/chrono) |
//! | time | Integrate with the [`time` crate](https://crates.io/crates/time). |
//! | humantime | Integrate with the [`humantime` crate](https://crates.io/crates/humantime) |
//! | openapi-explorer | Add OpenAPI Explorer support |
//! | swagger-ui | Add swagger UI support |
//! | rapidoc | Add RapiDoc UI support |
//! | redoc | Add Redoc UI support |
//! | email | Support for email address string |
//! | hostname | Support for hostname string |
//! | uuid | Integrate with the [`uuid` crate](https://crates.io/crates/uuid)|
//! | url | Integrate with the [`url` crate](https://crates.io/crates/url) |
//! | bson | Integrate with the [`bson` crate](https://crates.io/crates/bson) |
//! | rust_decimal | Integrate with the [`rust_decimal` crate](https://crates.io/crates/rust_decimal) |
//! | static-files | Support for static file response |
//! | Feature | Description |
//! |------------------|----------------------------------------------------------------------------------------|
//! | chrono | Integrate with the [`chrono` crate](https://crates.io/crates/chrono). |
//! | time | Integrate with the [`time` crate](https://crates.io/crates/time). |
//! | humantime | Integrate with the [`humantime` crate](https://crates.io/crates/humantime) |
//! | openapi-explorer | Add OpenAPI Explorer support |
//! | swagger-ui | Add swagger UI support |
//! | rapidoc | Add RapiDoc UI support |
//! | redoc | Add Redoc UI support |
//! | email | Support for email address string |
//! | hostname | Support for hostname string |
//! | uuid | Integrate with the [`uuid` crate](https://crates.io/crates/uuid) |
//! | url | Integrate with the [`url` crate](https://crates.io/crates/url) |
//! | geo | Integrate with the [`geo-types` crate](https://crates.io/crates/geo-types) |
//! | bson | Integrate with the [`bson` crate](https://crates.io/crates/bson) |
//! | rust_decimal | Integrate with the [`rust_decimal` crate](https://crates.io/crates/rust_decimal) |
//! | prost-wkt-types | Integrate with the [`prost-wkt-types` crate](https://crates.io/crates/prost-wkt-types) |
//! | static-files | Support for static file response |
//! | websocket | Support for websocket |
#![doc(html_favicon_url = "https://raw.githubusercontent.com/poem-web/poem/master/favicon.ico")]
#![doc(html_logo_url = "https://raw.githubusercontent.com/poem-web/poem/master/logo.png")]
Expand Down
4 changes: 2 additions & 2 deletions poem-openapi/src/types/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ mod humantime;
mod integers;
mod ip;
mod optional;
#[cfg(feature = "prost-wkt-types")]
mod prost_wkt_types;
mod regex;
mod slice;
mod string;
Expand All @@ -30,5 +32,3 @@ mod url;
#[cfg(feature = "uuid")]
mod uuid;
mod vec;
#[cfg(feature = "prost-wkt-types")]
mod prost_wkt_types;
2 changes: 1 addition & 1 deletion poem-openapi/src/types/external/prost_wkt_types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mod r#struct;
mod value;
mod value;
41 changes: 20 additions & 21 deletions poem-openapi/src/types/external/prost_wkt_types/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ use std::borrow::Cow;

use prost_wkt_types::Value;

use crate::registry::{MetaSchema, MetaSchemaRef};
use crate::types::{ParseError, ParseFromJSON, ParseResult, ToJSON, Type};
use crate::{
registry::{MetaSchema, MetaSchemaRef},
types::{ParseError, ParseFromJSON, ParseResult, ToJSON, Type},
};

impl Type for prost_wkt_types::Struct {
const IS_REQUIRED: bool = true;
Expand All @@ -29,7 +31,7 @@ impl Type for prost_wkt_types::Struct {

fn raw_element_iter<'a>(
&'a self,
) -> Box<dyn Iterator<Item=&'a Self::RawElementValueType> + 'a> {
) -> Box<dyn Iterator<Item = &'a Self::RawElementValueType> + 'a> {
self.fields.raw_element_iter()
}

Expand All @@ -42,7 +44,8 @@ impl ParseFromJSON for prost_wkt_types::Struct {
fn parse_from_json(value: Option<serde_json::Value>) -> ParseResult<Self> {
let value = value.unwrap_or_default();
if let serde_json::Value::Object(_) = &value {
serde_json::from_value::<prost_wkt_types::Struct>(value).map_err(|e| ParseError::custom(e.to_string()))
serde_json::from_value::<prost_wkt_types::Struct>(value)
.map_err(|e| ParseError::custom(e.to_string()))
} else {
Err(ParseError::expected_type(value))
}
Expand Down Expand Up @@ -75,7 +78,8 @@ mod tests {
"f5": {"fa": "Hello"},
"f6": [1,2,3]
}
))).unwrap();
)))
.unwrap();

assert_eq!(
prost_struct.fields.get("f1").unwrap(),
Expand All @@ -85,27 +89,22 @@ mod tests {
prost_struct.fields.get("f2").unwrap(),
&Value::string("Hi".to_string())
);
assert_eq!(
prost_struct.fields.get("f3").unwrap(),
&Value::bool(true)
);
assert_eq!(
prost_struct.fields.get("f4").unwrap(),
&Value::null()
);
assert_eq!(prost_struct.fields.get("f3").unwrap(), &Value::bool(true));
assert_eq!(prost_struct.fields.get("f4").unwrap(), &Value::null());
assert_eq!(
prost_struct.fields.get("f5").unwrap(),
&Value::pb_struct(
HashMap::from([("fa".into(), Value::string("Hello".into()))])
)
&Value::pb_struct(HashMap::from([(
"fa".into(),
Value::string("Hello".into())
)]))
);
assert_eq!(
prost_struct.fields.get("f6").unwrap(),
&Value::pb_list(
vec![Value::number(1_f64),
Value::number(2_f64),
Value::number(3_f64)]
)
&Value::pb_list(vec![
Value::number(1_f64),
Value::number(2_f64),
Value::number(3_f64)
])
);
}
}
72 changes: 25 additions & 47 deletions poem-openapi/src/types/external/prost_wkt_types/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ use std::borrow::Cow;

use prost_wkt_types::value::Kind;

use crate::registry::{MetaSchema, MetaSchemaRef};
use crate::types::{ParseError, ParseFromJSON, ParseResult, ToJSON, Type};
use crate::{
registry::{MetaSchema, MetaSchemaRef},
types::{ParseError, ParseFromJSON, ParseResult, ToJSON, Type},
};

impl Type for prost_wkt_types::Value {
const IS_REQUIRED: bool = true;
Expand All @@ -26,15 +28,14 @@ impl Type for prost_wkt_types::Value {

fn raw_element_iter<'a>(
&'a self,
) -> Box<dyn Iterator<Item=&'a Self::RawElementValueType> + 'a> {
) -> Box<dyn Iterator<Item = &'a Self::RawElementValueType> + 'a> {
Box::new(self.as_raw_value().into_iter())
}
fn is_empty(&self) -> bool {
matches!(self.kind, Some(Kind::NullValue(_)) | None)
}
}


impl ParseFromJSON for prost_wkt_types::Value {
fn parse_from_json(value: Option<serde_json::Value>) -> ParseResult<Self> {
let value = value.unwrap_or_default();
Expand All @@ -59,73 +60,50 @@ mod tests {

#[test]
fn parse_from_number() {
let value = Value::parse_from_json(Some(
json!(10_f64)
)).unwrap();
assert_eq!(
value,
Value::number(10_f64)
);
let value = Value::parse_from_json(Some(json!(10_f64))).unwrap();
assert_eq!(value, Value::number(10_f64));
}

#[test]
fn parse_from_string() {
let value = Value::parse_from_json(Some(
json!("Hi")
)).unwrap();
assert_eq!(
value,
Value::string("Hi".into())
);
let value = Value::parse_from_json(Some(json!("Hi"))).unwrap();
assert_eq!(value, Value::string("Hi".into()));
}

#[test]
fn parse_from_bool() {
let value = Value::parse_from_json(Some(
json!(true)
)).unwrap();
assert_eq!(
value,
Value::bool(true)
);
let value = Value::parse_from_json(Some(json!(true))).unwrap();
assert_eq!(value, Value::bool(true));
}

#[test]
fn parse_from_null() {
let value = Value::parse_from_json(Some(
json!(null)
)).unwrap();
assert_eq!(
value,
Value::null()
);
let value = Value::parse_from_json(Some(json!(null))).unwrap();
assert_eq!(value, Value::null());
}

#[test]
fn parse_from_struct() {
let value = Value::parse_from_json(Some(
json!({"f1": "Hello"})
)).unwrap();
let value = Value::parse_from_json(Some(json!({"f1": "Hello"}))).unwrap();
assert_eq!(
value,
Value::pb_struct(
HashMap::from([("f1".into(), Value::string("Hello".into()))])
)
Value::pb_struct(HashMap::from([(
"f1".into(),
Value::string("Hello".into())
)]))
);
}

#[test]
fn parse_from_list() {
let value = Value::parse_from_json(Some(
json!([1,2,3])
)).unwrap();
let value = Value::parse_from_json(Some(json!([1, 2, 3]))).unwrap();
assert_eq!(
value,
Value::pb_list(
vec![Value::number(1_f64),
Value::number(2_f64),
Value::number(3_f64)]
)
Value::pb_list(vec![
Value::number(1_f64),
Value::number(2_f64),
Value::number(3_f64)
])
);
}
}
}
6 changes: 6 additions & 0 deletions poem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# [1.3.59] 2023-11-18

- added permissions and owner to UnixListener [#668](https://github.com/poem-web/poem/pull/668)
- In the examples, listen on `0.0.0.0`` instead of `127.0.0.1``[#672](https://github.com/poem-web/poem/pull/672)


# [1.3.58] 2023-09-02

- bump `rust-embed` from `6.3` to `8.0`
Expand Down
3 changes: 1 addition & 2 deletions poem/src/listener/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use std::{
};

use http::uri::Scheme;
use nix::unistd::chown;
use nix::unistd::{Gid, Uid};
use nix::unistd::{chown, Gid, Uid};
use tokio::{
io::Result as IoResult,
net::{UnixListener as TokioUnixListener, UnixStream},
Expand Down

0 comments on commit 4dc9a6a

Please sign in to comment.