Skip to content

Fix preview API version detection for const-based codegen pattern - #26761

Merged
Jiaqi Zhang (JiaqiZhang-Dev) merged 4 commits into
mainfrom
copilot/fix-generator-detect-api-version-logic
May 13, 2026
Merged

Fix preview API version detection for const-based codegen pattern#26761
Jiaqi Zhang (JiaqiZhang-Dev) merged 4 commits into
mainfrom
copilot/fix-generator-detect-api-version-logic

Conversation

Copilot AI commented May 13, 2026

Copy link
Copy Markdown
Contributor

autorest.go#1944 moved API version literals from inline usage to per-client consts, breaking containsPreviewAPIVersion in the generator.

Before (inline literal — old codegen):

reqQP.Set("api-version", "2023-01-01-preview")

After (const declaration — new codegen):

const defaultFooClientVersion string = "2023-01-01-preview"
// ...
reqQP.Set("api-version", defaultFooClientVersion)

The detector only matched the inline pattern via "api-version" string splitting, so it stopped finding preview versions in newly generated code.

Changes

  • Added apiVersionConstRegex to match const default<Name>Version string = "..." declarations
  • containsPreviewAPIVersion now checks both the inline and const patterns
  • Added test cases covering const-based preview and stable version detection

…rn from autorest.go PR #1944

Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-go/sessions/a77da1d3-82c0-40c1-9b92-6205fbab752a

Co-authored-by: JiaqiZhang-Dev <194873822+JiaqiZhang-Dev@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-go/sessions/85108293-9e2e-41cf-a788-e1e1aeb7de33

Co-authored-by: JiaqiZhang-Dev <194873822+JiaqiZhang-Dev@users.noreply.github.com>
@JiaqiZhang-Dev
Jiaqi Zhang (JiaqiZhang-Dev) marked this pull request as ready for review May 13, 2026 08:55
Copilot AI review requested due to automatic review settings May 13, 2026 08:55

@tadelesh Chenjie Shi (tadelesh) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you add the changelog and bump version?

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 updates the generator’s preview API version detection logic to recognize a const-based API version pattern (in addition to inline "api-version" usage), and adds unit tests for the new detection case.

Changes:

  • Add apiVersionConstRegex and extend containsPreviewAPIVersion() to detect preview API versions declared via a default*Version const.
  • Add unit tests covering preview/stable const-based API version declarations.
  • Apply gofmt alignment changes in the regex var block.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
eng/tools/generator/version/version_tool.go Adds a new regex and detection branch for const-based preview API version detection.
eng/tools/generator/version/version_tool_test.go Adds tests to validate the new const-based detection behavior.

Comment thread eng/tools/generator/version/version_tool.go
Comment thread eng/tools/generator/version/version_tool_test.go
@JiaqiZhang-Dev

Copy link
Copy Markdown
Member

Could you add the changelog and bump version?

Copilot pls help add the changelog and bump version for generator

Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-go/sessions/3a4f4503-9b34-4d9e-a447-971488c2fcb4

Co-authored-by: JiaqiZhang-Dev <194873822+JiaqiZhang-Dev@users.noreply.github.com>

Copilot AI commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

Could you add the changelog and bump version?

Copilot pls help add the changelog and bump version for generator

Done — bumped version to v0.4.11 in version.go and added the changelog entry in commit 2250f9d.

Comment thread eng/tools/generator/CHANGELOG.md Outdated
Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-go/sessions/3d11e51c-38eb-45f9-895a-6196c94027e7

Co-authored-by: JiaqiZhang-Dev <194873822+JiaqiZhang-Dev@users.noreply.github.com>

@tadelesh Chenjie Shi (tadelesh) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How could current logic handle multiple services case?

Copilot AI commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

How could current logic handle multiple services case?

containsPreviewAPIVersion iterates all .go files in the package directory and returns true if any file contains a preview API version (either inline or const pattern). So for multiple services/clients, the package is considered preview if any client has a preview version. This is the pre-existing behavior — this PR only adds the const-based detection pattern.

@JiaqiZhang-Dev
Jiaqi Zhang (JiaqiZhang-Dev) merged commit a148d76 into main May 13, 2026
20 checks passed
@JiaqiZhang-Dev
Jiaqi Zhang (JiaqiZhang-Dev) deleted the copilot/fix-generator-detect-api-version-logic branch May 13, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants