Drupal is a registered trademark of Dries Buytaert
drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

swagger_php

9 sites Security covered
View on drupal.org

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/

Activity

Total releases
4
First release
Nov 2025
Latest release
4 months ago
Release cadence
0 days
Stability
0% stable

Release Timeline

Releases

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