Skip to content

Commit 58d532e

Browse files
Require doccoments in typespec and typespec_client_core packages (#2972)
Partial fix for #1709 --------- Co-authored-by: Copilot <[email protected]>
1 parent 93cb970 commit 58d532e

File tree

27 files changed

+194
-5
lines changed

27 files changed

+194
-5
lines changed

sdk/core/azure_core_macros/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the MIT License.
33

44
#![doc = include_str!("../README.md")]
5+
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
6+
#![warn(missing_docs)]
57

68
mod tracing;
79
mod tracing_client;
@@ -41,6 +43,13 @@ pub fn new(attr: TokenStream, item: TokenStream) -> TokenStream {
4143
.map_or_else(|e| e.into_compile_error().into(), |v| v.into())
4244
}
4345

46+
/// Attribute client subclient struct declarations to enable distributed tracing.
47+
///
48+
/// To declare a subclient that will be traced, you should use the `#[tracing::subclient]` attribute
49+
/// exported from azure_core.
50+
///
51+
/// This macro will automatically instrument the subclient declaration with tracing information. It will also ensure that the subclient is created with the necessary tracing context.
52+
/// The `#[tracing::subclient]` attribute takes a single argument, which is a string representing the Azure Namespace name for the service being traced.
4453
#[proc_macro_attribute]
4554
pub fn subclient(attr: TokenStream, item: TokenStream) -> TokenStream {
4655
tracing_subclient::parse_subclient(attr.into(), item.into())
@@ -49,6 +58,15 @@ pub fn subclient(attr: TokenStream, item: TokenStream) -> TokenStream {
4958

5059
/// Attribute client public APIs to enable distributed tracing.
5160
///
61+
/// To declare a public API function that will be traced, you should use the `#[tracing::function]` attribute
62+
/// exported from azure_core.
63+
///
64+
/// This macro will automatically instrument the public API function with tracing information. It will also ensure that the function is executed with the necessary tracing context.
65+
///
66+
/// The `function` attribute takes one required argument, which is a string representing the name of the operation being traced.
67+
/// This name will be used in the tracing spans to identify the operation being performed. The name should be unique and match the
68+
/// typespec name for the operation being traced if possible.
69+
///
5270
#[proc_macro_attribute]
5371
pub fn function(attr: TokenStream, item: TokenStream) -> TokenStream {
5472
tracing_function::parse_function(attr.into(), item.into())
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Template crate for Azure SDK pipeline testing
1+
# Template crate for Azure SDK pipeline testing

sdk/template/azure_template_core/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
#![doc = include_str!("../README.md")]
5+
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
6+
#![warn(missing_docs)]
7+
48
/// Core numeric traits and types
59
pub mod numeric {
610
/// Core trait for numeric operations
@@ -18,6 +22,14 @@ pub mod numeric {
1822

1923
pub use numeric::NumericCore;
2024

25+
/// Adds two `u64` values and returns the result.
26+
///
27+
/// # Examples
28+
/// ```
29+
/// # use azure_template_core::add;
30+
/// let sum = add(5, 10);
31+
/// assert_eq!(sum, 15);
32+
/// ```
2133
pub fn add(left: u64, right: u64) -> u64 {
2234
left + right
2335
}

sdk/typespec/src/error/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ pub enum ErrorKind {
2222
/// An HTTP status code that was not expected.
2323
#[cfg(feature = "http")]
2424
HttpResponse {
25+
/// The HTTP status code that was returned.
2526
status: StatusCode,
27+
/// An optional error code returned by the service.
2628
error_code: Option<String>,
2729
},
2830
/// An error performing IO.
@@ -170,6 +172,7 @@ impl Error {
170172
}
171173
}
172174

175+
/// If this error is an HTTP response error, return the associated status code.
173176
#[cfg(feature = "http")]
174177
pub fn http_status(&self) -> Option<StatusCode> {
175178
match &self.kind() {

sdk/typespec/src/http/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
//! This module contains types and utilities for working with HTTP status codes.
5+
46
mod status_code;
57

68
pub use status_code::StatusCode;

sdk/typespec/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#![doc = include_str!("../README.md")]
55
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
6+
#![warn(missing_docs)]
67

78
pub mod error;
89
#[cfg(feature = "http")]

sdk/typespec/typespec_client_core/src/async_runtime/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ mod web_runtime;
4242
#[cfg(test)]
4343
mod tests;
4444

45+
/// A `TaskFuture` is a boxed future that represents a task that can be spawned and executed asynchronously.
4546
#[cfg(not(target_arch = "wasm32"))]
4647
pub type TaskFuture = Pin<Box<dyn Future<Output = ()> + Send + 'static>>;
4748

48-
// WASM32 does not support `Send` futures, so we use a non-Send future type.
49+
/// A `TaskFuture` is a boxed future that represents a task that can be spawned and executed asynchronously.
4950
#[cfg(target_arch = "wasm32")]
5051
pub type TaskFuture = Pin<Box<dyn Future<Output = ()> + 'static>>;
5152

@@ -60,6 +61,8 @@ pub type SpawnedTask = Pin<
6061
>,
6162
>;
6263

64+
/// A `SpawnedTask` is a future that represents a running task.
65+
/// It can be awaited to block until the task has completed.
6366
#[cfg(target_arch = "wasm32")]
6467
pub type SpawnedTask =
6568
Pin<Box<dyn Future<Output = std::result::Result<(), Box<dyn std::error::Error>>> + 'static>>;
@@ -105,6 +108,12 @@ pub trait AsyncRuntime: Send + Sync {
105108
/// that can be awaited.
106109
fn spawn(&self, f: TaskFuture) -> SpawnedTask;
107110

111+
/// Sleep for the specified duration asynchronously.
112+
///
113+
/// # Arguments
114+
/// * `duration` - The duration to sleep for.
115+
/// # Returns
116+
/// A future that resolves after the specified duration has elapsed.
108117
fn sleep(&self, duration: Duration) -> TaskFuture;
109118
}
110119

sdk/typespec/typespec_client_core/src/base64.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
// cspell:ignore Hdvcmxk
5+
46
//! Base64 encoding and decoding functions.
57
68
use base64::{
@@ -25,27 +27,87 @@ const URL_SAFE: GeneralPurpose = GeneralPurpose::new(
2527
.with_encode_padding(false),
2628
);
2729

30+
/// Encode the input into a base64 string using the standard base64 encoding scheme.
31+
///
32+
/// # Arguments
33+
/// * `input` - The input data to encode, which can be any type that implements `AsRef<[u8]>`.
34+
///
35+
/// # Returns
36+
/// A `String` containing the base64 encoded representation of the input data.
37+
///
38+
/// # Examples
39+
/// ```rust
40+
/// # use typespec_client_core::base64;
41+
/// let data = b"Hello, world!";
42+
/// let encoded = base64::encode(data);
43+
/// assert_eq!(encoded, "SGVsbG8sIHdvcmxkIQ==");
44+
/// ```
2845
pub fn encode<T>(input: T) -> String
2946
where
3047
T: AsRef<[u8]>,
3148
{
3249
STANDARD.encode(input)
3350
}
3451

52+
/// Decode a base64 encoded string using the standard base64 decoding scheme.
53+
///
54+
/// # Arguments
55+
/// * `input` - The base64 encoded input data to decode, which can be any type that implements `AsRef<[u8]>`.
56+
///
57+
/// # Returns
58+
/// A `Result` containing a `Vec<u8>` with the decoded data, or an error if the input is not valid base64.
59+
///
60+
/// # Examples
61+
/// ```rust
62+
/// # use typespec_client_core::base64;
63+
/// let encoded = "SGVsbG8sIHdvcmxkIQ==";
64+
/// let decoded = base64::decode(encoded).expect("Decoding should succeed");
65+
/// assert_eq!(decoded, b"Hello, world!");
66+
/// ```
3567
pub fn decode<T>(input: T) -> crate::Result<Vec<u8>>
3668
where
3769
T: AsRef<[u8]>,
3870
{
3971
Ok(STANDARD.decode(input)?)
4072
}
4173

74+
/// Encode the input into a base64 string using the URL safe base64 encoding scheme (base64url).
75+
///
76+
/// # Arguments
77+
/// * `input` - The input data to encode, which can be any type that implements `AsRef<[u8]>`.
78+
///
79+
/// # Returns
80+
/// A `String` containing the base64url encoded representation of the input data.
81+
///
82+
/// # Examples
83+
/// ```rust
84+
/// # use typespec_client_core::base64;
85+
/// let data = b"Hello, world!";
86+
/// let encoded = base64::encode_url_safe(data);
87+
/// assert_eq!(encoded, "SGVsbG8sIHdvcmxkIQ");
88+
/// ```
4289
pub fn encode_url_safe<T>(input: T) -> String
4390
where
4491
T: AsRef<[u8]>,
4592
{
4693
URL_SAFE.encode(input)
4794
}
4895

96+
/// Decode a base64url encoded string using the URL safe base64 decoding scheme. (base64url)
97+
///
98+
/// # Arguments
99+
/// * `input` - The base64url encoded input data to decode, which can be any type that implements `AsRef<[u8]>`.
100+
///
101+
/// # Returns
102+
/// A `Result` containing a `Vec<u8>` with the decoded data, or an error if the input is not valid base64url.
103+
///
104+
/// # Examples
105+
/// ```rust
106+
/// # use typespec_client_core::base64;
107+
/// let encoded = "SGVsbG8sIHdvcmxkIQ";
108+
/// let decoded = base64::decode_url_safe(encoded).expect("Decoding should succeed");
109+
/// assert_eq!(decoded, b"Hello, world!");
110+
/// ```
49111
pub fn decode_url_safe<T>(input: T) -> crate::Result<Vec<u8>>
50112
where
51113
T: AsRef<[u8]>,

sdk/typespec/typespec_client_core/src/http/format.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ pub trait Format: std::fmt::Debug {}
2525
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
2626
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
2727
pub trait DeserializeWith<F: Format>: Sized {
28+
/// Deserialize the response body using the specified format.
29+
///
30+
/// # Arguments
31+
/// * `body` - The response body to deserialize.
32+
///
33+
/// # Returns
34+
/// A `Result` containing the deserialized value of type `Self`, or an error if deserialization fails.
2835
async fn deserialize_with(body: ResponseBody) -> typespec::Result<Self>;
2936
}
3037

sdk/typespec/typespec_client_core/src/http/headers/common.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
#![allow(missing_docs)]
5+
46
use super::*;
57

68
// HTTP headers are case-insensitive.

0 commit comments

Comments
 (0)