use serde::de::{Error, MapAccess, Visitor};
use serde::{Deserialize, Deserializer, Serialize};
use serde_with::skip_serializing_none;
use std::fmt::{self, Formatter};
#[non_exhaustive]
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct OAuthClientRegistrationRequest {
#[serde(rename = "client_name")]
pub client_name: String,
#[serde(rename = "client_uri")]
pub client_uri: Option<String>,
#[serde(rename = "grant_types")]
pub grant_types: Option<Vec<crate::datadogV2::model::OAuthClientRegistrationGrantType>>,
#[serde(rename = "jwks_uri")]
pub jwks_uri: Option<String>,
#[serde(rename = "logo_uri")]
pub logo_uri: Option<String>,
#[serde(rename = "policy_uri")]
pub policy_uri: Option<String>,
#[serde(rename = "redirect_uris")]
pub redirect_uris: Vec<String>,
#[serde(rename = "response_types")]
pub response_types: Option<Vec<crate::datadogV2::model::OAuthClientRegistrationResponseType>>,
#[serde(rename = "scope")]
pub scope: Option<String>,
#[serde(rename = "token_endpoint_auth_method")]
pub token_endpoint_auth_method: Option<String>,
#[serde(rename = "tos_uri")]
pub tos_uri: Option<String>,
#[serde(flatten)]
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
#[serde(skip)]
#[serde(default)]
pub(crate) _unparsed: bool,
}
impl OAuthClientRegistrationRequest {
pub fn new(client_name: String, redirect_uris: Vec<String>) -> OAuthClientRegistrationRequest {
OAuthClientRegistrationRequest {
client_name,
client_uri: None,
grant_types: None,
jwks_uri: None,
logo_uri: None,
policy_uri: None,
redirect_uris,
response_types: None,
scope: None,
token_endpoint_auth_method: None,
tos_uri: None,
additional_properties: std::collections::BTreeMap::new(),
_unparsed: false,
}
}
pub fn client_uri(mut self, value: String) -> Self {
self.client_uri = Some(value);
self
}
pub fn grant_types(
mut self,
value: Vec<crate::datadogV2::model::OAuthClientRegistrationGrantType>,
) -> Self {
self.grant_types = Some(value);
self
}
pub fn jwks_uri(mut self, value: String) -> Self {
self.jwks_uri = Some(value);
self
}
pub fn logo_uri(mut self, value: String) -> Self {
self.logo_uri = Some(value);
self
}
pub fn policy_uri(mut self, value: String) -> Self {
self.policy_uri = Some(value);
self
}
pub fn response_types(
mut self,
value: Vec<crate::datadogV2::model::OAuthClientRegistrationResponseType>,
) -> Self {
self.response_types = Some(value);
self
}
pub fn scope(mut self, value: String) -> Self {
self.scope = Some(value);
self
}
pub fn token_endpoint_auth_method(mut self, value: String) -> Self {
self.token_endpoint_auth_method = Some(value);
self
}
pub fn tos_uri(mut self, value: String) -> Self {
self.tos_uri = Some(value);
self
}
pub fn additional_properties(
mut self,
value: std::collections::BTreeMap<String, serde_json::Value>,
) -> Self {
self.additional_properties = value;
self
}
}
impl<'de> Deserialize<'de> for OAuthClientRegistrationRequest {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct OAuthClientRegistrationRequestVisitor;
impl<'a> Visitor<'a> for OAuthClientRegistrationRequestVisitor {
type Value = OAuthClientRegistrationRequest;
fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("a mapping")
}
fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
where
M: MapAccess<'a>,
{
let mut client_name: Option<String> = None;
let mut client_uri: Option<String> = None;
let mut grant_types: Option<
Vec<crate::datadogV2::model::OAuthClientRegistrationGrantType>,
> = None;
let mut jwks_uri: Option<String> = None;
let mut logo_uri: Option<String> = None;
let mut policy_uri: Option<String> = None;
let mut redirect_uris: Option<Vec<String>> = None;
let mut response_types: Option<
Vec<crate::datadogV2::model::OAuthClientRegistrationResponseType>,
> = None;
let mut scope: Option<String> = None;
let mut token_endpoint_auth_method: Option<String> = None;
let mut tos_uri: Option<String> = None;
let mut additional_properties: std::collections::BTreeMap<
String,
serde_json::Value,
> = std::collections::BTreeMap::new();
let mut _unparsed = false;
while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
match k.as_str() {
"client_name" => {
client_name =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"client_uri" => {
if v.is_null() {
continue;
}
client_uri = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"grant_types" => {
if v.is_null() {
continue;
}
grant_types =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"jwks_uri" => {
if v.is_null() {
continue;
}
jwks_uri = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"logo_uri" => {
if v.is_null() {
continue;
}
logo_uri = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"policy_uri" => {
if v.is_null() {
continue;
}
policy_uri = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"redirect_uris" => {
redirect_uris =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"response_types" => {
if v.is_null() {
continue;
}
response_types =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"scope" => {
if v.is_null() {
continue;
}
scope = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"token_endpoint_auth_method" => {
if v.is_null() {
continue;
}
token_endpoint_auth_method =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"tos_uri" => {
if v.is_null() {
continue;
}
tos_uri = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
&_ => {
if let Ok(value) = serde_json::from_value(v.clone()) {
additional_properties.insert(k, value);
}
}
}
}
let client_name =
client_name.ok_or_else(|| M::Error::missing_field("client_name"))?;
let redirect_uris =
redirect_uris.ok_or_else(|| M::Error::missing_field("redirect_uris"))?;
let content = OAuthClientRegistrationRequest {
client_name,
client_uri,
grant_types,
jwks_uri,
logo_uri,
policy_uri,
redirect_uris,
response_types,
scope,
token_endpoint_auth_method,
tos_uri,
additional_properties,
_unparsed,
};
Ok(content)
}
}
deserializer.deserialize_any(OAuthClientRegistrationRequestVisitor)
}
}