Skip to content

Commit

Permalink
Merge branch 'master' into sherz/remove-x-alias-usage
Browse files Browse the repository at this point in the history
  • Loading branch information
skarimo authored Feb 29, 2024
2 parents 4ceb93a + 0fbeb75 commit 6753630
Show file tree
Hide file tree
Showing 78 changed files with 10,288 additions and 4,752 deletions.
28 changes: 20 additions & 8 deletions .generator/src/generator/templates/api.j2
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,19 @@ impl {{ structName }} {
{% if operation.description is defined %}
{{ operation.description | block_comment }}
{%- endif %}
pub async fn {{operation.operationId | snake_case}}(&self{% for name, parameter in requiredParams %}, {{name|variable_name}}: {{ get_type_for_parameter(parameter, version) }}{% endfor %}{% if operation|has_optional_parameter %}, params: {{operation.operationId}}OptionalParams{% endif %}) -> Result<Option<{% if returnType %}{{returnType}}{% else %}(){% endif %}>, Error<{{operation.operationId}}Error>> {
pub async fn {{operation.operationId | snake_case}}(&self{% for name, parameter in requiredParams %}, {{name|variable_name}}: {{ get_type_for_parameter(parameter, version) }}{% endfor %}{% if operation|has_optional_parameter %}, params: {{operation.operationId}}OptionalParams{% endif %}) -> Result<{% if returnType %}{{returnType}}{% else %}(){% endif %}, Error<{{operation.operationId}}Error>> {
match self.{{operation.operationId | snake_case}}_with_http_info({% for name, parameter in requiredParams %}{{name|variable_name}}{% if loop.last %}{% if operation|has_optional_parameter %}, {% endif %}{% else %}, {% endif %}{% endfor %}{% if operation|has_optional_parameter %} params{% endif %}).await {
Ok(response_content) => Ok(response_content.entity),
{%- if returnType %}
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(Error::Serde(serde::de::Error::custom("response content was None")))
}
},
{%- else%}
Ok(_) => Ok(()),
{%- endif%}
Err(err) => Err(err),
}
}
Expand Down Expand Up @@ -220,12 +230,14 @@ impl {{ structName }} {

if !local_status.is_client_error() && !local_status.is_server_error() {
{%- if returnType %}
let local_entity: Option<{{returnType}}> = serde_json::from_str(&local_content).ok();
Ok(ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
})
match serde_json::from_str::<{{ returnType }}>(&local_content) {
Ok(e) => return Ok(ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
}),
Err(e) => return Err(crate::datadog::Error::Serde(e)),
};
{%- else %}
Ok(ResponseContent {
status: local_status,
Expand Down
35 changes: 23 additions & 12 deletions src/datadogV1/api/api_authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ impl AuthenticationAPI {
/// Check if the API key (not the APP key) is valid. If invalid, a 403 is returned.
pub async fn validate(
&self,
) -> Result<
Option<crate::datadogV1::model::AuthenticationValidationResponse>,
Error<ValidateError>,
> {
) -> Result<crate::datadogV1::model::AuthenticationValidationResponse, Error<ValidateError>>
{
match self.validate_with_http_info().await {
Ok(response_content) => Ok(response_content.entity),
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
Expand Down Expand Up @@ -85,13 +91,18 @@ impl AuthenticationAPI {
let local_content = local_resp.text().await?;

if !local_status.is_client_error() && !local_status.is_server_error() {
let local_entity: Option<crate::datadogV1::model::AuthenticationValidationResponse> =
serde_json::from_str(&local_content).ok();
Ok(ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
})
match serde_json::from_str::<crate::datadogV1::model::AuthenticationValidationResponse>(
&local_content,
) {
Ok(e) => {
return Ok(ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(crate::datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<ValidateError> = serde_json::from_str(&local_content).ok();
let local_error = ResponseContent {
Expand Down
Loading

0 comments on commit 6753630

Please sign in to comment.