概要
DrupalでOpenAPIを有効にする機会がありましたので、その備忘録です。なお、以下のjson:apiモジュールを有効化済みです。
モジュールのインストール
以下の2つのモジュールをインストールします。
OpenAPI
This module allows you to make your Drupal information architecture (as exposed by your web service of choice) discoverable using the OpenAPI standard.
OpenAPI for JSON:API
Integrates with the base OpenAPI module to generate the definitions for JSON:API. Version notes Versions 2.x and 3.x implement version 2 of the Open API specification.
結果、以下のURLで、jsonを取得することができます。
/openapi/jsonapi

以下にアクセスすると、「No UI ...」と表示されます。次に、UIを追加してみます。
/admin/config/services/openapi

UIの追加
以下の2つのモジュールをインストールします。
OpenAPI UI
The OpenAPI UI module implements an API around displaying OpenAPI specs inside a Drupal site. This library implements a plugin base which can be used to initialize a API explorer UI within your site.
ReDoc for OpenAPI UI
ReDoc is a javascript library which allows a user to explore the api documentation for a web services API.
結果、「Explore」のボタンが表示されます。

ボタンをクリックすると、以下の画面に遷移します。
/admin/config/services/openapi/redoc/jsonapi
Swagger UIライクな画面が表示されます。

なお、Redocは、以下のように説明されていました。
Redoc is an open-source tool for generating documentation from OpenAPI (fka Swagger) definitions.
GitHub - Redocly/redoc: 📘 OpenAPI/Swagger-generated API Reference Documentation
📘 OpenAPI/Swagger-generated API Reference Documentation - Redocly/redoc
参考
以下の「Swagger UI for OpenAPI UI」についてもインストールしてみましたが、私の環境ではエラーが出てしまいました。
Swagger UI for OpenAPI UI
Swagger UI is a javascript library which allows a user to explore the api documentation for a web services API.
まとめ
DrupalでOpenAPIを利用される際の参考になりましたら幸いです。



コメント
…