Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Release: Opensolr Search 4.5.0 Minor update available for module opensolr_search (4.5.0). Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Usage Milestone: Simplify Module simplify crossed 10,000 active installs. Usage Milestone: Views Reference Filter Module entityreference_filter crossed 10,000 active installs. Usage Milestone: Dropdown Language Module dropdown_language crossed 10,000 active installs. Usage Milestone: Paragraphs Browser Module paragraphs_browser crossed 10,000 active installs. Usage Milestone: OpenAPI Module openapi crossed 10,000 active installs. Usage Milestone: Decoupled Router Module decoupled_router crossed 10,000 active installs. Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

This module enables you to document your Drupal code using PHP attributes. It then generates an OpenAPI 3 specification and a documentation user interface based on these attributes.

This module uses the zircote/swagger-php library to let you document your
Drupal code, and generate an OpenAPI 3 specification and documentation UI, based on those PHP attributes.

Installation

  • Install this module and its dependencies via Composer.
  • Install the swagger-api/swagger-ui library in your /libraries folder.

    See https://www.drupal.org/project/openapi_ui_swagger#installation-composer
  • Enable the swagger_php module
  • Use the zircote/swagger-php library PHP attributes to document your API,
    e.g. a custom RestResource plugin you have created.

Example usage

Say we have created a custom RestResource plugin, and want to document this API endpoint via the OpenAPI 3 specification.


namespace Drupal\my_custom_api\Plugin\rest\resource;

use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\rest\Attribute\RestResource;
use Drupal\rest\ModifiedResourceResponse;
use Drupal\rest\Plugin\ResourceBase;
use OpenApi\Attributes as OA;

/**
 * My custom API endpoint.
 */
#[OA\Info(
  version: "1.0.0",
  description: "API documentation for my custom API",
  title: "My Custom API"
)]
#[RestResource(
  id: 'my_custom_resource',
  label: new TranslatableMarkup('Custom API endpoint to send data to.'),
  uri_paths: [
    'create' => '/api/v1/custom/add',
  ],
)]
class MyCustomResource extends ResourceBase {

  /**
   * Responds to POST requests and saves the data.
   */
  #[OA\Post(path: '/api/v1/custom/add', operationId: 'my_custom_resource_add')]
  #[OA\Response(response: '200', description: 'The processed data')]
  public function post(array $data): ModifiedResourceResponse {}

}

This renders the following API documentation page + an OpenAPI 3 compatible JSON specification file:

More information: https://zircote.github.io/swagger-php/

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
4
Tracked since
Nov 2025
Latest release
9 months ago
Releases (12 mo)
4 ▲ from 0
Maintenance
Slowing

Release Timeline

Releases

Version Type Core Release date
1.0.0-alpha3 Pre-release 10–11 Nov 20, 2025
1.0.0-alpha2 Pre-release 10–11 Nov 19, 2025
1.0.x-dev Dev 10–11 Nov 19, 2025
1.0.0-alpha1 Pre-release 10–11 Nov 19, 2025