Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
/docs/howtos/DataPlane*/ @lmazuel @m-nash @iscai-msft @srnagar @joheredi

/packages/typespec-python @iscai-msft @msyyc @tadelesh @l0lawrence @ChenxiJiang333 @kashifkhan
/packages/typespec-java @weidongxu-microsoft @haolingdong-msft @XiaofeiCao
/packages/typespec-java @weidongxu-microsoft @haolingdong-msft @XiaofeiCao @alzimmermsft
20 changes: 20 additions & 0 deletions packages/typespec-java/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Change Log - @azure-tools/typespec-java

## 0.45.7

Compatible with compiler 1.14.0.

### Features

- [#4916](https://github.com/Azure/typespec-azure/pull/4916) Support `clientApiVersions`.

### Bug Fixes

- [#4916](https://github.com/Azure/typespec-azure/pull/4916) Fix per-client `ServiceVersion` regression after migrating from js-yaml and lodash.


## 0.45.6 (2026-07-15)

Compatible with compiler 1.14.0.

- Updated package dependencies to the latest versions.
- Replaced `js-yaml` with `yaml`, and `lodash` with builtin.

## 0.45.4 (2026-06-18)

Compatible with compiler 1.13.0.
Expand Down
55 changes: 8 additions & 47 deletions packages/typespec-java/Copy-Sources.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
# so `@azure-tools/typespec-java` builds the same emitter while keeping its own
# Azure-flavored `src/options.ts` (excluded from the copy).
#
# The desired core commit is pinned in core-commit.json. If that commit is newer
# than the submodule's current checkout, this script temporarily checks it out to
# copy the sources from, and always restores the submodule to its original SHA in
# the finally block (repo-wide `pnpm build` runs this and CI checks git status).
# The desired core commit is pinned in core-commit.json; CoreCommit.ps1's
# Enter-CoreCommit temporarily checks it out (when newer than the submodule's
# current checkout) to copy the sources from, and Restore-CoreCommit always puts
# the submodule back to its original SHA (repo-wide `pnpm build` runs this and CI
# checks git status).
#
# Mirrors the "Copy TypeScript code" step of autorest.java's Build-TypeSpec.ps1.

Expand All @@ -16,48 +17,9 @@ $packageRoot = $PSScriptRoot
$repoRoot = Resolve-Path (Join-Path $packageRoot ".." "..")
$coreRoot = Join-Path $repoRoot "core"

# Capture the submodule's current SHA so we can restore it no matter what.
$originSha = (git -C $coreRoot rev-parse HEAD).Trim()
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to read the current SHA of the 'core' submodule at: $coreRoot`nMake sure it is checked out (git submodule update --init --recursive)."
}

. (Join-Path $packageRoot "CoreCommit.ps1")
$originSha = Enter-CoreCommit -CoreRoot $coreRoot -PackageRoot $packageRoot
try {
# core-commit.json is optional: when present it pins the core commit to copy
# sources from; when absent we just use the submodule's current checkout.
$configPath = Join-Path $packageRoot "core-commit.json"
$targetSha = $null
if (Test-Path $configPath) {
$targetSha = ((Get-Content -Raw $configPath | ConvertFrom-Json).sha).Trim()
if ([string]::IsNullOrWhiteSpace($targetSha)) {
Write-Error "No 'sha' found in $configPath."
}
}
else {
Write-Host "core-commit.json not found; using current core checkout $originSha."
}

if ($targetSha -and $targetSha -ne $originSha) {
# Make sure the target commit is available locally (it may be newer than
# what has been fetched); ignore failure if it is already present.
git -C $coreRoot fetch --quiet origin $targetSha 2>$null

# Only move forward: check out the target when it is a descendant (newer)
# of the current checkout. `merge-base --is-ancestor A B` exits 0 when A is
# an ancestor of B, i.e. B is newer than A.
git -C $coreRoot merge-base --is-ancestor $originSha $targetSha
if ($LASTEXITCODE -eq 0) {
Write-Host "Checking out newer core commit $targetSha (was $originSha)"
git -C $coreRoot checkout --quiet $targetSha
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to checkout core commit $targetSha."
}
}
else {
Write-Host "core-commit.json SHA $targetSha is not newer than current $originSha; using current checkout."
}
}

$emitterRoot = Resolve-Path (Join-Path $coreRoot "packages" "http-client-java" "emitter")

Copy-Item -Path (Join-Path $emitterRoot "src") -Destination $packageRoot -Exclude "options.ts" -Recurse -Force
Expand Down Expand Up @@ -88,6 +50,5 @@ try {
}
}
finally {
# Always restore the submodule to the SHA it was at when this script started.
git -C $coreRoot checkout --quiet $originSha
Restore-CoreCommit -CoreRoot $coreRoot -OriginSha $originSha
}
89 changes: 89 additions & 0 deletions packages/typespec-java/CoreCommit.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Shared helpers for running work against the desired `core/` submodule commit.
#
# Dot-source this file to import Enter-CoreCommit / Restore-CoreCommit, then wrap
# the work in a try/finally:
#
# . (Join-Path $packageRoot "CoreCommit.ps1")
# $originSha = Enter-CoreCommit -CoreRoot $coreRoot -PackageRoot $packageRoot
# try {
# # copy/sync from the (possibly pinned) core checkout
# }
# finally {
# Restore-CoreCommit -CoreRoot $coreRoot -OriginSha $originSha
# }
#
# The desired core commit is pinned in <PackageRoot>/core-commit.json. When that
# file is present and its commit is newer than the submodule's current checkout,
# Enter-CoreCommit temporarily checks it out; Restore-CoreCommit puts the submodule
# back to its original SHA (repo-wide `pnpm build` runs these scripts and CI checks
# git status).

# Check out the pinned core commit (when newer) and return the submodule's original
# SHA so the caller can restore it in a finally block.
function Enter-CoreCommit {
param(
# Path to the `core/` submodule.
[Parameter(Mandatory = $true)]
[string] $CoreRoot,

# Directory that contains the optional core-commit.json pin file.
[Parameter(Mandatory = $true)]
[string] $PackageRoot
)

# Capture the submodule's current SHA so the caller can restore it.
$originSha = (git -C $CoreRoot rev-parse HEAD).Trim()
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to read the current SHA of the 'core' submodule at: $CoreRoot`nMake sure it is checked out (git submodule update --init --recursive)."
}

# core-commit.json is optional: when present it pins the core commit to use;
# when absent we just use the submodule's current checkout.
$configPath = Join-Path $PackageRoot "core-commit.json"
$targetSha = $null
if (Test-Path $configPath) {
$targetSha = ((Get-Content -Raw $configPath | ConvertFrom-Json).sha).Trim()
if ([string]::IsNullOrWhiteSpace($targetSha)) {
Write-Error "No 'sha' found in $configPath."
}
}
else {
Write-Host "core-commit.json not found; using current core checkout $originSha."
}

if ($targetSha -and $targetSha -ne $originSha) {
# Make sure the target commit is available locally (it may be newer than
# what has been fetched); ignore failure if it is already present.
git -C $CoreRoot fetch --quiet origin $targetSha 2>$null

# Only move forward: check out the target when it is a descendant (newer)
# of the current checkout. `merge-base --is-ancestor A B` exits 0 when A is
# an ancestor of B, i.e. B is newer than A.
git -C $CoreRoot merge-base --is-ancestor $originSha $targetSha
if ($LASTEXITCODE -eq 0) {
Write-Host "Checking out newer core commit $targetSha (was $originSha)"
git -C $CoreRoot checkout --quiet $targetSha
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to checkout core commit $targetSha."
}
}
else {
Write-Host "core-commit.json SHA $targetSha is not newer than current $originSha; using current checkout."
}
}

