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

feat: Add schema validation for result of Sessionize API #183

Merged
merged 2 commits into from
Apr 2, 2023

Conversation

taigakiyokawa
Copy link
Member

概要

Sessionize API へのリクエスト結果を型安全に使用するために zod を使った schema 定義と useSessionize 内での validation を追加しました。

変更

  • yarn add zod
  • src/modules/sessionize/schema.ts に Sessionize API の取得結果を元に zod を使った schema オブジェクト (sessionizeViewAllSchema) の定義と型 (SessionizeViewAllSchemaType) 定義を追加
  • useSessionize 内でエラーハンドリングと schema validation を追加して、戻り値を SessionizeViewAllSchemaType | null に変更

使用例

import { useSessionize } from 'src/modules/sessionize/hooks'

export const Foo: FC = () => {
  const data = useSessionize()
  if (!data) {
    return <p>Loading...</p>
  }

  ...
}

Copy link
Contributor

@maito1201 maito1201 left a comment

Choose a reason for hiding this comment

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

これは天才、ありがとうございます

@taigakiyokawa taigakiyokawa merged commit a40ef81 into develop Apr 2, 2023
@taigakiyokawa taigakiyokawa deleted the schema-validation branch April 2, 2023 12:43
@@ -24,7 +24,8 @@
"react-i18next": "11.18.6",
"react-rewards": "^2.0.4",
"swr": "2.0.3",
"use-local-storage-state": "18.1.1"
"use-local-storage-state": "18.1.1",
"zod": "^3.21.4"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"zod": "^3.21.4"
"zod": "3.21.4"

renovate使っているので、package.json記載のバージョンは固定できると良いかなと思います

Copy link
Member Author

Choose a reason for hiding this comment

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

#184 にて対応しました 🙏

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

Successfully merging this pull request may close these issues.

2 participants