Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌐 Add Japanese translation for docs/ja/docs/tutorial/body-multiple-params.md #1903

Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/en/mkdocs.yml
Expand Up @@ -22,6 +22,7 @@ nav:
- Languages:
- en: /
- es: /es/
- ja: /ja/
- it: /it/
- pt: /pt/
- ru: /ru/
Expand Down
1 change: 1 addition & 0 deletions docs/es/mkdocs.yml
Expand Up @@ -22,6 +22,7 @@ nav:
- Languages:
- en: /
- es: /es/
- ja: /ja/
- it: /it/
- pt: /pt/
- ru: /ru/
Expand Down
443 changes: 443 additions & 0 deletions docs/ja/docs/index.md

Large diffs are not rendered by default.

169 changes: 169 additions & 0 deletions docs/ja/docs/tutorial/body-multiple-params.md
@@ -0,0 +1,169 @@
# ボディ - 複数のパラメータ

これまで`Path`と`Query`をどう使うかを見てきましたが、リクエストボディの宣言のより高度な使い方を見てみましょう。

## `Path`、`Query`とボディパラメータを混ぜる

まず、もちろん、`Path`と`Query`とリクエストボディのパラメータの宣言は自由に混ぜることができ、 **FastAPI** は何をするべきかを知っています。

また、デフォルトの`None`を設定することで、ボディパラメータをオプションとして宣言することもできます:

```Python hl_lines="17 18 19"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hl_lines="19 20 21"

{!../../../docs_src/body_multiple_params/tutorial001.py!}
```

!!! note "備考"
この場合、ボディから取得する`item`はオプションであることに注意してください。デフォルト値は`None`です。

## 複数のボディパラメータ

上述の例では、*path operations*は`item`の属性を持つ以下のようなJSONボディを期待していました:

```JSON
{
"name": "Foo",
"description": "The pretender",
"price": 42.0,
"tax": 3.2
}
```

しかし、`item`と`user`のように複数のボディパラメータを宣言することもできます:

```Python hl_lines="20"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hl_lines="22"

{!../../../docs_src/body_multiple_params/tutorial002.py!}
```

この場合、**FastAPI**は関数内に複数のボディパラメータ(Pydanticモデルである2つのパラメータ)があることに気付きます。

そのため、パラメータ名をボディのキー(フィールド名)として使用し、以下のようなボディを期待しています:

```JSON
{
"item": {
"name": "Foo",
"description": "The pretender",
"price": 42.0,
"tax": 3.2
},
"user": {
"username": "dave",
"full_name": "Dave Grohl"
}
}
```

!!! note "備考"
以前と同じように`item`が宣言されていたにもかかわらず、`item`はキー`item`を持つボディの内部にあることが期待されていることに注意してください。

**FastAPI** はリクエストから自動で変換を行い、パラメータ`item`が特定の内容を受け取り、`user`も同じように特定の内容を受け取ります。

複合データの検証を行い、OpenAPIスキーマや自動ドキュメントのように文書化してくれます。

## ボディ内の単数値

クエリとパスパラメータの追加データを定義するための `Query` と `Path` があるのと同じように、 **FastAPI** は同等の `Body` を提供します。

例えば、前のモデルを拡張して、同じボディに `item` と `user` の他にもう一つのキー `importance` を入れたいと決めることができます。

単数値なのでそのまま宣言すると、**FastAPI** はそれがクエリパラメータであるとみなします。

しかし、`Body`を使用して、**FastAPI** に別のボディキーとして扱うように指示することができます:


```Python hl_lines="21"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hl_lines="23"

{!../../../docs_src/body_multiple_params/tutorial003.py!}
```

この場合、**FastAPI** は以下のようなボディを期待します:


```JSON
{
"item": {
"name": "Foo",
"description": "The pretender",
"price": 42.0,
"tax": 3.2
},
"user": {
"username": "dave",
"full_name": "Dave Grohl"
},
"importance": 5
}
```

