Skip to content

eng, remove api-version required check, and infer sdk release type from api-version if not provided#48706

Open
XiaofeiCao wants to merge 5 commits intomainfrom
eng_infer_sdk_release_type
Open

eng, remove api-version required check, and infer sdk release type from api-version if not provided#48706
XiaofeiCao wants to merge 5 commits intomainfrom
eng_infer_sdk_release_type

Conversation

@XiaofeiCao
Copy link
Copy Markdown
Contributor

Description

Please add an informative description that covers that changes made by the pull request and link all relevant issues.

If an SDK is being regenerated based on a new swagger spec, a link to the pull request containing these swagger spec changes has been included above.

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

@XiaofeiCao XiaofeiCao marked this pull request as ready for review April 7, 2026 07:27
Copilot AI review requested due to automatic review settings April 7, 2026 07:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the TypeSpec management-plane SDK automation script to infer whether to generate a beta vs stable release when sdkReleaseType isn’t provided, based on generated metadata.

Changes:

  • Added infer_sdk_release_type(...) to derive sdkReleaseType from generated *_metadata.json.
  • Adjusted TypeSpec project generation flow to default to beta, then (optionally) infer and apply stable/beta selection for versioning after generation.
  • Removed the previous self-serve parameter validation gate around apiVersion/sdkReleaseType.

@XiaofeiCao XiaofeiCao changed the title eng, infer sdk release type from api-version eng, remove api-version required check, and infer sdk release type from api-version if not provided Apr 7, 2026
run_mode: str = config["runMode"] if "runMode" in config else None

if run_mode == "release" or run_mode == "local":
verify_self_serve_parameters(api_version, sdk_release_type)
Copy link
Copy Markdown
Member

@raych1 raych1 Apr 7, 2026

Choose a reason for hiding this comment

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

Do we still call verify_self_serve_parameters somewhere? This validation still needs to happen when users specify 'api-version' and 'sdk-release-type' in the release and local scenarios. That said, the validation can be removed only when they are not defined.

Copy link
Copy Markdown
Contributor Author

@XiaofeiCao XiaofeiCao Apr 8, 2026

Choose a reason for hiding this comment

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

Do we still call verify_self_serve_parameters somewhere?

After this PR, we won't.

The tricky part is "what" to validate. when they are not defined is vague.
E.g.

  • Should we still throw exception when api-version is specified GA and sdk_release_type is specified beta?
  • If so, should we also throw exception when api-version is not specified and inferred GA, while sdk_release_type is specified beta?
  • Also, when api-version is specified and sdk_release_type is not, should we throw exception when spec is multi-service(e.g. Compute)?

When we make api-version optional, we are already hoping user to know what they are doing. I'd say validation makes little sense now.

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.

I'm ok for removing this validation given this automation won't be invoked directly by users. The most important scenario to defense is with using preview api-version and GA sdk-release-type. This check is already in place of pipeline.

# Infer sdk release type from generated metadata when not explicitly provided
if not sdk_release_type and sdk_folder and module:
inferred_type = infer_sdk_release_type(sdk_root, sdk_folder, module)
release_beta_sdk = inferred_type == "beta"
Copy link
Copy Markdown
Member

@weidongxu-microsoft weidongxu-microsoft Apr 8, 2026

Choose a reason for hiding this comment

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

We may need to have an update to pom.xml, to remove the revapi.skip line, if target version is stable.

Previously it is done in emitter, based on version_client. And this likely would not be correct as #48706 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, updated. Also removed release_beta_sdk parameter from generate_from_typespec function.
Test PRs:

Copy link
Copy Markdown
Member

@weidongxu-microsoft weidongxu-microsoft Apr 8, 2026

Choose a reason for hiding this comment

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

test on keyvault is meaningless ? I thought we don't update pom on premium (could be wrong though)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, created new PR for inferred stable:

Also added unit test for revapi.skip.

(Not related)Strange, seems there's no increment-version PR since last storagemover release.. Maybe we need to make one:
https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/storagemover/azure-resourcemanager-storagemover/CHANGELOG.md

Copy link
Copy Markdown
Member

@weidongxu-microsoft weidongxu-microsoft left a comment

Choose a reason for hiding this comment

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

