# OpenAPI

REST API のドキュメントを手作業で作成するのは、時間のかかる作業です。幸い、GitBook では OpenAPI ドキュメントをインポートできるため、この作業を効率化できます。OpenAPI ドキュメントには、API の構造と機能の詳細が記載されています。

OpenAPI Specification（OAS）は、開発者が REST API を文書化するために使用するフレームワークです。JSON または YAML で記述され、すべてのエンドポイント、パラメータ、スキーマ、認証方式を一覧化します。

GitBook にインポートすると、これらのドキュメントはインタラクティブでテスト可能な API ブロックに変換され、仕様がファイルとして提供されている場合でも URL から読み込まれる場合でも、API メソッドを視覚的に表現します。

GitBook は [Swagger 2.0](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md) または [OpenAPI 3.0](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md) 準拠ファイル。

{% openapi src="<https://petstore3.swagger.io/api/v3/openapi.json>" path="/pet" method="post" %}
<https://petstore3.swagger.io/api/v3/openapi.json>
{% endopenapi %}

### テストする（Scalar 搭載）

GitBook の OpenAPI ブロックには「テストする」機能もあり、エディタで入力されたデータやパラメータを使って、ユーザーが API メソッドをテストできます。

提供: [Scalar](https://scalar.com/)、ドキュメントを離れずに API メソッドの動作を確認できます。上の例をご覧ください。

#### FAQ

<details>

<summary>なぜ私の仕様は読み込まれないのですか？</summary>

{% hint style="info" %}
**注：** この情報は次にのみ適用されます **URL で追加された仕様**.
{% endhint %}

仕様を URL 経由で追加した場合、API では次を許可する必要があります [クロスオリジンを許可する](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Origin) ドキュメントサイトからの GET リクエストを許可してください。API の CORS 設定で、ドキュメントがホストされている正確なオリジンを許可します（例： `https://your-site.gitbook.io` または `https://docs.example.com`）。\
\
エンドポイントが公開されており、資格情報を使用しない場合は、次のヘッダーを返すこともできます： `Access-Control-Allow-Origin: *`\ <br>

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitbook.com/docs/documentation/ja-gitbook-documentation/api-references/openapi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
