Fix inline enum query/path params to use typed enums instead of String#779
Merged
Merged
Conversation
…Type enum The recursionLevel query parameter on git::items::get and git::items::list was typed as impl Into<String>. It now uses models::VersionControlRecursionType, a proper enum with variants None, OneLevel, OneLevelPlusNestedEmptyFolders, Full. Changes: - Patcher: add VersionControlRecursionType definition to git.json and replace the inline string enum on both the paths and x-ms-paths items operations - Codegen: generate Display impl for all enum types so they can be serialised as URL query parameter values - Examples: update git_items_list and git_repo_download_zip to use the new type Closes microsoft#78 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Previously, the patcher was adding spec patches for each inline enum query parameter (e.g. recursionLevel). This replaces that approach with a proper code generator fix. Changes: - spec.rs: WebParameter::type_name() now returns TypeName::Reference(name) for parameters with a non-empty `enum` field and an `x-ms-enum.name`, instead of TypeName::String. - spec.rs: new Spec::inline_parameter_enum_schemas() collects synthetic Schema entries for all inline enum parameters across all operations so the models codegen can generate named enum types for them. - codegen_models.rs: all_schemas() calls inline_parameter_enum_schemas() to include those synthetic schemas alongside definition-based schemas. - patcher.rs: remove the now-unnecessary patch_git_items_recursion_level patch function. This automatically fixes all 105 inline enum query/path parameters across all API areas (build, git, release, wit, tfvc, wiki, etc.), generating proper typed enum types instead of impl Into<String> for each. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #78.
The
recursionLevelquery parameter ongit::items::getandgit::items::listwas the reported case, but the same problem affected 105 parameters across all API areas — any parameter withtype: string, anenumfield, and anx-ms-enumextension was being generated asimpl Into<String>instead of a typed enum.Root cause
WebParameter::type_name()in the codegen calledget_type_name_for_schema(), which returnedTypeName::Stringfor all string-typed parameters and discarded theenum/x-ms-enumfields entirely.Fix
Two changes to the code generator — no spec patches required:
autorust/codegen/src/spec.rsWebParameter::type_name()now checks for non-emptyenum_+x_ms_enum.nameand returnsTypeName::Reference(name)instead ofTypeName::String.Spec::inline_parameter_enum_schemas()collects syntheticSchemaentries for all inline enum parameters so the models codegen can generate a named enum type for each.autorust/codegen/src/codegen_models.rsall_schemas()callsinline_parameter_enum_schemas()to include those synthetic schemas alongside definition-based schemas.std::fmt::Display, so enum values serialise correctly into URL query/path parameters via.to_string().Effect
All 105 affected parameters across
build,git,release,wit,tfvc,wiki,distributedTask, etc. now use typed enums. Examples:git::itemsrecursionLevelimpl Into<String>impl Into<models::VersionControlRecursionType>build::buildsstatusFilterimpl Into<String>impl Into<models::BuildStatus>build::buildsresultFilterimpl Into<String>impl Into<models::BuildResult>releasestatusFilterimpl Into<String>impl Into<models::ReleaseStatus>git::pull_requestssearchCriteria.statusimpl Into<String>impl Into<models::PullRequestStatus>tfvcrecursionLevelimpl Into<String>impl Into<models::VersionControlRecursionType>Breaking change
Callers passing string literals for any of the 105 affected parameters will need to switch to the enum type. Example:
Test plan
./build.shsucceedscargo clippy --all-features -- --deny warningspassescargo clippy --all-features --examples -- --deny warningspasses🤖 Generated with Claude Code