繰り返しになりますが、データ型の変換、検証、文書化などを行います。

## 複数のボディパラメータとクエリ

もちろん、ボディパラメータに加えて、必要に応じて追加のクエリパラメータを宣言することもできます。

デフォルトでは、単数値はクエリパラメータとして解釈されるので、明示的に `Query` を追加する必要はありません。

```Python
q: str = None
```

以下において:

```Python hl_lines="25"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hl_lines="27"

{!../../../docs_src/body_multiple_params/tutorial004.py!}
```

!!! info "情報"
`Body`もまた、後述する `Query` や `Path` などと同様に、すべての検証パラメータとメタデータパラメータを持っています。


## 単一のボディパラメータの埋め込み

Pydanticモデル`Item`のボディパラメータ`item`を1つだけ持っているとしましょう。

デフォルトでは、**FastAPI**はそのボディを直接期待します。

しかし、追加のボディパラメータを宣言したときのように、キー `item` を持つ JSON とその中のモデルの内容を期待したい場合は、特別な `Body` パラメータ `embed` を使うことができます:

```Python
item: Item = Body(..., embed=True)
```

以下において:

```Python hl_lines="17"
{!../../../docs_src/body_multiple_params/tutorial005.py!}
```

この場合、**FastAPI** は以下のようなボディを期待します:

```JSON hl_lines="2"
{
"item": {
"name": "Foo",
"description": "The pretender",
"price": 42.0,
"tax": 3.2
}
}
```

以下の代わりに:

```JSON
{
"name": "Foo",
"description": "The pretender",
"price": 42.0,
"tax": 3.2
}
```

## まとめ

リクエストが単一のボディしか持てない場合でも、*path operation関数*に複数のボディパラメータを追加することができます。

しかし、**FastAPI** はそれを処理し、関数内の正しいデータを与え、*path operation*内の正しいスキーマを検証し、文書化します。

また、ボディの一部として受け取る単数値を宣言することもできます。

また、単一のパラメータしか宣言されていない場合でも、ボディをキーに埋め込むように **FastAPI** に指示することができます。
81 changes: 81 additions & 0 deletions docs/ja/docs/tutorial/index.md
@@ -0,0 +1,81 @@
# チュートリアル - ユーザーガイド - はじめに

このチュートリアルは**FastAPI**のほぼすべての機能の使い方を段階的に紹介します。

各セクションは前のセクションを踏まえた内容になっています。しかし、トピックごとに分割されているので、特定のAPIの要求を満たすようなトピックに直接たどり着けるようになっています。

また、将来的にリファレンスとして機能するように構築されています。

従って、後でこのチュートリアルに戻ってきて必要なものを確認できます。

## コードを実行する

すべてのコードブロックをコピーして直接使用できます(実際にテストされたPythonファイルです)。

いずれかの例を実行するには、コードを `main.py`ファイルにコピーし、` uvicorn`を次のように起動します:

<div class="termy">

```console
$ uvicorn main:app --reload

<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
<span style="color: green;">INFO</span>: Started reloader process [28720]
<span style="color: green;">INFO</span>: Started server process [28722]
<span style="color: green;">INFO</span>: Waiting for application startup.
<span style="color: green;">INFO</span>: Application startup complete.
```

</div>

コードを記述またはコピーし、編集してローカルで実行することを**強くお勧めします**。

また、エディターで使用することで、書く必要のあるコードの少なさ、すべての型チェック、自動補完などのFastAPIの利点を実感できます。

---

## FastAPIをインストールする

最初のステップは、FastAPIのインストールです。

チュートリアルのために、すべてのオプションの依存関係と機能をインストールしたいとき:

<div class="termy">

```console
$ pip install fastapi[all]

---> 100%
```

</div>

...これには、コードを実行するサーバーとして使用できる `uvicorn`も含まれます。

!!! note "備考"
パーツ毎にインストールすることも可能です。

