> 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/hajimeni/configuration.md).

# 設定

設定はイニシャライザに記述します。すべての設定は任意です。

```ruby
# config/initializers/rails_openapi_generator.rb
RailsOpenapiGenerator.configure do |config|
  config.output_path             = "doc/openapi.yaml"
  config.title                   = "My Store API"
  config.api_version             = "2.0.0"
  config.route_filter            = ->(route) { route.path.start_with?("/api/") }
  config.exclude_source_paths    = ["vendor/", %r{app/controllers/legacy/}]
  config.method_resolution_depth = 5
end
```

## 設定項目一覧

| 設定                        | デフォルト                | 説明                                  |
| ------------------------- | -------------------- | ----------------------------------- |
| `output_path`             | `"doc/openapi.json"` | specファイルの出力先                        |
| `format`                  | 拡張子から自動判定            | `:json` または `:yaml`                 |
| `title`                   | アプリ名                 | specの`info.title`                   |
| `api_version`             | `"1.0.0"`            | specの`info.version`                 |
| `route_filter`            | すべて含む                | ルートごとに呼ばれるlambda — `false`を返すと除外    |
| `exclude_source_paths`    | `[]`                 | コントローラのソースファイルパスに対してマッチする文字列または正規表現 |
| `method_resolution_depth` | `5`                  | ヘルパー・コールバックチェーンを追跡する深さ              |

## output\_path と format

```ruby
config.output_path = "doc/openapi.json"   # JSON出力
config.output_path = "doc/openapi.yaml"   # YAML出力
config.output_path = "doc/openapi.yml"    # YAMLも可
```

フォーマットは拡張子から自動判定されます。`config.format`で明示的に指定することもできます。

```ruby
config.format = :yaml
```

## title と api\_version

OpenAPIの`info`オブジェクトに直接対応します。

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "My Store API",
    "version": "2.0.0"
  }
}
```

## route\_filter

ルートオブジェクトを受け取り、`true`で含める・`false`で除外するlambdaです。APIネームスペースに限定する場合などに便利です。

```ruby
# /api/ 以下のルートのみ含める
config.route_filter = ->(route) { route.path.start_with?("/api/") }

# 特定のパスを除外
config.route_filter = ->(route) { !route.path.start_with?("/internal/") }

# JSON対応のverbのみ
config.route_filter = ->(route) { %w[GET POST PUT PATCH DELETE].include?(route.verb) }
```

詳しくは[ルートフィルタリング](/rails-openapi-generator/ja/gaido/route-filtering.md)を参照してください。

## exclude\_source\_paths

コントローラのソースファイルパスに対してマッチする文字列または正規表現の配列です。少なくとも1つのエントリにマッチしたコントローラは除外されます。

```ruby
config.exclude_source_paths = [
  "vendor/",                            # vendor/ 以下のすべて
  %r{app/controllers/admin/},           # adminネームスペース
  "app/controllers/devise/",            # Deviseコントローラ
]
```

## method\_resolution\_depth

ヘルパーメソッドの呼び出しや`before_action`コールバック、`rescue_from`ハンドラを追跡する際に、何段階まで深く追うかを制御します。

```ruby
config.method_resolution_depth = 5   # デフォルト
```

深くネストされたヘルパーチェーンがある場合は増やしてください。大規模アプリで速度を優先する場合は減らすこともできます。

## コマンドラインでの一時的な上書き

```sh
rake openapi:generate OUTPUT=tmp/openapi.yaml FORMAT=yaml
```

`OUTPUT`と`FORMAT`は、その1回の実行のみイニシャライザの設定を上書きします。

## CLIの場合

```sh
bundle exec rails-openapi-generator \
  --rails-root . \
  --output doc/openapi.json
```


---

# 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/hajimeni/configuration.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.
