Compilation error: codegen emits the code for optional api version, when it is not

Open
#920 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
rust
Domain
tooling

Research direction

Start with specification/purview/data-plane/datamap and inspect the generated spec/datamap/src/generated/clients/data_map_discovery_client.rs around the api_version declaration and auto_complete method. Trace the code-generation entry point that produces this client, then regenerate the output and compile it to confirm the optional API-version handling is consistent.

Written by the indexing model from the issue text.

Description

This affects specification/purview/data-plane/datamap:

error[E0277]: the trait bound `std::string::String: AsRef<std::option::Option<_>>` is not satisfied
  --> spec\datamap\src\generated\clients\data_map_discovery_client.rs:47:53
   |
47 |         if let Some(api_version) = self.api_version.as_ref() {
   |                                                     ^^^^^^ the trait `AsRef<std::option::Option<_>>` is not implemented for `std::string::String`
   |
   = help: the following other types implement trait `AsRef<T>`:
             `std::string::String` implements `AsRef<OsStr>`
             `std::string::String` implements `AsRef<Path>`
             `std::string::String` implements `AsRef<[u8]>`
             `std::string::String` implements `AsRef<str>`

when

...
#[tracing::client]
pub struct DataMapDiscoveryClient {
    pub(crate) api_version: String, // <-- declared here
    pub(crate) endpoint: Url,
    pub(crate) pipeline: Pipeline,
}

impl DataMapDiscoveryClient {
    ...
    #[tracing::function("Customizations.Discovery.autoComplete")]
    pub async fn auto_complete(
        &self,
        body: RequestContent<AutoCompleteOptions>,
        options: Option<DataMapDiscoveryClientAutoCompleteOptions<'_>>,
    ) -> Result<Response<AutoCompleteResult>> {
        let options = options.unwrap_or_default();
        let ctx = options.method_options.context.to_borrowed();
        let mut url = self.endpoint.clone();
        url.append_path("/search/autocomplete");
        let mut query_builder = url.query_builder();
        if let Some(api_version) = self.api_version.as_ref() { // <--fails here
            query_builder.set_pair("api-version", api_version);
        }
        ...

Dominant language
Rust
Stars
7
Forks
11
Avg merge
14h 15m
Merged PRs (30d)
6

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Azure/typespec-rust

All issues in Azure/typespec-rust

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.