This repository has been archived by the owner on Oct 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make
openadr-vtn
a dev dependency of openadr-client
- Loading branch information
1 parent
8125b16
commit 7ee3f8e
Showing
10 changed files
with
83 additions
and
70 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,3 @@ pub mod data_source; | |
mod error; | ||
pub mod jwt; | ||
pub mod state; | ||
|
||
pub use error::Problem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use http::StatusCode; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_with::skip_serializing_none; | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] | ||
pub struct ProblemUri(String); | ||
|
||
impl Default for ProblemUri { | ||
fn default() -> Self { | ||
Self("about:blank".to_string()) | ||
} | ||
} | ||
|
||
/// Reusable error response. From <https://opensource.zalando.com/problem/schema.yaml>. | ||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Default)] | ||
#[skip_serializing_none] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Problem { | ||
/// An absolute URI that identifies the problem type. | ||
/// When dereferenced, it SHOULD provide human-readable documentation for the problem type | ||
/// (e.g., using HTML). | ||
#[serde(default)] | ||
pub r#type: ProblemUri, | ||
/// A short, summary of the problem type. | ||
/// Written in english and readable for engineers | ||
/// (usually not suited for non-technical stakeholders and not localized); | ||
/// example: Service Unavailable. | ||
pub title: Option<String>, | ||
/// The HTTP status code generated by the origin server for this occurrence of the problem. | ||
#[serde(with = "status_code_serialization")] | ||
pub status: StatusCode, | ||
/// A human-readable explanation specific to this occurrence of the problem. | ||
pub detail: Option<String>, | ||
/// An absolute URI that identifies the specific occurrence of the problem. | ||
/// It may or may not yield further information if dereferenced. | ||
pub instance: Option<String>, | ||
} | ||
|
||
mod status_code_serialization { | ||
use super::*; | ||
|
||
use serde::de::Unexpected; | ||
use serde::{Deserializer, Serializer}; | ||
|
||
pub fn serialize<S>(code: &StatusCode, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
serializer.serialize_u16(code.as_u16()) | ||
} | ||
|
||
pub fn deserialize<'de, D>(deserializer: D) -> Result<StatusCode, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
u16::deserialize(deserializer).and_then(|code| { | ||
StatusCode::from_u16(code).map_err(|_| { | ||
serde::de::Error::invalid_value( | ||
Unexpected::Unsigned(code as u64), | ||
&"Valid http status code", | ||
) | ||
}) | ||
}) | ||
} | ||
} |