From 5f22ab9e05a4a5ae80db57e9111dbd9577c29600 Mon Sep 17 00:00:00 2001 From: Martin Chudoba Date: Fri, 27 Nov 2026 10:07:04 +0100 Subject: [PATCH 1/3] docs(openapi): register Swagger UI plugins Document the window.apiPlatformSwaggerUiPlugins hook and how to load a custom script in the documentation page with Symfony and Laravel. --- core/configuration.md | 26 +++++++++++------ core/openapi.md | 67 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 9 deletions(-) diff --git a/core/configuration.md b/core/configuration.md index 5b2ff83a8db..720b255d841 100644 --- a/core/configuration.md +++ b/core/configuration.md @@ -555,23 +555,31 @@ return [ ], ], - 'swagger' => [ - // The active versions of OpenAPI to be exported or used in the swagger_ui. The first value is the default. - 'versions' => [2, 3], + 'swagger_ui' => [ + // Enable or disable Swagger UI. + 'enabled' => true, + + // The API keys Swagger UI can send, indexed by the name of the security scheme. + 'apiKeys' => [ + 'api' => [ + // The name of the header or query parameter containing the API key. + 'name' => 'Authorization', + + // Whether the API key should be a query parameter or a header. + 'type' => 'header', + ], + ], - // The swagger API keys. - 'api_keys' => [], + // If set to true, it persists authorization data and it would not be lost on browser close/refresh + 'persist_authorization' => true, - 'swagger_ui_extra_configuration' => [ + 'extra_configuration' => [ // Controls the default expansion setting for the operations and tags. It can be 'list' (expands only the tags), 'full' (expands the tags and operations) or 'none' (expands nothing). 'docExpansion' => 'list', // If set, enables filtering. The top bar will show an edit box that you can use to filter the tagged operations that are shown. 'filter' => false, - // If set to true, it persists authorization data and it would not be lost on browser close/refresh - 'persistAuthorization' => true, - // You can use any other configuration parameters too. ], ], diff --git a/core/openapi.md b/core/openapi.md index 21ff6265376..71bab616e5b 100644 --- a/core/openapi.md +++ b/core/openapi.md @@ -890,6 +890,73 @@ You may want to copy the [one shipped with API Platform](https://github.com/api-platform/core/blob/main/src/Laravel/resources/views/swagger-ui.blade.php) and customize it. +## Registering Swagger UI Plugins + +[Swagger UI plugins](https://swagger.io/docs/open-source-tools/swagger-ui/customization/plugin-api/) +are JavaScript functions that must be passed to Swagger UI when it is created, so they cannot be set +with the `swagger_ui_extra_configuration` option. Instead, API Platform passes every plugin found in +the `window.apiPlatformSwaggerUiPlugins` array, which means you don't have to override the script +that initializes Swagger UI. + +Push your plugin to this array from your own script: + +```javascript +// public/js/swagger-ui-plugin.js +(window.apiPlatformSwaggerUiPlugins ||= []).push(function NoticePlugin() { + return { + wrapComponents: { + // Renders a notice above the title and description of the API + InfoContainer: + (Original, { React }) => + (props) => + React.createElement( + "div", + null, + React.createElement("p", null, "This is the staging environment."), + React.createElement(Original, props), + ), + }, + }; +}); +``` + +Then load this script in the documentation page. It only has to run before the `load` event of the +page, so it can be added after the scripts of API Platform. + +For a complete example, see +[swagger-ui-login-plugin](https://github.com/ViPErCZ/swagger-ui-login-plugin), a community plugin +that logs in from Swagger UI and authorizes with the returned token. + +### Registering Swagger UI Plugins using Symfony + +Extend the Twig template of API Platform and add your script to the `javascript` block (use the +`stylesheet` block for stylesheets): + +```twig +{# templates/bundles/ApiPlatformBundle/SwaggerUi/index.html.twig #} +{% extends '@!ApiPlatform/SwaggerUi/index.html.twig' %} + +{% block javascript %} + {{ parent() }} + +{% endblock %} +``` + +### Registering Swagger UI Plugins using Laravel + +The documentation page includes two optional views. Create them in your application to add your own +scripts and stylesheets, there is no need to override the whole Blade template: + +```html +{{-- resources/views/vendor/api-platform/swagger-ui-javascript.blade.php --}} + +``` + +```html +{{-- resources/views/vendor/api-platform/swagger-ui-stylesheet.blade.php --}} + +``` + ## Compatibility Layer with Amazon API Gateway [AWS API Gateway](https://aws.amazon.com/api-gateway/) supports OpenAPI partially, but it From 5a0a163a44ad3c2e3a1ac5dcc322c78b34b48e74 Mon Sep 17 00:00:00 2001 From: Martin Chudoba Date: Fri, 27 Nov 2026 10:23:22 +0100 Subject: [PATCH 2/3] docs(graphql): format the pagination examples with Prettier 3.10 The CI runs an unpinned Prettier, and its latest release reformats the empty selection sets of two GraphQL snippets. --- core/graphql.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core/graphql.md b/core/graphql.md index d6777e29bea..d4344d088af 100644 --- a/core/graphql.md +++ b/core/graphql.md @@ -1273,8 +1273,7 @@ To get the next page, you would add the `endCursor` from the current page as the ```graphql { - offers(first: 10, after: "endCursor") { - } + offers(first: 10, after: "endCursor") {} } ``` @@ -1283,8 +1282,7 @@ parameter. ```graphql { - offers(last: 10, before: "startCursor") { - } + offers(last: 10, before: "startCursor") {} } ``` From d4ec288bca51f304d77bdbe0101e145676ce696d Mon Sep 17 00:00:00 2001 From: soyuka Date: Thu, 3 Dec 2026 13:17:27 +0100 Subject: [PATCH 3/3] docs(openapi): republish the Laravel assets for the hook --- core/openapi.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/openapi.md b/core/openapi.md index 48ab40d9d70..d2dd3727025 100644 --- a/core/openapi.md +++ b/core/openapi.md @@ -1033,6 +1033,9 @@ scripts and stylesheets, there is no need to override the whole Blade template: ``` +Existing applications must re-publish the assets to get the `apiPlatformSwaggerUiPlugins` hook: +`php artisan vendor:publish --tag=api-platform-assets --force`. + ## Compatibility Layer with Amazon API Gateway [AWS API Gateway](https://aws.amazon.com/api-gateway/) supports OpenAPI partially, but it