return $originSha
}

# Restore the submodule to the SHA captured by Enter-CoreCommit.
function Restore-CoreCommit {
param(
[Parameter(Mandatory = $true)]
[string] $CoreRoot,

[Parameter(Mandatory = $true)]
[string] $OriginSha
)

git -C $CoreRoot checkout --quiet $OriginSha
}
1 change: 1 addition & 0 deletions packages/typespec-java/core-commit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "sha": "8cef6d928a2ac3237d5eacb69b4ac671a54bcf92" }
80 changes: 73 additions & 7 deletions packages/typespec-java/emitter-tests/SyncTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,81 @@
#
# Generated output (src/main, **/generated/**) is gitignored; only the
# hand-written tests and specs synced here are committed.
#
# The desired core commit is pinned in ../core-commit.json; CoreCommit.ps1's
# Enter-CoreCommit transiently checks it out (when newer) and Restore-CoreCommit
# restores the submodule afterwards.

$ErrorActionPreference = "Stop"
Set-Location $PSScriptRoot

$testRoot = Resolve-Path (Join-Path ".." ".." ".." "core" "packages" "http-client-java" "generator" "http-client-generator-test")
$scriptRoot = $PSScriptRoot
$packageRoot = Resolve-Path (Join-Path $scriptRoot "..")
$coreRoot = Resolve-Path (Join-Path $scriptRoot ".." ".." ".." "core")

. (Join-Path $packageRoot "CoreCommit.ps1")
$originSha = Enter-CoreCommit -CoreRoot $coreRoot -PackageRoot $packageRoot
try {
$testRoot = Resolve-Path (Join-Path $coreRoot "packages" "http-client-java" "generator" "http-client-generator-test")

$localSrc = Join-Path $scriptRoot "src"
$localTsp = Join-Path $scriptRoot "tsp"
Remove-Item $localSrc -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item $localTsp -Recurse -Force -ErrorAction SilentlyContinue
Copy-Item -Path (Join-Path $testRoot "src") -Destination $localSrc -Recurse -Force
Copy-Item -Path (Join-Path $testRoot "tsp") -Destination $localTsp -Recurse -Force

Write-Host "Synced src and tsp from $testRoot"

# Sync the versions of shared "dependencies" and "overrides" entries from the
# upstream package.json so this Azure test project stays aligned with the source
# of truth. For each package that exists in BOTH package.json files, only its
# version is updated to match core. Entries that exist here but NOT in core (e.g.
# @azure-tools/typespec-java, @azure-tools/typespec-liftr-base) are preserved
# as-is -- they are never removed and their versions are left untouched. Entries
# that exist only in core are not added. Key order and 2-space indentation are
# preserved by ConvertTo-Json's round-trip.
$corePackageJsonPath = Join-Path $testRoot "package.json"
$localPackageJsonPath = Join-Path $scriptRoot "package.json"

$corePackage = Get-Content $corePackageJsonPath -Raw | ConvertFrom-Json
$localPackage = Get-Content $localPackageJsonPath -Raw | ConvertFrom-Json

foreach ($section in @("dependencies", "overrides")) {
if (-not $corePackage.$section -or -not $localPackage.$section) { continue }
$localNames = $localPackage.$section.PSObject.Properties.Name
foreach ($prop in $corePackage.$section.PSObject.Properties) {
# Only touch packages that already exist locally: overwrite the version
# with core's. Missing (core-only) packages are skipped, and local-only
# packages are left untouched since we never iterate over them.
if ($localNames -contains $prop.Name) {
$localPackage.$section.$($prop.Name) = $prop.Value
}
}
}

Remove-Item ./src -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item ./tsp -Recurse -Force -ErrorAction SilentlyContinue
Copy-Item -Path (Join-Path $testRoot "src") -Destination ./src -Recurse -Force
Copy-Item -Path (Join-Path $testRoot "tsp") -Destination ./tsp -Recurse -Force
# Re-serialize and write back. Normalize CRLF -> LF and add a single trailing
# newline so the output matches the repo's LF convention regardless of platform.
$json = ($localPackage | ConvertTo-Json -Depth 20).Replace("`r`n", "`n")
[System.IO.File]::WriteAllText($localPackageJsonPath, $json + "`n")
Write-Host "Synced dependency and override versions from $corePackageJsonPath"
}
finally {
Restore-CoreCommit -CoreRoot $coreRoot -OriginSha $originSha
}

Write-Host "Synced src and tsp from $testRoot"
# Point the local @azure-tools/typespec-java dependency at the .tgz produced by
# this repo's emitter (Build-TypeSpec.ps1 runs `npm pack`, which names the file
# azure-tools-typespec-java-<version>.tgz). Keep both this test project's own
# version and that dependency in sync with packages/typespec-java/package.json so
# a version bump there propagates here. This depends only on the local repo, not
# on core, so it runs outside the core-commit checkout as its own read-modify-write.
$localPackageJsonPath = Join-Path $scriptRoot "package.json"
$emitterVersion = (Get-Content (Join-Path $packageRoot "package.json") -Raw | ConvertFrom-Json).version
$localPackage = Get-Content $localPackageJsonPath -Raw | ConvertFrom-Json
$localPackage.version = $emitterVersion
if ($localPackage.dependencies.PSObject.Properties.Name -contains "@azure-tools/typespec-java") {
$localPackage.dependencies.'@azure-tools/typespec-java' = "file:../azure-tools-typespec-java-$emitterVersion.tgz"
}
$json = ($localPackage | ConvertTo-Json -Depth 20).Replace("`r`n", "`n")
[System.IO.File]::WriteAllText($localPackageJsonPath, $json + "`n")
Write-Host "Synced @azure-tools/typespec-java version to $emitterVersion"
38 changes: 19 additions & 19 deletions packages/typespec-java/emitter-tests/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure-tools/typespec-java-tests",
"version": "0.1.0",
"version": "0.45.7",
"type": "module",
"scripts": {
"format": "npm run -s prettier -- --write",
Expand All @@ -13,31 +13,31 @@
"spector-stop": "tsp-spector server stop"
},
"dependencies": {
"@typespec/spec-api": "0.1.0-alpha.14",
"@typespec/spector": "0.1.0-alpha.25",
"@typespec/http-specs": "0.1.0-alpha.38",
"@azure-tools/azure-http-specs": "0.1.0-alpha.42",
"@azure-tools/typespec-java": "file:../azure-tools-typespec-java-0.45.4.tgz"
"@typespec/spec-api": "0.1.0-alpha.15",
"@typespec/spector": "0.1.0-alpha.26",
"@typespec/http-specs": "0.1.0-alpha.39",
"@azure-tools/azure-http-specs": "0.1.0-alpha.43",
"@azure-tools/typespec-java": "file:../azure-tools-typespec-java-0.45.7.tgz"
},
"devDependencies": {
"@typespec/prettier-plugin-typespec": "^1.13.0",
"prettier-plugin-organize-imports": "^4.3.0",
"prettier": "^3.8.4"
},
"overrides": {
"@typespec/compiler": "1.13.0",
"@typespec/http": "1.13.0",
"@typespec/rest": "0.83.0",
"@typespec/versioning": "0.83.0",
"@typespec/openapi": "1.13.0",
"@typespec/xml": "0.83.0",
"@typespec/events": "0.83.0",
"@typespec/sse": "0.83.0",
"@typespec/streams": "0.83.0",
"@azure-tools/typespec-azure-core": "0.69.0",
"@azure-tools/typespec-client-generator-core": "0.69.0",
"@azure-tools/typespec-azure-resource-manager": "0.69.1",
"@azure-tools/typespec-autorest": "0.69.1",
"@typespec/compiler": "1.14.0",
"@typespec/http": "1.14.0",
"@typespec/rest": "0.84.0",
"@typespec/versioning": "0.84.0",
"@typespec/openapi": "1.14.0",
"@typespec/xml": "0.84.0",
"@typespec/events": "0.84.0",
"@typespec/sse": "0.84.0",
"@typespec/streams": "0.84.0",
"@azure-tools/typespec-azure-core": "0.70.0",
"@azure-tools/typespec-client-generator-core": "0.70.0",
"@azure-tools/typespec-azure-resource-manager": "0.70.0",
"@azure-tools/typespec-autorest": "0.70.0",
"@azure-tools/typespec-liftr-base": "0.14.0"
},
"private": true
Expand Down
Loading
Loading