Templates: Update Umbraco extension template for OpenAPI route changes#22670
Conversation
Following the migration from Swashbuckle to Microsoft.AspNetCore.OpenApi in #21058, the extension template still pointed at the old Swagger URL pattern and used outdated terminology in code comments. - generate-client npm script now points at /umbraco/openapi/{name}.json instead of /umbraco/swagger/{name}/swagger.json - generate-openapi.js renames swaggerUrl to openApiUrl and updates the example URL in the missing-argument error message - UmbracoExtensionApiComposer.cs comments updated from "Swagger" to "OpenAPI"
Without an explicit ShouldInclude predicate, Microsoft.AspNetCore.OpenApi only includes endpoints whose ApiExplorer GroupName equals the document name. The template's controller declared a different group name, so the custom document was created but stayed empty (paths: []), which in turn made npm run generate-client produce an empty TypeScript SDK. Filter by the [MapToApi] attribute already present on the extension's controller base, mirroring the pattern used by the Management and Delivery API options.
7193594 to
9117b27
Compare
The PerProject mode of the umbraco-extension template took a direct dependency on Microsoft.AspNetCore.OpenApi (with a long comment explaining why) but the Central mode did not, so default Central scaffolds failed to build with the source-generator interceptors error. Mirror the dependency in the Central csproj block and Directory.Packages.props.
|
Claude finished @lauraneto's task in 3m 41s —— View job PR ReviewTarget: Updates the
Suggestions
ApprovedThis looks good to be merged as-is, but please do a manual sanity check and testing before merging. |
There was a problem hiding this comment.
Pull request overview
Updates the UmbracoExtension template to match Umbraco v18’s Microsoft OpenAPI document generation and routing, ensuring newly scaffolded extensions can generate a usable OpenAPI document and TypeScript client.
Changes:
- Update template OpenAPI spec URLs from
/umbraco/swagger/.../swagger.jsonto/umbraco/openapi/{name}.jsonand align terminology/naming. - Add an explicit
OpenApiOptions.ShouldIncludepredicate so the template’s custom document includes the extension endpoints. - Add an explicit
Microsoft.AspNetCore.OpenApidependency for both CPM and non-CPM template modes.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| templates/UmbracoExtension/Umbraco.Extension.csproj | Adds explicit Microsoft.AspNetCore.OpenApi reference (and reorders package refs) to avoid transitive version mismatches in generated extensions. |
| templates/UmbracoExtension/Directory.Packages.props | Pins Microsoft.AspNetCore.OpenApi for CPM-based scaffolds. |
| templates/UmbracoExtension/Composers/UmbracoExtensionApiComposer.cs | Switches comments to OpenAPI terminology and adds ShouldInclude filtering by MapToApi. |
| templates/UmbracoExtension/Client/scripts/generate-openapi.js | Renames swaggerUrl → openApiUrl and updates example/spec URL to the new OpenAPI route. |
| templates/UmbracoExtension/Client/package.json | Updates generate-client script to call the new /umbraco/openapi/{name}.json endpoint. |
AndyButland
left a comment
There was a problem hiding this comment.
This tests out as described (thanks for the effort in providing the clear steps).
I had a suggestion for the issue you commented on, but I'm not sure it's necessary - happy for you to decide whether to update or just leave it as you have it.
Summary
Follow-up to #21058 (the Microsoft.AspNetCore.OpenApi migration). The
UmbracoExtensiondotnet template was not updated as part of that PR, so a freshly scaffolded extension hits several issues against a v18 site.This PR fixes:
generate-clientURL inClient/package.jsonand the example URL inClient/scripts/generate-openapi.jsto use the new/umbraco/openapi/{name}.jsonroute. Also renamesswaggerUrltoopenApiUrl, updates the related log strings for consistency, and replaces outdated "Swagger" terminology inUmbracoExtensionApiComposer.cscomments.ShouldIncludepredicate onOpenApiOptionsinUmbracoExtensionApiComposer.cs, filtering by theMapToApiattribute that's already on the extension's controller base. Without it, Microsoft.AspNetCore.OpenApi's default predicate filters byApiExplorer.GroupNamematching the document name, which doesn't match for the template's setup, so the custom document was created but stayed empty (paths: []), makingnpm run generate-clientproduce an empty TypeScript SDK.Microsoft.AspNetCore.OpenApiin the Central package management mode of the extension template (Umbraco.Extension.csprojandDirectory.Packages.props). The PerProject mode already had this, but Central mode did not, so default Central scaffolds failed to build with the source-generator interceptors error.Testing
End-to-end test requires a running Umbraco 18 site with the extension loaded. Quickest path is to pack everything locally and scaffold a fresh site and extension from the updated templates:
dotnet pack umbraco.sln -c Release -o ./packages.dotnet new install ./packages/Umbraco.Templates.18.0.0--*.nupkg.NuGet.configin it that points at<repo>/packagesalongsidenuget.org.dotnet new umbraco -n MyTestSite --development-database-type SQLite --friendly-name "Test Admin" --email admin@test.local --password "Test1234!@#".dotnet new umbraco-extension -n MyTestExtension.MyTestExtension/Client/package.json, set@umbraco-cms/backofficeto^17.3.5(no v18 release on npm yet) and update the URL in thegenerate-clientscript to match the port you'll run the site on (e.g.https://localhost:44339).MyTestSite:dotnet add reference ../MyTestExtension/MyTestExtension.csproj, thendotnet build, thendotnet run --urls https://localhost:44339(matching the port from step 6).https://localhost:44339/umbraco/openapi/mytestextension.jsonreturns 200 with thepingendpoint underpaths, andhttps://localhost:44339/umbraco/swagger/mytestextension/swagger.jsonreturns 404.MyTestExtension/Client, runnpm install,npm run generate-client,npm run build. All three should succeed.