以下は、アプリケーションを本番環境にデプロイする際に行うであろうものです:

```
pip install fastapi
```

また、サーバーとして動作するように`uvicorn` をインストールします:
Also install `uvicorn` to work as the server:

```
pip install uvicorn
```

そして、使用したい依存関係をそれぞれ同様にインストールします。

## 高度なユーザーガイド

**高度なユーザーガイド**もあり、**チュートリアル - ユーザーガイド**の後で読むことができます。

**高度なユーザーガイド**は**チュートリアル - ユーザーガイド**に基づいており、同じ概念を使用し、いくつかの追加機能を紹介しています。

ただし、最初に**チュートリアル - ユーザーガイド**(現在読んでいる内容)をお読みください。

**チュートリアル-ユーザーガイド**だけで完全なアプリケーションを構築できるように設計されています。加えて、**高度なユーザーガイド**の中からニーズに応じたアイデアを使用して、様々な拡張が可能です。
69 changes: 69 additions & 0 deletions docs/ja/mkdocs.yml
@@ -0,0 +1,69 @@
site_name: FastAPI
site_description: FastAPI framework, high performance, easy to learn, fast to code, ready for production
site_url: https://fastapi.tiangolo.com/ja/
theme:
name: material
palette:
primary: teal
accent: amber
icon:
repo: fontawesome/brands/github-alt
logo: https://fastapi.tiangolo.com/img/icon-white.svg
favicon: https://fastapi.tiangolo.com/img/favicon.png
language: ja
repo_name: tiangolo/fastapi
repo_url: https://github.com/tiangolo/fastapi
edit_uri: ''
google_analytics:
- UA-133183413-1
- auto
nav:
- FastAPI: index.md
- Languages:
- en: /
- es: /es/
- ja: /ja/
- pt: /pt/
- zh: /zh/
- チュートリアル - ユーザーガイド:
- tutorial/index.md
- tutorial/body-multiple-params.md
markdown_extensions:
- toc:
permalink: true
- markdown.extensions.codehilite:
guess_lang: false
- markdown_include.include:
base_path: docs
- admonition
- codehilite
- extra
- pymdownx.superfences:
custom_fences:
- name: mermaid
class: mermaid
format: !!python/name:pymdownx.superfences.fence_div_format ''
- pymdownx.tabbed
extra:
social:
- icon: fontawesome/brands/github-alt
link: https://github.com/tiangolo/typer
- icon: fontawesome/brands/twitter
link: https://twitter.com/tiangolo
- icon: fontawesome/brands/linkedin
link: https://www.linkedin.com/in/tiangolo
- icon: fontawesome/brands/dev
link: https://dev.to/tiangolo
- icon: fontawesome/brands/medium
link: https://medium.com/@tiangolo
- icon: fontawesome/solid/globe
link: https://tiangolo.com
extra_css:
- https://fastapi.tiangolo.com/css/termynal.css
- https://fastapi.tiangolo.com/css/custom.css
extra_javascript:
- https://unpkg.com/mermaid@8.4.6/dist/mermaid.min.js
- https://fastapi.tiangolo.com/js/termynal.js
- https://fastapi.tiangolo.com/js/custom.js
- https://fastapi.tiangolo.com/js/chat.js
- https://sidecar.gitter.im/dist/sidecar.v1.js
1 change: 1 addition & 0 deletions docs/pt/mkdocs.yml
Expand Up @@ -22,6 +22,7 @@ nav:
- Languages:
- en: /
- es: /es/
- ja: /ja/
- it: /it/
- pt: /pt/
- ru: /ru/
Expand Down
1 change: 1 addition & 0 deletions docs/zh/mkdocs.yml
Expand Up @@ -22,6 +22,7 @@ nav:
- Languages:
- en: /
- es: /es/
- ja: /ja/
- it: /it/
- pt: /pt/
- ru: /ru/
Expand Down