> For the complete documentation index, see [llms.txt](https://tonystrawberry.gitbook.io/rails-openapi-generator/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tonystrawberry.gitbook.io/rails-openapi-generator/ja/ji-neng/html-and-file-responses.md).

# HTMLページとファイルダウンロード

すべてのエンドポイントがJSONを返すわけではありません。ジェネレーターはHTMLページのレンダーとファイルダウンロードのレスポンスを認識し、spec内で適切に分類します。

## HTMLページ

アクションが`.html.*`ビューファイルに解決されるテンプレートをレンダーする場合、レスポンスはHTMLページレスポンスとして分類されます。

```ruby
class PagesController < ApplicationController
  def home
    render :home   # → app/views/pages/home.html.erbに解決
  end
end
```

→ 以下のレスポンスエントリが生成されます。

* `content-type`: `text/html`
* OpenAPIタグ: `"HTML Pages"`
* 拡張: `x-renders-html: true`
* ボディスキーマなし（HTMLは機械読み取り不可）

HTMLページのオペレーションはレンダリングされたドキュメント内で別の`"HTML Pages"`タグの下にグループ化され、APIエンドポイントと区別しやすくなります。

## ファイルダウンロード

アクションが`send_file`または`send_data`を呼び出す場合（直接または ヘルパーラッパー経由）、レスポンスはファイルダウンロードとして分類されます。

```ruby
def download
  send_file Rails.root.join("storage", params[:filename]),
            disposition: :attachment
end
```

→ 以下のレスポンスエントリが生成されます。

* `content-type`: `application/octet-stream`
* OpenAPIタグ: `"File Downloads"`
* 拡張: `x-sends-file: true`
* ボディスキーマなし

### ヘルパーラッパー

ジェネレーターは`send_file`/`send_data`の呼び出しを`method_resolution_depth`レベルまで追跡します。

```ruby
def export
  deliver_csv_attachment("users.csv", User.all.to_csv)
end

private

def deliver_csv_attachment(filename, content)
  send_data content, filename: filename, type: "text/csv", disposition: :attachment
end
```

→ `send_data`がヘルパー内にあっても、`export`はファイルダウンロードとして分類されます。

## 混合レスポンス（respond\_to）

アクションが`respond_to`を使って複数のコンテンツタイプを提供する場合、すべてのアクティブなブランチが1つのステータスコード下にまとめられます。

```ruby
def show
  respond_to do |format|
    format.json { render json: @user }
    format.html
  end
end
```

→ `200`レスポンスエントリに2つのコンテンツタイプエントリ: `application/json`（スキーマあり）と`text/html`。

## リダイレクト

[ステータスコード → リダイレクト](https://tonystrawberry.gitbook.io/rails-openapi-generator/ja/ji-neng/pages/ZVnWoN8jPqXvPaZSO1VY#リダイレクト)を参照してください。リダイレクトは適切な3xxステータスコードとボディスキーマなしのレスポンスエントリを生成します。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://tonystrawberry.gitbook.io/rails-openapi-generator/ja/ji-neng/html-and-file-responses.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
