Skip to content

Commit

Permalink
Add Korean translation for /docs/ko/docs/tutorial/body-fields.md
Browse files Browse the repository at this point in the history
  • Loading branch information
KaniKim committed Feb 8, 2024
1 parent ab22b79 commit 88ed1c2
Showing 1 changed file with 116 additions and 0 deletions.
116 changes: 116 additions & 0 deletions docs/ko/docs/tutorial/body-fields.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# 본문 - 필드

같은 방식으로 추가적인 검증이나 메타데이터를 `Query`, `Path``Body`*경로 동작 함수* 매개변수 안에 선언할 수 있으며, Pydantic의 `Field`를 사용하여 Pydantic 모델 안에 검증과 메타데이터를 선언할 수 있습니다.

## `Field` 임포트

먼저 이를 임포트해야 합니다:

=== "Python 3.10+"

```Python hl_lines="4"
{!> ../../../docs_src/body_fields/tutorial001_an_py310.py!}
```

=== "Python 3.9+"

```Python hl_lines="4"
{!> ../../../docs_src/body_fields/tutorial001_an_py39.py!}
```

=== "Python 3.8+"

```Python hl_lines="4"
{!> ../../../docs_src/body_fields/tutorial001_an.py!}
```

=== "Python 3.10+ Annotated가 없는 경우"

!!! 팁
가능하다면 `Annotated`가 달린 버전을 권장합니다.

```Python hl_lines="2"
{!> ../../../docs_src/body_fields/tutorial001_py310.py!}
```

=== "Python 3.8+ Annotated가 없는 경우"

!!! tip "팁"
가능하다면 `Annotated`가 달린 버전을 권장합니다.

```Python hl_lines="4"
{!> ../../../docs_src/body_fields/tutorial001.py!}
```

!!! warning "경고"
`Field`는 나머지 모든 것처럼 (`Query`, `Path`, `Body` 등) `fastapi`에서가 아닌 `pydantic`에서 바로 임포트 되는 점에 주의하세요.

## 모델 어트리뷰트 선언

그 다음 모델 어트리뷰와 함께 `Field`를 사용할 수 있습니다:

=== "Python 3.10+"

```Python hl_lines="11-14"
{!> ../../../docs_src/body_fields/tutorial001_an_py310.py!}
```

=== "Python 3.9+"

```Python hl_lines="11-14"
{!> ../../../docs_src/body_fields/tutorial001_an_py39.py!}
```

=== "Python 3.8+"

```Python hl_lines="12-15"
{!> ../../../docs_src/body_fields/tutorial001_an.py!}
```

=== "Python 3.10+ Annotated가 없는 경우"

!!! tip "팁"
가능하다면 `Annotated`가 달린 버전을 권장합니다.

```Python hl_lines="9-12"
{!> ../../../docs_src/body_fields/tutorial001_py310.py!}
```

=== "Python 3.8+ Annotated가 없는 경우"

!!! tip "팁"
가능하다면 `Annotated`가 달린 버전을 권장합니다.

```Python hl_lines="11-14"
{!> ../../../docs_src/body_fields/tutorial001.py!}
```

`Field``Query`, `Path``Body`처럼 같은 방식으로 동작하며, 모두 같은 매개변수 등을 가집니다.

!!! note "기술적 세부사항"
실제로 `Query`, `Path`등, 여러분이 앞으로 볼 다른 것들은 공통 클래스인 `Param` 클래스의 서브클래스 객체를 만드는데, 그 자체로 Pydantic의 `FieldInfo` 클래스의 서브클래스입니다.

그리고 Pydantic의 `Field`는 `FieldInfo`의 인스턴스 또한 반환합니다.

`Body` 또한 `FieldInfo`의 서브클래스 객체를 직접 반환합니다. 그리고 `Body` 클래스의 서브클래스인 것들도 여러분이 나중에 보게될 것입니다.

`Query`, `Path`와 그 외 것들을 `fastapi`에서 임포트할 때, 이는 실제로 특별한 클래스를 반환하는 함수인 것을 기억해 주세요.

!!! tip "팁"
주목할 점은 어떻게 타입 그고 기본 값과 `Field`로 이루어진 각기 모델의 어트리뷰트가 `Path`, `Query``Body`대신 `Field`를 사용하는 *경로 작동 함수*의 매개변수와 같은 구를 가지는지 입니다.

## 별도 정보 추가

`Field`, `Query`, `Body`, 그 외 안에 별도 정보를 선언할 수 있습니다. 이는 생성된 JSON 스키마에 포함됩니다.

여러분이 예제를 선언할 때 나중에 이 공식 문서에서 별도 정보를 추가하는 방법을 배울 것입니다.

!!! warning "경고"
별도 키가 전달된 `Field` 또한 여러분의 어플리케이션의 OpenAPI 스키마에 나타날 것입니다.
이런 키가 OpenAPI 명세서, [the OpenAPI validator](https://validator.swagger.io/)같은 몇몇 OpenAPI 도구들에 포함되지 못할 수 있으며, 여러분이 생성한 스키마와 호환되지 않을 수 있습니다.

## 요약

모델 어트리뷰트를 위한 추가 검증과 메타데이터 선언하기 위해 Pydantic의 `Field` 를 사용할 수 있습니다.

또한 추가적인 JSON 스키마 메타데이터를 전달하기 위한 별도의 키워드 인자를 사용할 수 있습니다.

0 comments on commit 88ed1c2

Please sign in to comment.