diff --git a/packages/typespec-rust/.scripts/tspcompile.js b/packages/typespec-rust/.scripts/tspcompile.js index 6f792d8fc..31db13687 100644 --- a/packages/typespec-rust/.scripts/tspcompile.js +++ b/packages/typespec-rust/.scripts/tspcompile.js @@ -75,7 +75,7 @@ const httpSpecsGroup = { }; const azureHttpSpecsGroup = { - //'spector_access': {input: 'azure/client-generator-core/access'}, + 'spector_access': {input: 'azure/client-generator-core/access'}, 'spector_apiverheader': {input: 'azure/client-generator-core/api-version/header/client.tsp'}, 'spector_apiverpath': {input: 'azure/client-generator-core/api-version/path/client.tsp'}, 'spector_apiverquery': {input: 'azure/client-generator-core/api-version/query/client.tsp'}, diff --git a/packages/typespec-rust/test/Cargo.lock b/packages/typespec-rust/test/Cargo.lock index acce552de..46827a0dc 100644 --- a/packages/typespec-rust/test/Cargo.lock +++ b/packages/typespec-rust/test/Cargo.lock @@ -1464,6 +1464,15 @@ dependencies = [ "windows-sys 0.60.2", ] +[[package]] +name = "spector_access" +version = "0.1.0" +dependencies = [ + "azure_core", + "serde", + "tokio", +] + [[package]] name = "spector_apikey" version = "0.1.0" diff --git a/packages/typespec-rust/test/Cargo.toml b/packages/typespec-rust/test/Cargo.toml index 76d5b7a06..61ff40a24 100644 --- a/packages/typespec-rust/test/Cargo.toml +++ b/packages/typespec-rust/test/Cargo.toml @@ -16,6 +16,7 @@ members = [ "spector/authentication/http/custom", "spector/authentication/oauth2", "spector/authentication/union", + "spector/azure/client-generator-core/access", "spector/azure/client-generator-core/api-version/header", "spector/azure/client-generator-core/api-version/path", "spector/azure/client-generator-core/api-version/query", diff --git a/packages/typespec-rust/test/spector/azure/client-generator-core/access/Cargo.toml b/packages/typespec-rust/test/spector/azure/client-generator-core/access/Cargo.toml new file mode 100644 index 000000000..946bd81ae --- /dev/null +++ b/packages/typespec-rust/test/spector/azure/client-generator-core/access/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "spector_access" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +rust-version.workspace = true + +[features] +default = ["azure_core/default"] + +[dependencies] +azure_core = { workspace = true } +serde = { workspace = true } + +[dev-dependencies] +tokio = { workspace = true } diff --git a/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/clients/access_client.rs b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/clients/access_client.rs new file mode 100644 index 000000000..d5db5a014 --- /dev/null +++ b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/clients/access_client.rs @@ -0,0 +1,107 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) Rust Code Generator. DO NOT EDIT. + +use crate::generated::clients::{ + AccessInternalOperationClient, AccessPublicOperationClient, + AccessRelativeModelInOperationClient, AccessSharedModelInOperationClient, +}; +use azure_core::{ + fmt::SafeDebug, + http::{ClientOptions, Pipeline, Url}, + tracing, Result, +}; + +/// Test for internal decorator. +#[tracing::client] +pub struct AccessClient { + pub(crate) endpoint: Url, + pub(crate) pipeline: Pipeline, +} + +/// Options used when creating a [`AccessClient`](AccessClient) +#[derive(Clone, Default, SafeDebug)] +pub struct AccessClientOptions { + /// Allows customization of the client. + pub client_options: ClientOptions, +} + +impl AccessClient { + /// Creates a new AccessClient requiring no authentication. + /// + /// # Arguments + /// + /// * `endpoint` - Service host + /// * `options` - Optional configuration for the client. + #[tracing::new("_Specs_.Azure.ClientGenerator.Core.Access")] + pub fn with_no_credential( + endpoint: &str, + options: Option, + ) -> Result { + let options = options.unwrap_or_default(); + let endpoint = Url::parse(endpoint)?; + if !endpoint.scheme().starts_with("http") { + return Err(azure_core::Error::with_message( + azure_core::error::ErrorKind::Other, + format!("{endpoint} must use http(s)"), + )); + } + Ok(Self { + endpoint, + pipeline: Pipeline::new( + option_env!("CARGO_PKG_NAME"), + option_env!("CARGO_PKG_VERSION"), + options.client_options, + Vec::default(), + Vec::default(), + None, + ), + }) + } + + /// Returns the Url associated with this client. + pub fn endpoint(&self) -> &Url { + &self.endpoint + } + + /// Returns a new instance of AccessInternalOperationClient. + #[tracing::subclient] + pub fn get_access_internal_operation_client(&self) -> AccessInternalOperationClient { + AccessInternalOperationClient { + endpoint: self.endpoint.clone(), + pipeline: self.pipeline.clone(), + } + } + + /// Returns a new instance of AccessPublicOperationClient. + #[tracing::subclient] + pub fn get_access_public_operation_client(&self) -> AccessPublicOperationClient { + AccessPublicOperationClient { + endpoint: self.endpoint.clone(), + pipeline: self.pipeline.clone(), + } + } + + /// Returns a new instance of AccessRelativeModelInOperationClient. + #[tracing::subclient] + pub fn get_access_relative_model_in_operation_client( + &self, + ) -> AccessRelativeModelInOperationClient { + AccessRelativeModelInOperationClient { + endpoint: self.endpoint.clone(), + pipeline: self.pipeline.clone(), + } + } + + /// Returns a new instance of AccessSharedModelInOperationClient. + #[tracing::subclient] + pub fn get_access_shared_model_in_operation_client( + &self, + ) -> AccessSharedModelInOperationClient { + AccessSharedModelInOperationClient { + endpoint: self.endpoint.clone(), + pipeline: self.pipeline.clone(), + } + } +} diff --git a/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/clients/access_internal_operation_client.rs b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/clients/access_internal_operation_client.rs new file mode 100644 index 000000000..0557700eb --- /dev/null +++ b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/clients/access_internal_operation_client.rs @@ -0,0 +1,146 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) Rust Code Generator. DO NOT EDIT. + +use crate::generated::models::{ + AccessInternalOperationClientInternalDecoratorInInternalOptions, + AccessInternalOperationClientNoDecoratorInInternalOptions, + AccessInternalOperationClientPublicDecoratorInInternalOptions, + InternalDecoratorModelInInternal, NoDecoratorModelInInternal, PublicDecoratorModelInInternal, +}; +use azure_core::{ + error::CheckSuccessOptions, + http::{Method, Pipeline, PipelineSendOptions, Request, Response, Url, UrlExt}, + tracing, Result, +}; + +#[tracing::client] +pub struct AccessInternalOperationClient { + pub(crate) endpoint: Url, + pub(crate) pipeline: Pipeline, +} + +impl AccessInternalOperationClient { + /// Returns the Url associated with this client. + pub fn endpoint(&self) -> &Url { + &self.endpoint + } + + /// + /// # Arguments + /// + /// * `options` - Optional parameters for the request. + #[tracing::function( + "_Specs_.Azure.ClientGenerator.Core.Access.InternalOperation.internalDecoratorInInternal" + )] + pub(crate) async fn internal_decorator_in_internal( + &self, + name: &str, + options: Option>, + ) -> Result> { + let options = options.unwrap_or_default(); + let ctx = options.method_options.context.to_borrowed(); + let mut url = self.endpoint.clone(); + url.append_path( + "/azure/client-generator-core/access/internalOperation/internalDecoratorInInternal", + ); + let mut query_builder = url.query_builder(); + query_builder.set_pair("name", name); + query_builder.build(); + let mut request = Request::new(url, Method::Get); + request.insert_header("accept", "application/json"); + let rsp = self + .pipeline + .send( + &ctx, + &mut request, + Some(PipelineSendOptions { + check_success: CheckSuccessOptions { + success_codes: &[200], + }, + ..Default::default() + }), + ) + .await?; + Ok(rsp.into()) + } + + /// + /// # Arguments + /// + /// * `options` - Optional parameters for the request. + #[tracing::function( + "_Specs_.Azure.ClientGenerator.Core.Access.InternalOperation.noDecoratorInInternal" + )] + pub(crate) async fn no_decorator_in_internal( + &self, + name: &str, + options: Option>, + ) -> Result> { + let options = options.unwrap_or_default(); + let ctx = options.method_options.context.to_borrowed(); + let mut url = self.endpoint.clone(); + url.append_path( + "/azure/client-generator-core/access/internalOperation/noDecoratorInInternal", + ); + let mut query_builder = url.query_builder(); + query_builder.set_pair("name", name); + query_builder.build(); + let mut request = Request::new(url, Method::Get); + request.insert_header("accept", "application/json"); + let rsp = self + .pipeline + .send( + &ctx, + &mut request, + Some(PipelineSendOptions { + check_success: CheckSuccessOptions { + success_codes: &[200], + }, + ..Default::default() + }), + ) + .await?; + Ok(rsp.into()) + } + + /// + /// # Arguments + /// + /// * `options` - Optional parameters for the request. + #[tracing::function( + "_Specs_.Azure.ClientGenerator.Core.Access.InternalOperation.publicDecoratorInInternal" + )] + pub(crate) async fn public_decorator_in_internal( + &self, + name: &str, + options: Option>, + ) -> Result> { + let options = options.unwrap_or_default(); + let ctx = options.method_options.context.to_borrowed(); + let mut url = self.endpoint.clone(); + url.append_path( + "/azure/client-generator-core/access/internalOperation/publicDecoratorInInternal", + ); + let mut query_builder = url.query_builder(); + query_builder.set_pair("name", name); + query_builder.build(); + let mut request = Request::new(url, Method::Get); + request.insert_header("accept", "application/json"); + let rsp = self + .pipeline + .send( + &ctx, + &mut request, + Some(PipelineSendOptions { + check_success: CheckSuccessOptions { + success_codes: &[200], + }, + ..Default::default() + }), + ) + .await?; + Ok(rsp.into()) + } +} diff --git a/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/clients/access_public_operation_client.rs b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/clients/access_public_operation_client.rs new file mode 100644 index 000000000..3e8527f65 --- /dev/null +++ b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/clients/access_public_operation_client.rs @@ -0,0 +1,104 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) Rust Code Generator. DO NOT EDIT. + +use crate::generated::models::{ + AccessPublicOperationClientNoDecoratorInPublicOptions, + AccessPublicOperationClientPublicDecoratorInPublicOptions, NoDecoratorModelInPublic, + PublicDecoratorModelInPublic, +}; +use azure_core::{ + error::CheckSuccessOptions, + http::{Method, Pipeline, PipelineSendOptions, Request, Response, Url, UrlExt}, + tracing, Result, +}; + +#[tracing::client] +pub struct AccessPublicOperationClient { + pub(crate) endpoint: Url, + pub(crate) pipeline: Pipeline, +} + +impl AccessPublicOperationClient { + /// Returns the Url associated with this client. + pub fn endpoint(&self) -> &Url { + &self.endpoint + } + + /// + /// # Arguments + /// + /// * `options` - Optional parameters for the request. + #[tracing::function( + "_Specs_.Azure.ClientGenerator.Core.Access.PublicOperation.noDecoratorInPublic" + )] + pub async fn no_decorator_in_public( + &self, + name: &str, + options: Option>, + ) -> Result> { + let options = options.unwrap_or_default(); + let ctx = options.method_options.context.to_borrowed(); + let mut url = self.endpoint.clone(); + url.append_path("/azure/client-generator-core/access/publicOperation/noDecoratorInPublic"); + let mut query_builder = url.query_builder(); + query_builder.set_pair("name", name); + query_builder.build(); + let mut request = Request::new(url, Method::Get); + request.insert_header("accept", "application/json"); + let rsp = self + .pipeline + .send( + &ctx, + &mut request, + Some(PipelineSendOptions { + check_success: CheckSuccessOptions { + success_codes: &[200], + }, + ..Default::default() + }), + ) + .await?; + Ok(rsp.into()) + } + + /// + /// # Arguments + /// + /// * `options` - Optional parameters for the request. + #[tracing::function( + "_Specs_.Azure.ClientGenerator.Core.Access.PublicOperation.publicDecoratorInPublic" + )] + pub async fn public_decorator_in_public( + &self, + name: &str, + options: Option>, + ) -> Result> { + let options = options.unwrap_or_default(); + let ctx = options.method_options.context.to_borrowed(); + let mut url = self.endpoint.clone(); + url.append_path( + "/azure/client-generator-core/access/publicOperation/publicDecoratorInPublic", + ); + let mut query_builder = url.query_builder(); + query_builder.set_pair("name", name); + query_builder.build(); + let mut request = Request::new(url, Method::Get); + request.insert_header("accept", "application/json"); + let rsp = self + .pipeline + .send( + &ctx, + &mut request, + Some(PipelineSendOptions { + check_success: CheckSuccessOptions { + success_codes: &[200], + }, + ..Default::default() + }), + ) + .await?; + Ok(rsp.into()) + } +} diff --git a/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/clients/access_relative_model_in_operation_client.rs b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/clients/access_relative_model_in_operation_client.rs new file mode 100644 index 000000000..6be607bf2 --- /dev/null +++ b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/clients/access_relative_model_in_operation_client.rs @@ -0,0 +1,122 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) Rust Code Generator. DO NOT EDIT. + +use crate::generated::models::{ + AbstractModel, AccessRelativeModelInOperationClientDiscriminatorOptions, + AccessRelativeModelInOperationClientOperationOptions, OuterModel, +}; +use azure_core::{ + error::CheckSuccessOptions, + http::{Method, Pipeline, PipelineSendOptions, Request, Response, Url, UrlExt}, + tracing, Result, +}; + +#[tracing::client] +pub struct AccessRelativeModelInOperationClient { + pub(crate) endpoint: Url, + pub(crate) pipeline: Pipeline, +} + +impl AccessRelativeModelInOperationClient { + /// Returns the Url associated with this client. + pub fn endpoint(&self) -> &Url { + &self.endpoint + } + + /// Expected query parameter: kind="real" + /// Expected response body: + /// ```json + /// { + /// "name": "Madge", + /// "kind": "real" + /// } + /// ``` + /// + /// # Arguments + /// + /// * `options` - Optional parameters for the request. + #[tracing::function( + "_Specs_.Azure.ClientGenerator.Core.Access.RelativeModelInOperation.discriminator" + )] + pub(crate) async fn discriminator( + &self, + kind: &str, + options: Option>, + ) -> Result> { + let options = options.unwrap_or_default(); + let ctx = options.method_options.context.to_borrowed(); + let mut url = self.endpoint.clone(); + url.append_path( + "/azure/client-generator-core/access/relativeModelInOperation/discriminator", + ); + let mut query_builder = url.query_builder(); + query_builder.set_pair("kind", kind); + query_builder.build(); + let mut request = Request::new(url, Method::Get); + request.insert_header("accept", "application/json"); + let rsp = self + .pipeline + .send( + &ctx, + &mut request, + Some(PipelineSendOptions { + check_success: CheckSuccessOptions { + success_codes: &[200], + }, + ..Default::default() + }), + ) + .await?; + Ok(rsp.into()) + } + + /// Expected query parameter: name="Madge" + /// Expected response body: + /// ```json + /// { + /// "name": "Madge", + /// "inner": + /// { + /// "name": "Madge" + /// } + /// } + /// ``` + /// + /// # Arguments + /// + /// * `options` - Optional parameters for the request. + #[tracing::function( + "_Specs_.Azure.ClientGenerator.Core.Access.RelativeModelInOperation.operation" + )] + pub(crate) async fn operation( + &self, + name: &str, + options: Option>, + ) -> Result> { + let options = options.unwrap_or_default(); + let ctx = options.method_options.context.to_borrowed(); + let mut url = self.endpoint.clone(); + url.append_path("/azure/client-generator-core/access/relativeModelInOperation/operation"); + let mut query_builder = url.query_builder(); + query_builder.set_pair("name", name); + query_builder.build(); + let mut request = Request::new(url, Method::Get); + request.insert_header("accept", "application/json"); + let rsp = self + .pipeline + .send( + &ctx, + &mut request, + Some(PipelineSendOptions { + check_success: CheckSuccessOptions { + success_codes: &[200], + }, + ..Default::default() + }), + ) + .await?; + Ok(rsp.into()) + } +} diff --git a/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/clients/access_shared_model_in_operation_client.rs b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/clients/access_shared_model_in_operation_client.rs new file mode 100644 index 000000000..915d0b8eb --- /dev/null +++ b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/clients/access_shared_model_in_operation_client.rs @@ -0,0 +1,99 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) Rust Code Generator. DO NOT EDIT. + +use crate::generated::models::{ + AccessSharedModelInOperationClientInternalOptions, + AccessSharedModelInOperationClientPublicOptions, SharedModel, +}; +use azure_core::{ + error::CheckSuccessOptions, + http::{Method, Pipeline, PipelineSendOptions, Request, Response, Url, UrlExt}, + tracing, Result, +}; + +#[tracing::client] +pub struct AccessSharedModelInOperationClient { + pub(crate) endpoint: Url, + pub(crate) pipeline: Pipeline, +} + +impl AccessSharedModelInOperationClient { + /// Returns the Url associated with this client. + pub fn endpoint(&self) -> &Url { + &self.endpoint + } + + /// + /// # Arguments + /// + /// * `options` - Optional parameters for the request. + #[tracing::function( + "_Specs_.Azure.ClientGenerator.Core.Access.SharedModelInOperation.internal" + )] + pub(crate) async fn internal( + &self, + name: &str, + options: Option>, + ) -> Result> { + let options = options.unwrap_or_default(); + let ctx = options.method_options.context.to_borrowed(); + let mut url = self.endpoint.clone(); + url.append_path("/azure/client-generator-core/access/sharedModelInOperation/internal"); + let mut query_builder = url.query_builder(); + query_builder.set_pair("name", name); + query_builder.build(); + let mut request = Request::new(url, Method::Get); + request.insert_header("accept", "application/json"); + let rsp = self + .pipeline + .send( + &ctx, + &mut request, + Some(PipelineSendOptions { + check_success: CheckSuccessOptions { + success_codes: &[200], + }, + ..Default::default() + }), + ) + .await?; + Ok(rsp.into()) + } + + /// + /// # Arguments + /// + /// * `options` - Optional parameters for the request. + #[tracing::function("_Specs_.Azure.ClientGenerator.Core.Access.SharedModelInOperation.public")] + pub async fn public( + &self, + name: &str, + options: Option>, + ) -> Result> { + let options = options.unwrap_or_default(); + let ctx = options.method_options.context.to_borrowed(); + let mut url = self.endpoint.clone(); + url.append_path("/azure/client-generator-core/access/sharedModelInOperation/public"); + let mut query_builder = url.query_builder(); + query_builder.set_pair("name", name); + query_builder.build(); + let mut request = Request::new(url, Method::Get); + request.insert_header("accept", "application/json"); + let rsp = self + .pipeline + .send( + &ctx, + &mut request, + Some(PipelineSendOptions { + check_success: CheckSuccessOptions { + success_codes: &[200], + }, + ..Default::default() + }), + ) + .await?; + Ok(rsp.into()) + } +} diff --git a/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/clients/mod.rs b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/clients/mod.rs new file mode 100644 index 000000000..6f45eb750 --- /dev/null +++ b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/clients/mod.rs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) Rust Code Generator. DO NOT EDIT. + +mod access_client; +mod access_internal_operation_client; +mod access_public_operation_client; +mod access_relative_model_in_operation_client; +mod access_shared_model_in_operation_client; +pub use access_client::*; +pub use access_internal_operation_client::*; +pub use access_public_operation_client::*; +pub use access_relative_model_in_operation_client::*; +pub use access_shared_model_in_operation_client::*; diff --git a/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/mod.rs b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/mod.rs new file mode 100644 index 000000000..2f25924aa --- /dev/null +++ b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/mod.rs @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) Rust Code Generator. DO NOT EDIT. + +/// Clients used to communicate with the service. +pub mod clients; +/// Contains all the data structures and types used by the client library. +pub mod models; +pub use clients::{AccessClient, AccessClientOptions}; diff --git a/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/models/method_options.rs b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/models/method_options.rs new file mode 100644 index 000000000..026cc84c5 --- /dev/null +++ b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/models/method_options.rs @@ -0,0 +1,69 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) Rust Code Generator. DO NOT EDIT. + +use azure_core::{fmt::SafeDebug, http::ClientMethodOptions}; + +/// Options to be passed to [`AccessInternalOperationClient::internal_decorator_in_internal()`](crate::generated::clients::AccessInternalOperationClient::internal_decorator_in_internal()) +#[derive(Clone, Default, SafeDebug)] +pub(crate) struct AccessInternalOperationClientInternalDecoratorInInternalOptions<'a> { + /// Allows customization of the method call. + pub(crate) method_options: ClientMethodOptions<'a>, +} + +/// Options to be passed to [`AccessInternalOperationClient::no_decorator_in_internal()`](crate::generated::clients::AccessInternalOperationClient::no_decorator_in_internal()) +#[derive(Clone, Default, SafeDebug)] +pub(crate) struct AccessInternalOperationClientNoDecoratorInInternalOptions<'a> { + /// Allows customization of the method call. + pub(crate) method_options: ClientMethodOptions<'a>, +} + +/// Options to be passed to [`AccessInternalOperationClient::public_decorator_in_internal()`](crate::generated::clients::AccessInternalOperationClient::public_decorator_in_internal()) +#[derive(Clone, Default, SafeDebug)] +pub(crate) struct AccessInternalOperationClientPublicDecoratorInInternalOptions<'a> { + /// Allows customization of the method call. + pub(crate) method_options: ClientMethodOptions<'a>, +} + +/// Options to be passed to [`AccessPublicOperationClient::no_decorator_in_public()`](crate::generated::clients::AccessPublicOperationClient::no_decorator_in_public()) +#[derive(Clone, Default, SafeDebug)] +pub struct AccessPublicOperationClientNoDecoratorInPublicOptions<'a> { + /// Allows customization of the method call. + pub method_options: ClientMethodOptions<'a>, +} + +/// Options to be passed to [`AccessPublicOperationClient::public_decorator_in_public()`](crate::generated::clients::AccessPublicOperationClient::public_decorator_in_public()) +#[derive(Clone, Default, SafeDebug)] +pub struct AccessPublicOperationClientPublicDecoratorInPublicOptions<'a> { + /// Allows customization of the method call. + pub method_options: ClientMethodOptions<'a>, +} + +/// Options to be passed to [`AccessRelativeModelInOperationClient::discriminator()`](crate::generated::clients::AccessRelativeModelInOperationClient::discriminator()) +#[derive(Clone, Default, SafeDebug)] +pub(crate) struct AccessRelativeModelInOperationClientDiscriminatorOptions<'a> { + /// Allows customization of the method call. + pub(crate) method_options: ClientMethodOptions<'a>, +} + +/// Options to be passed to [`AccessRelativeModelInOperationClient::operation()`](crate::generated::clients::AccessRelativeModelInOperationClient::operation()) +#[derive(Clone, Default, SafeDebug)] +pub(crate) struct AccessRelativeModelInOperationClientOperationOptions<'a> { + /// Allows customization of the method call. + pub(crate) method_options: ClientMethodOptions<'a>, +} + +/// Options to be passed to [`AccessSharedModelInOperationClient::internal()`](crate::generated::clients::AccessSharedModelInOperationClient::internal()) +#[derive(Clone, Default, SafeDebug)] +pub(crate) struct AccessSharedModelInOperationClientInternalOptions<'a> { + /// Allows customization of the method call. + pub(crate) method_options: ClientMethodOptions<'a>, +} + +/// Options to be passed to [`AccessSharedModelInOperationClient::public()`](crate::generated::clients::AccessSharedModelInOperationClient::public()) +#[derive(Clone, Default, SafeDebug)] +pub struct AccessSharedModelInOperationClientPublicOptions<'a> { + /// Allows customization of the method call. + pub method_options: ClientMethodOptions<'a>, +} diff --git a/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/models/mod.rs b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/models/mod.rs new file mode 100644 index 000000000..9c8f94c2d --- /dev/null +++ b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/models/mod.rs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) Rust Code Generator. DO NOT EDIT. + +mod method_options; +#[allow(clippy::module_inception)] +mod models; +mod models_impl; +mod unions_serde; +pub use method_options::*; +pub use models::*; +pub(crate) mod unions; +pub(crate) use unions::*; diff --git a/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/models/models.rs b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/models/models.rs new file mode 100644 index 000000000..a3fb2c3cd --- /dev/null +++ b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/models/models.rs @@ -0,0 +1,83 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) Rust Code Generator. DO NOT EDIT. + +use azure_core::fmt::SafeDebug; +use serde::{Deserialize, Serialize}; + +/// Used in internal operations, should be generated but not exported. +#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)] +#[non_exhaustive] +pub(crate) struct InnerModel { + #[serde(skip_serializing_if = "Option::is_none")] + pub(crate) name: Option, +} + +/// Used in an internal operation, should be generated but not exported. +#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)] +#[non_exhaustive] +pub(crate) struct InternalDecoratorModelInInternal { + #[serde(skip_serializing_if = "Option::is_none")] + pub(crate) name: Option, +} + +/// Used in an internal operation, should be generated but not exported. +#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)] +#[non_exhaustive] +pub(crate) struct NoDecoratorModelInInternal { + #[serde(skip_serializing_if = "Option::is_none")] + pub(crate) name: Option, +} + +/// Used in a public operation, should be generated and exported. +#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)] +#[non_exhaustive] +pub struct NoDecoratorModelInPublic { + #[serde(skip_serializing_if = "Option::is_none")] + pub name: Option, +} + +/// Used in internal operations, should be generated but not exported. +#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)] +#[non_exhaustive] +pub(crate) struct OuterModel { + #[serde(skip_serializing_if = "Option::is_none")] + pub(crate) inner: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + pub(crate) name: Option, +} + +/// Used in an internal operation but with public decorator, should be generated and exported. +#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)] +#[non_exhaustive] +pub struct PublicDecoratorModelInInternal { + #[serde(skip_serializing_if = "Option::is_none")] + pub name: Option, +} + +/// Used in a public operation, should be generated and exported. +#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)] +#[non_exhaustive] +pub struct PublicDecoratorModelInPublic { + #[serde(skip_serializing_if = "Option::is_none")] + pub name: Option, +} + +/// Used in internal operations, should be generated but not exported. +#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)] +#[non_exhaustive] +#[serde(rename = "real", tag = "kind")] +pub(crate) struct RealModel { + #[serde(skip_serializing_if = "Option::is_none")] + pub(crate) name: Option, +} + +/// Used by both public and internal operation. It should be generated and exported. +#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)] +#[non_exhaustive] +pub struct SharedModel { + #[serde(skip_serializing_if = "Option::is_none")] + pub name: Option, +} diff --git a/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/models/models_impl.rs b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/models/models_impl.rs new file mode 100644 index 000000000..f098a7e08 --- /dev/null +++ b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/models/models_impl.rs @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) Rust Code Generator. DO NOT EDIT. + +use super::{AbstractModel, RealModel}; + +impl From for AbstractModel { + fn from(value: RealModel) -> Self { + Self::RealModel(value) + } +} diff --git a/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/models/unions.rs b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/models/unions.rs new file mode 100644 index 000000000..6fc7c522a --- /dev/null +++ b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/models/unions.rs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) Rust Code Generator. DO NOT EDIT. + +use super::RealModel; +use azure_core::fmt::SafeDebug; +use serde::Deserialize; + +#[doc = r#"Used in internal operations, should be generated but not exported."#] +#[derive(Clone, Deserialize, SafeDebug)] +#[serde(tag = "kind")] +pub(crate) enum AbstractModel { + #[serde(rename = "real")] + RealModel(RealModel), + + #[serde(untagged)] + UnknownKind { + /// Discriminator property for AbstractModel. + kind: Option, + + name: Option, + }, +} diff --git a/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/models/unions_serde.rs b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/models/unions_serde.rs new file mode 100644 index 000000000..e75bfd282 --- /dev/null +++ b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/generated/models/unions_serde.rs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) Rust Code Generator. DO NOT EDIT. + +use super::{AbstractModel, RealModel}; +use serde::{Serialize, Serializer}; + +impl Serialize for AbstractModel { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + AbstractModel::RealModel(real_model) => RealModel::serialize(real_model, serializer), + AbstractModel::UnknownKind { kind, name } => { + #[derive(Serialize)] + struct UnknownKind<'a> { + #[serde(skip_serializing_if = "Option::is_none")] + kind: &'a Option, + #[serde(skip_serializing_if = "Option::is_none")] + name: &'a Option, + } + UnknownKind::serialize(&UnknownKind { kind, name }, serializer) + } + } + } +} diff --git a/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/lib.rs b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/lib.rs new file mode 100644 index 000000000..cc784e401 --- /dev/null +++ b/packages/typespec-rust/test/spector/azure/client-generator-core/access/src/lib.rs @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// Code generated by Microsoft (R) Rust Code Generator. + +#![cfg_attr(docsrs, feature(doc_cfg))] + +mod generated; +pub use generated::*; diff --git a/packages/typespec-rust/test/spector/azure/client-generator-core/access/tests/access_public_operation_client.rs b/packages/typespec-rust/test/spector/azure/client-generator-core/access/tests/access_public_operation_client.rs new file mode 100644 index 000000000..52281fe1e --- /dev/null +++ b/packages/typespec-rust/test/spector/azure/client-generator-core/access/tests/access_public_operation_client.rs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// Licensed under the MIT License. See License.txt in the project root for license information. + +use spector_access::AccessClient; + +#[tokio::test] +async fn public_operation_no_decorator_in_public() { + let client = AccessClient::with_no_credential("http://localhost:3000", None).unwrap(); + let resp = client + .get_access_public_operation_client() + .no_decorator_in_public("sample", None) + .await + .unwrap(); + let model = resp.into_model().unwrap(); + assert_eq!(model.name, Some("sample".to_string())); +} + +#[tokio::test] +async fn public_operation_public_decorator_in_public() { + let client = AccessClient::with_no_credential("http://localhost:3000", None).unwrap(); + let resp = client + .get_access_public_operation_client() + .public_decorator_in_public("sample", None) + .await + .unwrap(); + let model = resp.into_model().unwrap(); + assert_eq!(model.name, Some("sample".to_string())); +} diff --git a/packages/typespec-rust/test/spector/azure/client-generator-core/access/tests/access_shared_model_in_operation_client.rs b/packages/typespec-rust/test/spector/azure/client-generator-core/access/tests/access_shared_model_in_operation_client.rs new file mode 100644 index 000000000..1312fed95 --- /dev/null +++ b/packages/typespec-rust/test/spector/azure/client-generator-core/access/tests/access_shared_model_in_operation_client.rs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// Licensed under the MIT License. See License.txt in the project root for license information. + +use spector_access::AccessClient; + +#[tokio::test] +async fn shared_model_in_operation_public() { + let client = AccessClient::with_no_credential("http://localhost:3000", None).unwrap(); + let resp = client + .get_access_shared_model_in_operation_client() + .public("sample", None) + .await + .unwrap(); + let model = resp.into_model().unwrap(); + assert_eq!(model.name, Some("sample".to_string())); +}