Skip to content

OpenApi#19016

Open
Skrypt wants to merge 65 commits intomainfrom
skrypt/openapi
Open

OpenApi#19016
Skrypt wants to merge 65 commits intomainfrom
skrypt/openapi

Conversation

@Skrypt
Copy link
Copy Markdown
Contributor

@Skrypt Skrypt commented Mar 17, 2026

Summary

Introduces the OrchardCore.OpenApi module, providing OpenAPI specification generation and three interactive API documentation UIs for Orchard Core.

  • Swagger UI (/swagger) — Interactive API explorer with "Try it out" support
  • ReDoc (/redoc) — Read-only API reference documentation
  • Scalar (/scalar/v1) — Modern API reference with built-in HTTP client

Each UI can be individually enabled/disabled from the admin settings page (Settings > OpenApi). All endpoints are protected by the ApiViewContent permission (granted to Administrators by default) — unauthenticated users are redirected to /admin, unauthorized users receive 403.

Authentication

The module supports two authentication modes for the "Try it out" / "Send" buttons:

  • Cookie authentication (default) — Works out of the box. If you're logged into the admin, API calls from the UIs automatically include your session cookie. No configuration needed.
  • OAuth2 Authorization Code + PKCE — Configurable from the settings page. Adds an "Authorize" button to Swagger UI and Scalar. The OAuth2 endpoints can point to the local OpenID Connect server, a different tenant, or an external provider.

What's included

Component Description
Startup.cs Registers OpenAPI spec generation (ASP.NET Core + Swashbuckle), conditionally enables UIs, adds auth middleware
OpenApiSettings Site-level settings: UI toggles + OAuth2 configuration (Authorization URL, Token URL, Client ID, Scopes)
OpenApiSettingsDisplayDriver Admin settings page driver
OpenApiPermissions ApiViewContent permission
ProblemDetailsApiControllerExtensions Extension methods for standardized RFC 9457 error responses (ApiBadRequestProblem, ApiNotFoundProblem, ApiValidationProblem, etc.)
OrchardCore.OpenApi.nswag NSwag configuration for generating TypeScript (Axios) and C# (HttpClient) clients from the live spec
Documentation Full docs at src/docs/reference/modules/OpenApi/README.md

New dependencies

  • Microsoft.AspNetCore.OpenApi 10.0.5
  • Scalar.AspNetCore 2.0.0
  • Swashbuckle.AspNetCore.SwaggerGen / SwaggerUI / ReDoc 10.1.4

TODO:

  • Generate NSwag files with all modules that provides an API endpoint enabled. It is currently generated against the "TheBlog" recipe only.

Skrypt and others added 30 commits July 18, 2025 02:58
This is a work in progress. Pushing a PR to share.
# Conflicts:
#	Directory.Packages.props
#	OrchardCore.sln
#	src/OrchardCore.Build/TargetFrameworks.props
Refactor all Cypress functional tests in a 1:1 migration to Playwright.
The CI runners have Yarn 1.x globally but the project uses Yarn 4.9.4
via packageManager field. Adding corepack enable ensures the correct
Yarn version is used. Also removes unnecessary cd into subdirectory
for functional_all_db.yml since yarn workspace commands run from root.
* Initial plan

* Refactor Playwright functional tests from TypeScript to C#

- Remove TypeScript Playwright test project (test/OrchardCore.Tests.Playwright)
- Create C# Playwright test project at test/OrchardCore.Tests.Functional
- Add xUnit v3 test classes mirroring all original TS tests
- Add helper classes for auth, tenants, configuration, lifecycle, etc.
- Update all CI workflows to use dotnet test instead of yarn/npm
- Update OrchardCore.slnx, Directory.Packages.props, AGENTS.md
- Revert root package.json (remove Playwright workspace/scripts)

Co-authored-by: Skrypt <3228637+Skrypt@users.noreply.github.com>

* Fix code review feedback: use base-32 encoding and static members

Co-authored-by: Skrypt <3228637+Skrypt@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Skrypt <3228637+Skrypt@users.noreply.github.com>
… TypeScript → C# migration (#18992)

* Initial plan

* Fix CI workflows by removing obsolete Node.js setup step

Co-authored-by: Skrypt <3228637+Skrypt@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Skrypt <3228637+Skrypt@users.noreply.github.com>
….csproj

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…18994)

* Initial plan

* Fix: only delete migrations recipe if it was copied by us in this run

Co-authored-by: Skrypt <3228637+Skrypt@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Skrypt <3228637+Skrypt@users.noreply.github.com>
* Initial plan

* Refactor CMS tests to use CmsTestBase, eliminating duplicate tenant setup logic

Co-authored-by: Skrypt <3228637+Skrypt@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Skrypt <3228637+Skrypt@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Initial plan

* Fix BrowserContext leak in CreatePageAsync by closing context when page closes

Co-authored-by: Skrypt <3228637+Skrypt@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Skrypt <3228637+Skrypt@users.noreply.github.com>
…stion merge (#18997)

* Initial plan

* Fix CS1513 syntax error in TenantHelper.cs - malformed review suggestion merge

Co-authored-by: Skrypt <3228637+Skrypt@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Skrypt <3228637+Skrypt@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
* Initial plan

* fix: address review comments - HttpClient timeout and external site setup detection

Co-authored-by: Skrypt <3228637+Skrypt@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Skrypt <3228637+Skrypt@users.noreply.github.com>
Add an AllowAnonymousSchemaAccess setting (default: true) that controls
whether the JSON schema endpoints (/swagger/v1/swagger.json,
/openapi/v1.json) can be accessed without authentication. When disabled,
these endpoints require the ApiManage permission, returning 401 for
unauthenticated and 403 for unauthorized requests. This allows
administrators to temporarily expose the schema for code generators like
NSwag and lock it down otherwise.
@Skrypt
Copy link
Copy Markdown
Contributor Author

Skrypt commented Mar 21, 2026

@sebastienros Done, I moved them to features. The UI now only shows which UI is enabled.
Also, I added a checkbox to temporarly enable anonymous users to be able to fetch the OpenApi schemas.
That's mainly because it is easier than adding auth configurations in NSwag Studio to fetch the schema.
Also, less dangerous than what we did historically most of time by allowing these schema to anonymous users.

image

Skrypt added 5 commits March 21, 2026 11:30
Replace references to removed EnableSwaggerUI/ReDocUI/ScalarUI
checkboxes with feature enablement via FeatureHelper. Tests now enable
the individual sub-features (SwaggerUI, ReDocUI, ScalarUI) instead of
toggling settings checkboxes, and assert against the new
AllowAnonymousSchemaAccess element on the settings page.
Add explicit endpoint names (operationId) to all API controllers and
minimal API endpoints using [EndpointName] and .WithName() respectively.
This prevents NSwag from generating ambiguous method names like
ContentGET2Async by giving each operation a unique, descriptive
identifier. All names are prefixed with "Api" to avoid collisions with
existing admin route names. Also adds an OpenApi generation recipe to
the OpenApi module that enables all features exposing API endpoints.
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has merge conflicts. Please resolve those before requesting a review.

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has merge conflicts. Please resolve those before requesting a review.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

This pull request has merge conflicts. Please resolve those before requesting a review.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants