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

Add meta and source fields to JSONAPIErrorItem #440

Merged
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
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2025-01-06 18:09:25.627915",
"spec_repo_commit": "c020103f"
"regenerated": "2025-01-06 19:03:06.126054",
"spec_repo_commit": "b56ea2d7"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2025-01-06 18:09:25.643003",
"spec_repo_commit": "c020103f"
"regenerated": "2025-01-06 19:03:06.140967",
"spec_repo_commit": "b56ea2d7"
}
}
}
24 changes: 24 additions & 0 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15109,6 +15109,12 @@ components:
the error.
example: Missing required attribute in body
type: string
meta:
additionalProperties: {}
description: Non-standard meta-information about the error
type: object
source:
$ref: '#/components/schemas/JSONAPIErrorItemSource'
status:
description: Status code of the response.
example: '400'
Expand All @@ -15118,6 +15124,24 @@ components:
example: Bad Request
type: string
type: object
JSONAPIErrorItemSource:
description: References to the source of the error.
properties:
header:
description: A string indicating the name of a single request header which
caused the error.
example: Authorization
type: string
parameter:
description: A string indicating which URI query parameter caused the error.
example: limit
type: string
pointer:
description: A JSON pointer to the value in the request document that caused
the error.
example: /data/attributes/title
type: string
type: object
JSONAPIErrorResponse:
description: API error response.
properties:
Expand Down
2 changes: 2 additions & 0 deletions src/datadogV2/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ pub mod model_jsonapi_error_response;
pub use self::model_jsonapi_error_response::JSONAPIErrorResponse;
pub mod model_jsonapi_error_item;
pub use self::model_jsonapi_error_item::JSONAPIErrorItem;
pub mod model_jsonapi_error_item_source;
pub use self::model_jsonapi_error_item_source::JSONAPIErrorItemSource;
pub mod model_open_api_file;
pub use self::model_open_api_file::OpenAPIFile;
pub mod model_update_open_api_response;
Expand Down
34 changes: 34 additions & 0 deletions src/datadogV2/model/model_jsonapi_error_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ pub struct JSONAPIErrorItem {
/// A human-readable explanation specific to this occurrence of the error.
#[serde(rename = "detail")]
pub detail: Option<String>,
/// Non-standard meta-information about the error
#[serde(rename = "meta")]
pub meta: Option<std::collections::BTreeMap<String, serde_json::Value>>,
/// References to the source of the error.
#[serde(rename = "source")]
pub source: Option<crate::datadogV2::model::JSONAPIErrorItemSource>,
/// Status code of the response.
#[serde(rename = "status")]
pub status: Option<String>,
Expand All @@ -31,6 +37,8 @@ impl JSONAPIErrorItem {
pub fn new() -> JSONAPIErrorItem {
JSONAPIErrorItem {
detail: None,
meta: None,
source: None,
status: None,
title: None,
additional_properties: std::collections::BTreeMap::new(),
Expand All @@ -43,6 +51,16 @@ impl JSONAPIErrorItem {
self
}

pub fn meta(mut self, value: std::collections::BTreeMap<String, serde_json::Value>) -> Self {
self.meta = Some(value);
self
}

pub fn source(mut self, value: crate::datadogV2::model::JSONAPIErrorItemSource) -> Self {
self.source = Some(value);
self
}

pub fn status(mut self, value: String) -> Self {
self.status = Some(value);
self
Expand Down Expand Up @@ -86,6 +104,8 @@ impl<'de> Deserialize<'de> for JSONAPIErrorItem {
M: MapAccess<'a>,
{
let mut detail: Option<String> = None;
let mut meta: Option<std::collections::BTreeMap<String, serde_json::Value>> = None;
let mut source: Option<crate::datadogV2::model::JSONAPIErrorItemSource> = None;
let mut status: Option<String> = None;
let mut title: Option<String> = None;
let mut additional_properties: std::collections::BTreeMap<
Expand All @@ -102,6 +122,18 @@ impl<'de> Deserialize<'de> for JSONAPIErrorItem {
}
detail = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"meta" => {
if v.is_null() {
continue;
}
meta = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"source" => {
if v.is_null() {
continue;
}
source = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"status" => {
if v.is_null() {
continue;
Expand All @@ -124,6 +156,8 @@ impl<'de> Deserialize<'de> for JSONAPIErrorItem {

let content = JSONAPIErrorItem {
detail,
meta,
source,
status,
title,
additional_properties,
Expand Down
139 changes: 139 additions & 0 deletions src/datadogV2/model/model_jsonapi_error_item_source.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.
use serde::de::{Error, MapAccess, Visitor};
use serde::{Deserialize, Deserializer, Serialize};
use serde_with::skip_serializing_none;
use std::fmt::{self, Formatter};

/// References to the source of the error.
#[non_exhaustive]
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct JSONAPIErrorItemSource {
/// A string indicating the name of a single request header which caused the error.
#[serde(rename = "header")]
pub header: Option<String>,
/// A string indicating which URI query parameter caused the error.
#[serde(rename = "parameter")]
pub parameter: Option<String>,
/// A JSON pointer to the value in the request document that caused the error.
#[serde(rename = "pointer")]
pub pointer: Option<String>,
#[serde(flatten)]
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
#[serde(skip)]
#[serde(default)]
pub(crate) _unparsed: bool,
}

impl JSONAPIErrorItemSource {
pub fn new() -> JSONAPIErrorItemSource {
JSONAPIErrorItemSource {
header: None,
parameter: None,
pointer: None,
additional_properties: std::collections::BTreeMap::new(),
_unparsed: false,
}
}

pub fn header(mut self, value: String) -> Self {
self.header = Some(value);
self
}

pub fn parameter(mut self, value: String) -> Self {
self.parameter = Some(value);
self
}

pub fn pointer(mut self, value: String) -> Self {
self.pointer = Some(value);
self
}

pub fn additional_properties(
mut self,
value: std::collections::BTreeMap<String, serde_json::Value>,
) -> Self {
self.additional_properties = value;
self
}
}

impl Default for JSONAPIErrorItemSource {
fn default() -> Self {
Self::new()
}
}

impl<'de> Deserialize<'de> for JSONAPIErrorItemSource {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct JSONAPIErrorItemSourceVisitor;
impl<'a> Visitor<'a> for JSONAPIErrorItemSourceVisitor {
type Value = JSONAPIErrorItemSource;

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 header: Option<String> = None;
let mut parameter: Option<String> = None;
let mut pointer: 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() {
"header" => {
if v.is_null() {
continue;
}
header = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"parameter" => {
if v.is_null() {
continue;
}
parameter = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"pointer" => {
if v.is_null() {
continue;
}
pointer = 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 content = JSONAPIErrorItemSource {
header,
parameter,
pointer,
additional_properties,
_unparsed,
};

Ok(content)
}
}

deserializer.deserialize_any(JSONAPIErrorItemSourceVisitor)
}
}
Loading