Skip to content

Add new API generation tool#4666

Merged
heaths merged 7 commits into
Azure:mainfrom
heaths:api-gen
Jun 26, 2026
Merged

Add new API generation tool#4666
heaths merged 7 commits into
Azure:mainfrom
heaths:api-gen

Conversation

@heaths

@heaths heaths commented Jun 26, 2026

Copy link
Copy Markdown
Member

Introduce a new command-line tool for generating API documentation in the azure-sdk-for-rust repository. This tool includes diagnostics, a model for API structure, and supports output in both APIView and Markdown formats.

Enhancements include the extraction and rendering of explicit trait implementations, ensuring accurate representation in the documentation. The Rust toolchain configuration has been updated to include the rustc-dev component for development purposes.

Tests have been added to verify the correct rendering of trait implementations.

This will replace generate_api_report in a subsequent PR.

Fixes Azure/azure-sdk-tools#12698
Fixes Azure/azure-sdk-tools#15383
Fixes Azure/azure-sdk-tools#15384
Fixes Azure/azure-sdk-tools#15385
Fixes Azure/azure-sdk-tools#15445

heaths added 2 commits June 25, 2026 16:44
This commit introduces a new tool for generating API documentation for the
azure-sdk-for-rust repository. The tool includes a command-line interface,
diagnostics, and a model for representing the API structure.

The rendering logic supports two output formats: APIView and Markdown.
The APIView format produces a structured JSON output, while the Markdown
format generates Rust code snippets.

Additionally, the Rust toolchain configuration has been updated to include
the `rustc-dev` component, which is necessary for development purposes.
This update introduces the extraction and rendering of explicit trait
implementation blocks in the API model. It includes enhancements to
the extraction logic to identify and include trait implementations
alongside their associated members.

Additionally, the rendering functions have been updated to properly
format these implementations in the output, ensuring they are
navigable and correctly represented in the API documentation.

Tests have been added to verify the correct rendering of trait
implementations, ensuring that the new functionality works as
intended.
Copilot AI review requested due to automatic review settings June 26, 2026 00:52
This update introduces a new function to handle the rendering of self parameters
in a more idiomatic Rust style. The changes ensure that receiver parameters are
displayed as `self`, `&self`, or `&mut self` instead of `self: Self`,
`self: &Self`, or `self: &mut Self`. This improves the clarity and consistency
of the generated API documentation.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new standalone CLI tool, generate_api, under eng/tools/, intended to eventually replace generate_api_report. It generates public-API artifacts for a Rust crate by running cargo metadata + cargo rustdoc --output-format json, normalizing the rustdoc JSON into a tool-owned intermediate model, and rendering that model to either Markdown (API.md) or APIView (apiview.json). A notable feature is extraction/rendering of explicit (non-derived) trait impl blocks with navigable members. The rustc-dev component is added to the pinned nightly toolchain to enable a future move toward direct librustdoc/HIR integration.

Changes:

  • New generate_api bin crate (cli, diagnostics, driver, extract, model, output, render/apiview, render/markdown) plus README/PLAN docs, wired into the eng/tools workspace with clap added to workspace deps.
  • Adds rustc-dev to eng/tools/rust-toolchain.toml and updates .vscode/settings.json (linked projects, reordered cmake setting).
  • Unit tests covering trait-impl extraction and both renderers.
Show a summary per file
File Description
eng/tools/rust-toolchain.toml Adds rustc-dev component to the nightly toolchain
eng/tools/Cargo.toml Registers generate_api member and adds clap workspace dependency
eng/tools/generate_api/Cargo.toml New crate manifest inheriting workspace deps
eng/tools/generate_api/build.rs Reads toolchain channel from rust-toolchain.toml into TOOLCHAIN_CHANNEL
eng/tools/generate_api/src/main.rs Entry point: parse args, load model, render, write output
eng/tools/generate_api/src/cli.rs clap-based CLI args and Request/OutputFormat types
eng/tools/generate_api/src/diagnostics.rs Simple stdout/stderr logging helpers
eng/tools/generate_api/src/driver.rs Runs cargo metadata/rustdoc and caches workspace crate models
eng/tools/generate_api/src/extract.rs Converts rustdoc JSON into the shared model (re-exports, derives, trait impls)
eng/tools/generate_api/src/model.rs Shared intermediate API model and item-kind ordering
eng/tools/generate_api/src/output.rs Output path creation and file writing (&PathBuf param flagged)
eng/tools/generate_api/src/render/mod.rs Render module declarations
eng/tools/generate_api/src/render/markdown.rs Markdown renderer (member-placement issue flagged)
eng/tools/generate_api/src/render/apiview.rs APIView token renderer + validation and tokenizer
eng/tools/generate_api/README.md / PLAN.md Tool usage and design documentation
.vscode/settings.json Adds rust-analyzer linked projects; reorders cmake setting

Review details

  • Files reviewed: 17/17 changed files
  • Comments generated: 3
  • Review effort level: Medium

Comment thread eng/tools/generate_api/src/output.rs Outdated
Comment thread eng/tools/generate_api/src/render/markdown.rs Outdated
Comment thread eng/tools/generate_api/src/extract.rs Outdated
heaths and others added 3 commits June 25, 2026 18:04
This update introduces new functions to flatten whitespace and remove
unnecessary spaces around path separators in attributes. These changes
ensure that the review output remains consistent and source-like,
particularly for multiline attributes. Additional tests have been added
to verify the correctness of these normalizations.
- Extracted command execution into a reusable function to reduce code duplication
  in `driver.rs`.
- Simplified item implementation retrieval in `extract.rs` by introducing a helper
  function.
- Added sorting functionality for API items in `model.rs` to ensure consistent
  ordering during rendering.
- Updated rendering functions in `apiview.rs` and `markdown.rs` to utilize the new
  sorting method for improved output consistency.
Address PR Azure#4666 review feedback in the shared output and rendering layers.

Render inherent members inside source-shaped impl blocks for both review and APIView output, simplify the trait impl re-export plumbing, and accept &Path in write_file to satisfy Clippy.

Update the durable plan to reflect the final inherent impl rendering decision.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Make the review format the default, add the --no-docs switch for APIView output, and refactor APIView rendering to use a forward-compatible RenderOptions struct.

Update the README and durable plan to document the new CLI behavior and the preference for options structs over threaded booleans in renderer configuration.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@heaths heaths merged commit 51ac7c3 into Azure:main Jun 26, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants