Skip to content

Fastifyアプリでschema定義すると[FSTWRN001] FastifyWarning: The body schema for GET: /users is missing. This may indicate the schema is not well specified.がでる #167

Description

@qaynam

環境

fastiy -> 5.6.2
nodejs -> 22
@notainc/typed-api-spec -> 0.6.0

問題

Fastifyアプリで、fastify-type-provider-zodを使ってschemaをSerializerした場合、fastifyの[FSTWRN001]というエラーが発生する
Image from Gyazo

fastify側にコード
https://github.com/fastify/fastify/blob/61ca0021db7c338626395117ee9fb9444515bfce/lib/warnings.js#L16
このエラーが発生する条件はおそらく、schemaにあるheaders, body, queryStringといったキーの値がundefinedに入っているだと思います。
https://github.com/fastify/fastify/blob/61ca0021db7c338626395117ee9fb9444515bfce/lib/validation.js#L86

解決策

export const toSchema = <Spec extends ApiSpecSchema>(
あたりに条件分岐いれてあげると、治るはずです。

再現

https://stackblitz.com/edit/stackblitz-starters-5sncvilu?file=index.js

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions