Orchardcore openapi

From CrestApps/CrestApps.AgentSkills · View interactive version

Orchardcore openapi is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for the Orchard Core 4.0 OpenAPI module. Covers OpenAPI and Swagger schema generation, the Swagger UI, ReDoc and Scalar documentation sub-features, silent authorization-code plus PKCE sign-in for Try it out requests, the OpenApiPkce and OpenApiGeneration recipes, the AllowAnonymousSchemaAccess

How to use this skill

Skill file

Orchard Core OpenAPI - Prompt Templates

Document and Explore Orchard Core APIs

You are an Orchard Core expert. Generate configuration, recipes, and code for the OrchardCore.OpenApi module, which ships with Orchard Core 4.0.

Guidelines

Installing the Package

The module is part of the OrchardCore.Application.Cms.Targets bundle. For a custom host, reference it in the web (startup) project:

<PackageReference Include="OrchardCore.OpenApi" Version="4.*" />

Features

| Feature | ID | URL |

|---|---|---|

| OpenApi | OrchardCore.OpenApi | /swagger/v1/swagger.json, /openapi/v1.json |

| OpenApi Swagger UI | OrchardCore.OpenApi.SwaggerUI | /swagger |

| OpenApi ReDoc UI | OrchardCore.OpenApi.ReDocUI | /redoc |

| OpenApi Scalar UI | OrchardCore.OpenApi.ScalarUI | /scalar/v1 |

All URLs are relative to the tenant, so a tenant with the customer-a prefix serves /customer-a/swagger.

Enabling the Documentation UIs

{
  "steps": [
    {
      "name": "feature",
      "enable": [
        "OrchardCore.OpenApi",
        "OrchardCore.OpenApi.SwaggerUI",
        "OrchardCore.OpenApi.ScalarUI"
      ]
    }
  ]
}

Settings

Settings → OpenApi shows which UIs are enabled and exposes one setting, OpenApiSettings.AllowAnonymousSchemaAccess (default false):

{
  "steps": [
    {
      "name": "settings",
      "OpenApiSettings": {
        "AllowAnonymousSchemaAccess": true
      }
    }
  ]
}

Enable anonymous schema access only on tenants used for client generation. The schema lists every API route and its parameters.

Provisioning Silent Sign-In with the OpenApiPkce Recipe

Run OpenAPI Documentation — Bearer/PKCE (OpenApiPkce) from Tools → Recipes. It enables OrchardCore.OpenApi, OrchardCore.OpenId.Server, OrchardCore.OpenId.Validation, and OrchardCore.OpenId.Management, turns on the authorization code flow with PKCE required, configures local token validation, and registers a public openapi client. The equivalent custom recipe looks like this:

{
  "steps": [
    {
      "name": "feature",
      "enable": [
        "OrchardCore.OpenApi",
        "OrchardCore.OpenId.Management",
        "OrchardCore.OpenId.Server",
        "OrchardCore.OpenId.Validation"
      ]
    },
    {
      "name": "OpenIdServerSettings",
      "EnableTokenEndpoint": true,
      "EnableAuthorizationEndpoint": true,
      "EnableLogoutEndpoint": true,
      "EnableUserInfoEndpoint": true,
      "AllowAuthorizationCodeFlow": true,
      "RequireProofKeyForCodeExchange": true
    },
    {
      "name": "OpenIdValidationSettings",
      "Tenant": "Default"
    },
    {
      "name": "OpenIdApplication",
      "ClientId": "openapi",
      "DisplayName": "OpenAPI Interactive UI",
      "Type": "public",
      "ConsentType": "implicit",
      "AllowAuthorizationCodeFlow": true,
      "AllowLogoutEndpoint": true,
      "RequireProofKeyForCodeExchange": true,
      "RedirectUris": "https://cms.example.com/OrchardCore.OpenApi/openapi-oidc-silent.html",
      "PostLogoutRedirectUris": "https://cms.example.com/",
      "ScopeEntries": [
        { "Name": "email" },
        { "Name": "profile" },
        { "Name": "roles" }
      ]
    }
  ]
}

Adjust before running:

Generating Clients with NSwag

The OpenApiGeneration recipe enables the API features (Contents, Media, Media TUS, Queries, Tenants, Lucene, Elasticsearch, OpenApi) and turns on AllowAnonymousSchemaAccess. Its settings step replaces the stored OpenApi settings, so run it on a throwaway generation tenant.

dotnet tool install -g NSwag.ConsoleCore
# Against a running site with anonymous schema access enabled
nswag openapi2csclient /input:https://localhost:5001/swagger/v1/swagger.json /output:OrchardClient.cs /namespace:MyApp.OrchardClient

In the Orchard Core repository, dotnet run --project tools/OpenApiClientGenerator -c Release boots the CMS in-process with the OpenApiGenerationSetup recipe and regenerates the bundled clients headlessly. Operations are sorted by route and verb, so unchanged APIs regenerate byte-identical clients.

Without anonymous access, fetch the schema with an Authorization: Bearer <token> header for a user that has ViewOpenApiContent.

Documenting a Custom API Endpoint

Endpoints appear in the document when they are API controllers or minimal APIs with an HTTP method. Secure them with the Api scheme and describe every response:

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using OrchardCore;

namespace MyModule.Controllers;

[ApiController]
[Route("api/inventory")]
[Authorize(AuthenticationSchemes = OrchardCoreConstants.AuthenticationSchemes.Api)]
public sealed class InventoryController : ControllerBase
{
    /// <summary>
    /// Gets the stock level of a product.
    /// </summary>
    [HttpGet("{sku}", Name = "ApiGetInventory")]
    [ProducesResponseType(typeof(InventoryDto), StatusCodes.Status200OK)]
    [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
    public IActionResult Get(string sku)
    {
        return Ok(new InventoryDto { Sku = sku, Quantity = 10 });
    }
}

public sealed class InventoryDto
{
    public string Sku { get; set; }

    public int Quantity { get; set; }
}

Upgrading from 3.x

Troubleshooting

| Symptom | Check |

|---|---|

| 401 on Try it out | Run OpenApiPkce, confirm OrchardCore.OpenId.Validation is enabled and OpenIdValidationSettings.Tenant is set. |

| Silent sign-in fails | The redirect URI must match origin, tenant prefix, and /OrchardCore.OpenApi/openapi-oidc-silent.html; check the browser console for [openapi-ui] errors. |

| Token acquired but 401/403 from the API | The signed-in user's roles lack the endpoint permission. |

| NSwag gets 401 for swagger.json | Enable AllowAnonymousSchemaAccess on a generation tenant or send a bearer token. |

| /swagger returns 404 | Enable OrchardCore.OpenApi.SwaggerUI. |

| Endpoint missing from the document | Its feature is disabled, it lacks an HTTP method attribute, or the app was not restarted. |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.