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

Schema Validation Layer | Blog by pumpkiinbell #8

Open
utterances-bot opened this issue Jul 25, 2022 · 7 comments
Open

Schema Validation Layer | Blog by pumpkiinbell #8

utterances-bot opened this issue Jul 25, 2022 · 7 comments

Comments

@utterances-bot
Copy link

Schema Validation Layer | Blog by pumpkiinbell

평소 API 반환값을 추론하기 위해 어떤 방식을 사용하시나요? Schema Validation Layer 를 추가하면 메인 로직을 깔끔하게 관리할 수 있습니다.

https://www.pumpkiinbell.com/blog/remote/scheme-validation-layer

Copy link

https://www.pumpkiinbell.com/blog/remote/scheme-validation-layer#parse

에서 궁금한것이 있는데 아래 코드에서 어떻게 id 키를 필터링 할 수 있는건가요?

type Something = z.infer<typeof Something>;
const Something = z.object({
  id: z.string();
  name: z.string();
  content: z.string();
})

function fetchSomething(payload: Something) {
  const newPayload = Something.parse(payload);

  // do something...
}

Copy link

정리 너무 잘해주셔서 이해가 쏙쏙 되네요 ㅎㅎ

Copy link
Owner

pumpkiinbell commented Jul 25, 2022

@gomjellie
앗...!! 오타가 있었군요 😭 id: z.string() 이 제외되어야 합니다.
아래와 같이 수정하였습니다. 코멘트 감사합니다~

type Something = z.infer<typeof Something>;
const Something = z.object({
- id: z.string();
  name: z.string();
  content: z.string();
})

function fetchSomething(payload: Something) {
  const newPayload = Something.parse(payload);

  // do something...
}

Copy link

peanudge commented Oct 7, 2022

Backend 개발할 때 Fastify의 AJV로 payload body 검증하는 사례를 봤을 때 굉장히 편한 도구가 많이 나왔다고 생각했는데 이 글을 보고나니 Frontend 사이드도 굉장히 진보되었다는 것을 새삼느끼네요!! 👏 좋은 글 잘 읽었습니다. :))))

Copy link

잘읽었습니다 감사합니다~

Copy link

좋은글 감사합니다~

Copy link

너무너무 좋은 글 입니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants