Skip to content

Hide endpoint in Swagger: retarget net10.0, Swashbuckle 10.2.3, add built-in OpenAPI companion - #2205

Merged
vladimir-pecanac-main merged 3 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/94995-aspnetcore-how-to-hide-endpoint-in-swagger
Sep 22, 2026
Merged

vladimir-pecanac-main merged 3 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/94995-aspnetcore-how-to-hide-endpoint-in-swagger

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Retargets the HideEndpointInSwagger sample to .NET 10 and adds a companion project that shows the same techniques against the built-in OpenAPI generator.

  • HideEndpointInSwagger and HideEndpointInSwaggerTests move from net7.0 to net10.0.
  • Swashbuckle.AspNetCore 6.4.0 to 10.2.3, Microsoft.AspNetCore.OpenApi 7.0.2 to 10.0.12. Both clear the NU1903 advisories the old versions carried.
  • SwaggerDocumentFilter.cs now uses Microsoft.OpenApi. On the current Swashbuckle line Microsoft.OpenApi.Models no longer exists, so the old using is a compile error.
  • Program.cs moves to top-level statements and drops AddEndpointsApiExplorer(), which the current template does not call.
  • Summaries becomes a collection expression.
  • Test packages: Microsoft.NET.Test.Sdk 18.10.0, xunit 2.9.3, xunit.runner.visualstudio 4.0.0, coverlet.collector 10.0.1.
  • New HideEndpointInOpenApi project references only Microsoft.AspNetCore.OpenApi and carries the same controller plus OpenApiOptions.ShouldInclude and an IOpenApiDocumentTransformer.

Verified on SDK 10.0.302: solution builds at 0 warnings, 5 of 5 tests pass. The Swashbuckle app serves /swagger/v1/swagger.json with "paths": {} and /swagger/index.html at 200; the companion app serves /openapi/v1.json with "paths": {}. On both builds GetMethodOne returns 404 and the other four endpoints return 200 while absent from the document.

…uilt-in OpenAPI companion

- HideEndpointInSwagger and its test project move from net7.0 to net10.0
- Swashbuckle.AspNetCore 6.4.0 to 10.2.3, Microsoft.AspNetCore.OpenApi 7.0.2 to 10.0.12
- SwaggerDocumentFilter uses Microsoft.OpenApi, the namespace OpenApiDocument lives in now
- Program.cs moves to top-level statements and drops AddEndpointsApiExplorer()
- Summaries becomes a collection expression
- Test packages: Microsoft.NET.Test.Sdk 18.10.0, xunit 2.9.3, xunit.runner.visualstudio 4.0.0, coverlet.collector 10.0.1
- New HideEndpointInOpenApi project shows the same techniques against the built-in OpenAPI generator, with ShouldInclude and an IOpenApiDocumentTransformer
@vladimir-pecanac-main
vladimir-pecanac-main merged commit b70e6bc into CodeMazeBlog:main Sep 22, 2026
4 checks passed
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.

1 participant