We may need to have a post generate update to `revapi.skip

@@ -321,6 +335,11 @@ def sdk_automation_typespec_project(tsp_project: str, config: dict) -> dict:
Copy link
Copy Markdown
Member

@weidongxu-microsoft weidongxu-microsoft Apr 8, 2026

Choose a reason for hiding this comment

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

Note here that it uses a potentially wrong generate_beta_sdk value. It likely affect version_client.txt

So you may need to update it again, after success (and update the CHANGELOG too?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Currently we have that after generation:

if succeeded:
# TODO (weidxu): move to typespec-java
if require_sdk_integration:
update_service_files_for_new_lib(sdk_root, service, GROUP_ID, module)
update_root_pom(sdk_root, service)
# get the stable version and current version from version_client.txt, current version in version_client will be updated if the release type is GA.
# e.g. If current version is 1.2.0-beta.1 and the release type is GA, then current version will be updated to 1.2.0
stable_version, current_version = set_or_increase_version(sdk_root, GROUP_ID, module, preview=release_beta_sdk)
output_folder = sdk_folder
update_version(sdk_root, output_folder)

For changelog:

update_changelog_version(sdk_root, output_folder, current_version)

The generate_beta_sdk parameter is used for passing package-version to emitter, possibly for setting revapi.skip.
My local test also seems fine. If we can't rely on release type in emitter, guess we could consider removing it, after this PR.

Copy link
Copy Markdown
Member

@weidongxu-microsoft weidongxu-microsoft Apr 8, 2026

Choose a reason for hiding this comment

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

We seem do have another pair here (I think this path is only for mgmt lib)?

if remove_before_regen and group_id:
remove_generated_source_code(os.path.join(sdk_root, sdk_folder), f"{group_id}.{service}")
_, current_version = set_or_increase_version(
sdk_root, group_id, module, version=version, preview=generate_beta_sdk
)
emitter_options.append(f"package-version={current_version}")
if api_version:
emitter_options.append(f"api-version={api_version}")

(so we seem updated version_client twice, in the script, on mgmt lib?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, here is for getting the correct current_version for setting into package-version for emitter. Previous logic to put it here, is due to module parse logic also being here.

Guess now we can remove line 613-616, since generate_beta_sdk cannot be trusted any more.

XiaofeiCao and others added 2 commits April 8, 2026 14:56
When SDK release type is beta (either explicitly passed or inferred from
api-version), ensure <revapi.skip>true</revapi.skip> is present in the
generated pom.xml: add it if missing, or change false to true.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The preview version is set again after generation with the correct
release_beta_sdk value, so the pre-generation call defaults to True.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
# Infer sdk release type from generated metadata when not explicitly provided
if not sdk_release_type and sdk_folder and module:
inferred_type = infer_sdk_release_type(sdk_root, sdk_folder, module)
release_beta_sdk = inferred_type == "beta"
Copy link
Copy Markdown
Member

@weidongxu-microsoft weidongxu-microsoft Apr 8, 2026

Choose a reason for hiding this comment

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

test on keyvault is meaningless ? I thought we don't update pom on premium (could be wrong though)


# Ensure revapi.skip=true for beta releases
if release_beta_sdk:
ensure_revapi_skip(os.path.join(sdk_root, output_folder, "pom.xml"))
Copy link
Copy Markdown
Member

@weidongxu-microsoft weidongxu-microsoft Apr 8, 2026

Choose a reason for hiding this comment

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

We either need this to handle both way (ensure_revapi_not_skip as well), or update emitter to remove the logic
https://github.com/microsoft/typespec/blob/main/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/template/FluentPomTemplate.java#L34-L36

As in most cases, the current version of version_client is a beta, so emitter will add revapi.skip.
Therefore, most cases, it would be ensure_revapi_not_skip upon stable.

We can remove the emitter logic, but it seems still valid when user run tsp-client update in repo, where the current version in version_client IS valid and IS the final version.

Hence I guess we just make a util method to always add/update revapi.skip according to beta/stable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, added.

XiaofeiCao and others added 2 commits April 9, 2026 15:54
Renamed ensure_revapi_skip to update_revapi_skip. Now sets revapi.skip=true
for beta releases and revapi.skip=false for stable releases.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

[Java] Remove validation on "APIVersion" parameter in self-service SDK generation

4 participants