Skip to content

Commit c11ef30

Browse files
authored
[SDK generation pipeline] Support apiVersion for generation from typespec (#41218)
* support apiVersion * fix * fix * format
1 parent 41b7f17 commit c11ef30

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

tools/azure-sdk-tools/packaging_tools/generate_utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import re
55
from functools import wraps
6+
from typing import Optional
67

78
from ci_tools.git_tools import get_add_diff_file_list
89
from pathlib import Path
@@ -408,12 +409,21 @@ def gen_typespec(
408409
head_sha: str,
409410
rest_repo_url: str,
410411
run_in_pipeline: bool,
412+
api_version: Optional[str] = None,
411413
) -> Dict[str, Any]:
412414
typespec_python = "@azure-tools/typespec-python"
413415
# call scirpt to generate sdk
414416
try:
415417
tsp_dir = (Path(spec_folder) / typespec_relative_path).resolve()
416418
repo_url = rest_repo_url.replace("https://github.com/", "")
419+
tspconfig = tsp_dir / "tspconfig.yaml"
420+
if api_version and tspconfig.exists():
421+
with open(tspconfig, "r") as file_in:
422+
content = yaml.safe_load(file_in)
423+
if content.get("options", {}).get("@azure-tools/typespec-python"):
424+
content["options"]["@azure-tools/typespec-python"]["api-version"] = api_version
425+
with open(tspconfig, "w") as file_out:
426+
yaml.dump(content, file_out)
417427
cmd = (
418428
f"tsp-client init --tsp-config {tsp_dir} --local-spec-repo {tsp_dir} --commit {head_sha} --repo {repo_url}"
419429
)

tools/azure-sdk-tools/packaging_tools/sdk_generator.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,14 @@ def main(generate_input, generate_output):
246246
config = gen_dpg(readme_or_tsp, data.get("autorestConfig", ""), dpg_relative_folder(spec_folder))
247247
else:
248248
del_outdated_generated_files(str(Path(spec_folder, readme_or_tsp)))
249-
config = gen_typespec(readme_or_tsp, spec_folder, data["headSha"], data["repoHttpsUrl"], run_in_pipeline)
249+
config = gen_typespec(
250+
readme_or_tsp,
251+
spec_folder,
252+
data["headSha"],
253+
data["repoHttpsUrl"],
254+
run_in_pipeline,
255+
data.get("apiVersion"),
256+
)
250257
_LOGGER.info(f"code generation cost time: {int(time.time() - code_generation_start_time)} seconds")
251258
except Exception as e:
252259
_LOGGER.error(f"fail to generate sdk for {readme_or_tsp}: {str(e)}")

0 commit comments

Comments
 (0)