Skip to content

[Storage] Augment return type from Response<ListOfSentMessage, ...> -> Response<SentMessage, ...> #868

@vincenttran-msft

Description

@vincenttran-msft

Currently, the send_message API is defined as follows:

 pub async fn send_message(
        &self,
        queue_message: RequestContent<QueueMessage, XmlFormat>,
        options: Option<QueueClientSendMessageOptions<'_>>,
    ) -> Result<Response<SentMessage, XmlFormat>> {
        let response = self.client.send_message(queue_message, options).await?;

        Self::extract_first_message(response, |list: &ListOfSentMessage| {
            list.items.clone().unwrap_or_default()
        })
        .await
    }

This is because the underlying generated function is defined as:

pub async fn send_message(
        &self,
        queue_message: RequestContent<QueueMessage, XmlFormat>,
        options: Option<QueueClientSendMessageInternalOptions<'_>>,
    ) -> Result<Response<ListOfSentMessage, XmlFormat>> {

So the feature request is whether there is anyway we can define something, similar to alternateType, but we would want to be able to define in this case:

  1. Turn send_message return type from ListOfSentMessage to SentMessage
  2. We can define the conversion function in handwritten code to go from ListOfSentMessage -> SentMessage

We just want to be able to define this sort of behavior without having to maintain the handwritten layer just for this functionality.

For completeness, this is the current implementation of extract_first_message() which is what we currently use to do the repacking to the desired return type:

async fn extract_first_sent_message(
        response: Response<ListOfSentMessage, XmlFormat>,
    ) -> Result<Response<SentMessage, XmlFormat>> {
        let status = response.status();
        let headers = response.headers().clone();
        let list = response.into_model()?;
        let first = list
            .items
            .unwrap_or_default()
            .into_iter()
            .next()
            .ok_or_else(|| {
                azure_core::Error::with_message(
                    azure_core::error::ErrorKind::DataConversion,
                    "No messages found in the response.",
                )
            })?;
        let xml_body = xml::to_xml(&first)?;
        Ok(RawResponse::from_bytes(status, headers, xml_body).into())
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    CodeGenIssues that relate to code generationfeature-requestThis issue requires a new behavior in the product in order be resolved.

    Projects

    Status

    Untriaged

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions