Skip to content

Unify YARP TypeScript route helpers - #15729

Merged
Sébastien Ros (sebastienros) merged 18 commits into
mainfrom
sebros/yarp-route-union
Apr 2, 2026
Merged

Sébastien Ros (sebastienros) merged 18 commits into
mainfrom
sebros/yarp-route-union

Conversation

@sebastienros

Copy link
Copy Markdown
Contributor

Description

This improves the TypeScript YARP withConfiguration experience by allowing a single addRoute(...) / addCatchAllRoute(...) surface to accept clusters, endpoints, service-discovery resources, and external services. It addresses the follow-up from #15531 and the PR review feedback to make the route APIs feel more like the unified fluent builder experience.

The change adds union-based YARP polyglot exports, keeps older route capability IDs working through obsolete internal shims, and updates the TypeScript YARP playground to use the new unified route helpers. It also fixes TypeScript code generation for union input parameters so interface-handle union members are emitted as usable input types.

Fixes #15531

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

Copilot AI review requested due to automatic review settings March 31, 2026 14:02
@github-actions

github-actions Bot commented Mar 31, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15729

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 15729"

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 unifies the TypeScript YARP withConfiguration route APIs by introducing union-typed exports so addRoute(...) / addCatchAllRoute(...) can accept multiple target kinds (cluster, endpoint, service-discovery resource, external service), while also updating the TypeScript code generator to emit usable input types for union parameters.

Changes:

  • Added new union-based YARP polyglot exports for addRoute and addCatchAllRoute, and introduced an obsolete compatibility shim for the prior cluster-only addRoute export.
  • Updated the TypeScript ATS code generator to correctly map union input parameters (especially unions containing interface handles) to usable TS types.
  • Updated the TypeScript YARP playground ValidationAppHost to use the new unified route helpers.

Reviewed changes

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

File Description
src/Aspire.Hosting.Yarp/ConfigurationBuilder/IYarpConfigurationBuilder.cs Adds the new exported union-based route helpers and hides the interface method from ATS export; includes compatibility shim.
src/Aspire.Hosting.CodeGeneration.TypeScript/AtsTypeScriptCodeGenerator.cs Fixes TypeScript input type mapping for ATS union parameters.
playground/polyglot/TypeScript/Aspire.Hosting.Yarp/ValidationAppHost/apphost.ts Migrates sample usage from addRouteFrom* / addCatchAllRouteFrom* to unified addRoute / addCatchAllRoute.

@davidfowl David Fowler (davidfowl) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I love this trick.

Lets open a issue to handle obsolete in TypeScript.

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.

3 comments: 1 potential bug (silent unknown fallback for empty union input types), 1 design concern (inconsistent cluster naming for string destinations), 1 backward-compatibility question (missing addCatchAllRoute compat shim).

# Conflicts:
#	tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/AtsGeneratedAspire.verified.ts
#	tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts
@github-actions

github-actions Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

🎬 CLI E2E Test Recordings — 55 recordings uploaded (commit ad1965c)

View recordings
Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
Banner_NotDisplayedWithNoLogoFlag ▶️ View Recording
CertificatesClean_RemovesCertificates ▶️ View Recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View Recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View Recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunEmptyAppHostProject ▶️ View Recording
CreateAndRunJavaEmptyAppHostProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptEmptyAppHostProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateJavaAppHostWithViteApp ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View Recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View Recording
GlobalMigration_PreservesAllValueTypes ▶️ View Recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View Recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LegacySettingsMigration_AdjustsRelativeAppHostPath ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RestoreSupportsConfigOnlyHelperPackageAndCrossPackageTypes ▶️ View Recording
RunFromParentDirectory_UsesExistingConfigNearAppHost ▶️ View Recording
RunWithMissingAwaitShowsHelpfulError ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording
TypeScriptAppHostWithProjectReferenceIntegration ▶️ View Recording

📹 Recordings uploaded automatically from CI run #23909269906

@sebastienros
Sébastien Ros (sebastienros) merged commit cb281e7 into main Apr 2, 2026
263 checks passed
@sebastienros
Sébastien Ros (sebastienros) deleted the sebros/yarp-route-union branch April 14, 2026 17:31
@joperezr Jose Perez Rodriguez (joperezr) added this to the 13.3 milestone Apr 14, 2026
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

Docs Check — No Documentation PR Required

After reviewing the changes in this PR, no documentation update is needed on aspire.dev.

Reason: The changes improve the TypeScript polyglot YARP route helper APIs internally (unifying addRoute/addCatchAllRoute to accept union input types). The aspire.dev site does not currently have dedicated documentation for TypeScript polyglot YARP app hosts, so there is no existing page to update, and the scope of this change (TypeScript SDK code generation refinement + internal API shims) does not warrant creating new documentation at this time. The C#-focused YARP integration docs are unaffected.

Generated by PR Documentation Check · ● 525.6K · ◷

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve async pattern in typescript withConfiguration block

5 participants