{"_id":"@benjaminlindberg/fastify-type-provider-zod","name":"@benjaminlindberg/fastify-type-provider-zod","dist-tags":{"latest":"1.1.9"},"versions":{"1.1.9":{"name":"@benjaminlindberg/fastify-type-provider-zod","version":"1.1.9","description":"Zod Type Provider for Fastify@4","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc","test":"npm run build && npm run typescript && jest","test:coverage":"jest --coverage","format":"prettier --write .","lint":"eslint .","lint:fix":"eslint --fix .","typescript":"tsd","prepublishOnly":"npm run build"},"peerDependencies":{"fastify":"^4.0.0","zod":"^3.14.2"},"repository":{"url":"git+https://github.com/turkerdev/fastify-type-provider-zod.git"},"keywords":["fastify","zod","type","provider"],"author":{"name":"turkerd"},"license":"MIT","bugs":{"url":"https://github.com/turkerdev/fastify-type-provider-zod/issues"},"homepage":"https://github.com/turkerdev/fastify-type-provider-zod","dependencies":{"zod-to-json-schema":"^3.17.1"},"devDependencies":{"@fastify/swagger":"^8.12.0","@fastify/swagger-ui":"^1.10.1","@types/jest":"^29.5.10","@types/node":"^18.18.13","@typescript-eslint/eslint-plugin":"^6.12.0","@typescript-eslint/parser":"^6.12.0","eslint":"^8.54.0","eslint-config-prettier":"^8.5.0","eslint-plugin-import":"^2.26.0","eslint-plugin-prettier":"^4.2.1","fastify":"^4.24.3","fastify-plugin":"^4.5.1","jest":"^29.7.0","oas-validator":"^5.0.8","prettier":"^2.7.1","ts-jest":"^29.1.1","tsd":"^0.29.0","typescript":"^5.3.2","zod":"^3.22.4"},"tsd":{"directory":"types"},"gitHead":"62dc659a6eeff353387b19473eec3fe2aacd622e","_id":"@benjaminlindberg/fastify-type-provider-zod@1.1.9","_nodeVersion":"20.1.0","_npmVersion":"9.6.4","dist":{"integrity":"sha512-avdO03xZkwxP03PGEk3ix6xl3c5XU3Rfq0z6MXNFNyVNCRQ14u8ic7n+TsNzcTYUzKdKInDFLwtM3nZV4f4+nQ==","shasum":"8939b5dfcb757ed2dbfbf2633c6a18cbf7ba2f9e","tarball":"https://registry.npmjs.org/@benjaminlindberg/fastify-type-provider-zod/-/fastify-type-provider-zod-1.1.9.tgz","fileCount":24,"unpackedSize":42227,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC5WS1IQBMdHAL1P3lohZqF2XQD3QenHHGUtUWXNNM6GQIhAN+8lnoAkAHhdmC3Zb1zF8PI3RdouHHh3cef9n35Cx0s"}]},"_npmUser":{"name":"benjaminlindberg","email":"lindbergbenjamin2@gmail.com"},"directories":{},"maintainers":[{"name":"benjaminlindberg","email":"lindbergbenjamin2@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fastify-type-provider-zod_1.1.9_1709755697239_0.3560350076857719"},"_hasShrinkwrap":false}},"time":{"created":"2024-03-06T20:08:17.096Z","1.1.9":"2024-03-06T20:08:17.377Z","modified":"2024-03-06T20:08:17.916Z"},"maintainers":[{"name":"benjaminlindberg","email":"lindbergbenjamin2@gmail.com"}],"description":"Zod Type Provider for Fastify@4","homepage":"https://github.com/turkerdev/fastify-type-provider-zod","keywords":["fastify","zod","type","provider"],"repository":{"url":"git+https://github.com/turkerdev/fastify-type-provider-zod.git"},"author":{"name":"turkerd"},"bugs":{"url":"https://github.com/turkerdev/fastify-type-provider-zod/issues"},"license":"MIT","readme":"# Fastify Type Provider Zod\n\n[![NPM Version](https://img.shields.io/npm/v/fastify-type-provider-zod.svg)](https://npmjs.org/package/fastify-type-provider-zod)\n[![NPM Downloads](https://img.shields.io/npm/dm/fastify-type-provider-zod.svg)](https://npmjs.org/package/fastify-type-provider-zod)\n[![Build Status](https://github.com//turkerdev/fastify-type-provider-zod/workflows/CI/badge.svg)](https://github.com//turkerdev/fastify-type-provider-zod/actions)\n\n## How to use?\n\n```js\nimport Fastify from \"fastify\";\nimport { serializerCompiler, validatorCompiler, ZodTypeProvider } from \"fastify-type-provider-zod\";\nimport z from \"zod\";\n\nconst app = Fastify()\n\n// Add schema validator and serializer\napp.setValidatorCompiler(validatorCompiler);\napp.setSerializerCompiler(serializerCompiler);\n\napp.withTypeProvider<ZodTypeProvider>().route({\n  method: \"GET\",\n  url: \"/\",\n  // Define your schema\n  schema: {\n    querystring: z.object({\n      name: z.string().min(4),\n    }),\n    response: {\n      200: z.string(),\n    },\n  },\n  handler: (req, res) => {\n    res.send(req.query.name);\n  },\n});\n\napp.listen({ port: 4949 });\n```\n\n## How to use together with @fastify/swagger\n\n```ts\nimport fastify from 'fastify';\nimport fastifySwagger from '@fastify/swagger';\nimport fastifySwaggerUI from '@fastify/swagger-ui';\nimport { z } from 'zod';\n\nimport {\n  jsonSchemaTransform,\n  createJsonSchemaTransform,\n  serializerCompiler,\n  validatorCompiler,\n  ZodTypeProvider,\n} from 'fastify-type-provider-zod';\n\nconst app = fastify();\napp.setValidatorCompiler(validatorCompiler);\napp.setSerializerCompiler(serializerCompiler);\n\napp.register(fastifySwagger, {\n  openapi: {\n    info: {\n      title: 'SampleApi',\n      description: 'Sample backend service',\n      version: '1.0.0',\n    },\n    servers: [],\n  },\n  transform: jsonSchemaTransform,\n  // You can also create transform with custom skiplist of endpoints that should not be included in the specification:\n  //\n  // transform: createJsonSchemaTransform({\n  //   skipList: [ '/documentation/static/*' ]\n  // })\n});\n\napp.register(fastifySwaggerUI, {\n  routePrefix: '/documentation',\n});\n\nconst LOGIN_SCHEMA = z.object({\n  username: z.string().max(32).describe('Some description for username'),\n  password: z.string().max(32),\n});\n\napp.after(() => {\n  app.withTypeProvider<ZodTypeProvider>().route({\n    method: 'POST',\n    url: '/login',\n    schema: { body: LOGIN_SCHEMA },\n    handler: (req, res) => {\n      res.send('ok');\n    },\n  });\n});\n\nasync function run() {\n  await app.ready();\n\n  await app.listen({\n    port: 4949,\n  });\n\n  console.log(`Documentation running at http://localhost:4949/documentation`);\n}\n\nrun();\n```\n\n## How to create a plugin?\n\n```ts\nimport { z } from 'zod';\nimport { FastifyPluginAsyncZod } from 'fastify-type-provider-zod';\n\nconst plugin: FastifyPluginAsyncZod = async function (fastify, _opts) {\n  fastify.route({\n    method: 'GET',\n    url: '/',\n    // Define your schema\n    schema: {\n      querystring: z.object({\n        name: z.string().min(4),\n      }),\n      response: {\n        200: z.string(),\n      },\n    },\n    handler: (req, res) => {\n      res.send(req.query.name);\n    },\n  });\n};\n```\n","readmeFilename":"README.md"}