{"_id":"@bret/type-provider-json-schema-to-ts","_rev":"3-7f85a85ca62caaf37b1cbeca1558b1da","name":"@bret/type-provider-json-schema-to-ts","dist-tags":{"latest":"5.0.1"},"versions":{"4.0.1":{"name":"@bret/type-provider-json-schema-to-ts","version":"4.0.1","keywords":["fastify","json-schema-to-ts"],"author":{"name":"RafaelGSS"},"license":"MIT","_id":"@bret/type-provider-json-schema-to-ts@4.0.1","maintainers":[{"name":"bret","email":"bcomnes@gmail.com"}],"homepage":"https://github.com/fastify/fastify-type-provider-json-schema-to-ts#readme","bugs":{"url":"https://github.com/fastify/fastify-type-provider-json-schema-to-ts/issues"},"tsd":{"directory":"types"},"dist":{"shasum":"a7ee7fa5dc973b958a70959f2d06eecbef743b33","tarball":"https://registry.npmjs.org/@bret/type-provider-json-schema-to-ts/-/type-provider-json-schema-to-ts-4.0.1.tgz","fileCount":14,"integrity":"sha512-+WpmHLP8tTL7iEZ5Zzmfj+bYuPR/vtIq12ck6xnQufcDuNzU/mOn4dShUfamr0squdIZJHrOmyFjDkAWf1xc2g==","signatures":[{"sig":"MEUCIGoKOsAhTQb5XtCk+8JXoF5gxEfBuQV2QLenzbNtOQK5AiEA80yNydhteyPrrEZfI4IA/2kvNAM5WpxwHZbFZ8Ejuqc=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":16066},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"c04007ce22e4f1304cbc709a0b11e12989c54f26","scripts":{"lint":"eslint \"**/*.ts\"","test":"npm run build && npm run test:typescript","build":"rimraf dist && mkdir dist && tsc --outDir dist","lint:fix":"eslint \"**/*.ts\" --fix","prepublishOnly":"npm run build","test:typescript":"tsc --strict --noEmit && tsd"},"_npmUser":{"name":"bret","email":"bcomnes@gmail.com"},"repository":{"url":"git+https://github.com/fastify/fastify-type-provider-json-schema-to-ts.git","type":"git"},"_npmVersion":"10.8.3","description":"A Type Provider for json-schema-to-ts over Fastify","directories":{},"_nodeVersion":"22.9.0","dependencies":{"json-schema-to-ts":"^3.1.0"},"_hasShrinkwrap":false,"devDependencies":{"tsd":"^0.31.0","eslint":"^8.57.0","rimraf":"^5.0.7","fastify":"^5.0.0","typescript":"^5.4.5","@types/node":"^20.14.2","eslint-plugin-n":"^16.6.2","fastify-tsconfig":"^2.0.0","@fastify/pre-commit":"^2.1.0","eslint-plugin-import":"^2.29.1","eslint-plugin-promise":"^6.2.0","eslint-config-standard":"^17.1.0","@typescript-eslint/parser":"^7.13.0","@typescript-eslint/eslint-plugin":"^7.13.0"},"_npmOperationalInternal":{"tmp":"tmp/type-provider-json-schema-to-ts_4.0.1_1728159186849_0.7835881966066851","host":"s3://npm-registry-packages"}},"4.0.2":{"name":"@bret/type-provider-json-schema-to-ts","version":"4.0.2","keywords":["fastify","json-schema-to-ts"],"author":{"name":"RafaelGSS"},"license":"MIT","_id":"@bret/type-provider-json-schema-to-ts@4.0.2","maintainers":[{"name":"bret","email":"bcomnes@gmail.com"}],"homepage":"https://github.com/fastify/fastify-type-provider-json-schema-to-ts#readme","bugs":{"url":"https://github.com/fastify/fastify-type-provider-json-schema-to-ts/issues"},"tsd":{"directory":"types"},"dist":{"shasum":"2456b46a74a9389f43bfce40a0135f213ef65f83","tarball":"https://registry.npmjs.org/@bret/type-provider-json-schema-to-ts/-/type-provider-json-schema-to-ts-4.0.2.tgz","fileCount":14,"integrity":"sha512-jPinrSuiEfJ55EE4k9JeZBhzIE0uMMXdHLUZHG1hxednnVpcN6PcN1NVkTnriaOCDk+oJFr4JIDSEZsJHpiH2w==","signatures":[{"sig":"MEQCIDXGC05+I1gU6ChKetFFf2Wtm0tUvhl93h7yif7yZkslAiAyN/gJYGLk0bGpsRUUt+p/vn+kqPFSEJbX7ajzakrJgw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":16108},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"5d3aacef2d3bd0cf181f108d6eaec326de223366","scripts":{"lint":"eslint \"**/*.ts\"","test":"npm run build && npm run test:typescript","build":"rimraf dist && mkdir dist && tsc --outDir dist","lint:fix":"eslint \"**/*.ts\" --fix","prepublishOnly":"npm run build","test:typescript":"tsc --strict --noEmit && tsd"},"_npmUser":{"name":"bret","email":"bcomnes@gmail.com"},"repository":{"url":"git+https://github.com/fastify/fastify-type-provider-json-schema-to-ts.git","type":"git"},"_npmVersion":"10.8.3","description":"A Type Provider for json-schema-to-ts over Fastify","directories":{},"_nodeVersion":"22.9.0","dependencies":{"json-schema-to-ts":"^3.1.0"},"_hasShrinkwrap":false,"devDependencies":{"tsd":"^0.31.0","eslint":"^8.57.0","rimraf":"^5.0.7","fastify":"^5.0.0","typescript":"^5.4.5","@types/node":"^20.14.2","eslint-plugin-n":"^16.6.2","fastify-tsconfig":"^2.0.0","@fastify/pre-commit":"^2.1.0","eslint-plugin-import":"^2.29.1","eslint-plugin-promise":"^6.2.0","eslint-config-standard":"^17.1.0","@typescript-eslint/parser":"^7.13.0","@typescript-eslint/eslint-plugin":"^7.13.0"},"_npmOperationalInternal":{"tmp":"tmp/type-provider-json-schema-to-ts_4.0.2_1728448289806_0.9801995605450073","host":"s3://npm-registry-packages"}},"5.0.0":{"name":"@bret/type-provider-json-schema-to-ts","version":"5.0.0","keywords":["fastify","json-schema-to-ts"],"author":{"name":"RafaelGSS"},"license":"MIT","_id":"@bret/type-provider-json-schema-to-ts@5.0.0","maintainers":[{"name":"bret","email":"bcomnes@gmail.com"}],"homepage":"https://github.com/fastify/fastify-type-provider-json-schema-to-ts#readme","bugs":{"url":"https://github.com/fastify/fastify-type-provider-json-schema-to-ts/issues"},"tsd":{"directory":"types"},"dist":{"shasum":"aad9b94384337a11ca3f494e083840b5d15a6549","tarball":"https://registry.npmjs.org/@bret/type-provider-json-schema-to-ts/-/type-provider-json-schema-to-ts-5.0.0.tgz","fileCount":14,"integrity":"sha512-SvvXMpNGY7AKNoGC3bszAFNUc6WBYq5xh5fatV5/14VFYEBWgtCHr1vHP1Bgp7NqPJWQZdlj4WDx3J2K1h6awQ==","signatures":[{"sig":"MEYCIQCbuzy87v56hxVH/OSv7lerZZDPi+/QTC8SAXKLBoDRJQIhAP2rtY5BB1rqtyGzfRPYG5dkF5316ndUh4aRgF78f6CF","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":26946},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"c0a79babcd17526f49bea6963e65df79a0b35fe9","scripts":{"lint":"eslint \"**/*.ts\"","test":"npm run build && npm run test:typescript","build":"rimraf dist && mkdir dist && tsc --outDir dist","lint:fix":"eslint \"**/*.ts\" --fix","prepublishOnly":"npm run build","test:typescript":"tsc --strict --noEmit && tsd"},"_npmUser":{"name":"bret","email":"bcomnes@gmail.com"},"repository":{"url":"git+https://github.com/fastify/fastify-type-provider-json-schema-to-ts.git","type":"git"},"_npmVersion":"10.9.0","description":"A Type Provider for json-schema-to-ts over Fastify","directories":{},"_nodeVersion":"22.12.0","dependencies":{"json-schema-to-ts":"^3.1.0"},"_hasShrinkwrap":false,"devDependencies":{"tsd":"^0.31.0","eslint":"^8.57.0","rimraf":"^5.0.7","fastify":"^5.0.0","typescript":"~5.4.5","@types/node":"^20.14.2","eslint-plugin-n":"^16.6.2","fastify-tsconfig":"^2.0.0","@fastify/pre-commit":"^2.1.0","eslint-plugin-import":"^2.29.1","eslint-plugin-promise":"^6.2.0","eslint-config-standard":"^17.1.0","@typescript-eslint/parser":"^7.13.0","@typescript-eslint/eslint-plugin":"^7.13.0"},"_npmOperationalInternal":{"tmp":"tmp/type-provider-json-schema-to-ts_5.0.0_1734565447923_0.10093341370079312","host":"s3://npm-registry-packages-npm-production"}},"5.0.1":{"name":"@bret/type-provider-json-schema-to-ts","version":"5.0.1","description":"A Type Provider for json-schema-to-ts over Fastify","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"rimraf dist && mkdir dist && tsc --outDir dist","test":"npm run build && npm run test:typescript","test:typescript":"tsc --strict --noEmit && tsd","lint":"eslint","lint:fix":"eslint --fix","prepublishOnly":"npm run build"},"repository":{"type":"git","url":"git+https://github.com/fastify/fastify-type-provider-json-schema-to-ts.git"},"keywords":["fastify","json-schema-to-ts"],"author":{"name":"RafaelGSS"},"license":"MIT","bugs":{"url":"https://github.com/fastify/fastify-type-provider-json-schema-to-ts/issues"},"homepage":"https://github.com/fastify/fastify-type-provider-json-schema-to-ts#readme","tsd":{"directory":"types"},"dependencies":{"json-schema-to-ts":"^3.1.0"},"devDependencies":{"@fastify/pre-commit":"^2.1.0","@types/node":"^22.10.2","eslint":"^9.17.0","fastify":"^5.0.0","fastify-tsconfig":"^2.0.0","neostandard":"^0.12.0","rimraf":"^6.0.1","tsd":"^0.31.0","typescript":"~5.7.2"},"_id":"@bret/type-provider-json-schema-to-ts@5.0.1","gitHead":"25e278b59f1fd43201b1ca89685779381a74fb2d","_nodeVersion":"22.12.0","_npmVersion":"10.9.0","dist":{"integrity":"sha512-aDN1HqZfM58AroYdJA6ZfZ1z8D6aq1YnOQ2rcnsHKVm5rW8H9uzHWytocj1GJa2/Ycts4hZbiV7e4QHSBhOVlg==","shasum":"a2df370ad430ea4132f991cf5d36060fbefb48b2","tarball":"https://registry.npmjs.org/@bret/type-provider-json-schema-to-ts/-/type-provider-json-schema-to-ts-5.0.1.tgz","fileCount":14,"unpackedSize":27719,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCBF2JSattqUAVEz2+wT0AfAX/pIft/EiVrfL5KMpgBLAIgevUc3/DhagQFSAZ9tu7otNop4q029EEeYpZSmRQ8e4E="}]},"_npmUser":{"name":"bret","email":"bcomnes@gmail.com"},"directories":{},"maintainers":[{"name":"bret","email":"bcomnes@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/type-provider-json-schema-to-ts_5.0.1_1734637722044_0.06746446808094309"},"_hasShrinkwrap":false}},"time":{"created":"2024-10-05T20:13:06.747Z","modified":"2024-12-19T19:48:42.425Z","4.0.1":"2024-10-05T20:13:07.066Z","4.0.2":"2024-10-09T04:31:29.982Z","5.0.0":"2024-12-18T23:44:08.078Z","5.0.1":"2024-12-19T19:48:42.230Z"},"bugs":{"url":"https://github.com/fastify/fastify-type-provider-json-schema-to-ts/issues"},"author":{"name":"RafaelGSS"},"license":"MIT","homepage":"https://github.com/fastify/fastify-type-provider-json-schema-to-ts#readme","keywords":["fastify","json-schema-to-ts"],"repository":{"type":"git","url":"git+https://github.com/fastify/fastify-type-provider-json-schema-to-ts.git"},"description":"A Type Provider for json-schema-to-ts over Fastify","maintainers":[{"name":"bret","email":"bcomnes@gmail.com"}],"readme":"# @fastify/type-provider-json-schema-to-ts\n\n[![CI](https://github.com/fastify/fastify-type-provider-json-schema-to-ts/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/fastify-type-provider-json-schema-to-ts/actions/workflows/ci.yml)\n[![NPM version](https://img.shields.io/npm/v/@fastify/type-provider-json-schema-to-ts.svg?style=flat)](https://www.npmjs.com/package/@fastify/type-provider-json-schema-to-ts)\n[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)\n\nA Type Provider for [json-schema-to-ts](https://github.com/ThomasAribart/json-schema-to-ts)\n\n## Install\n\n```bash\nnpm i @fastify/type-provider-json-schema-to-ts\n```\n\n## TypeScript requirements\n\nIt is required to use `TypeScript@4.3` or above with\n[`strict`](https://www.typescriptlang.org/tsconfig#strict)\nmode enabled and\n[`noStrictGenericChecks`](https://www.typescriptlang.org/tsconfig#noStrictGenericChecks)\ndisabled. You may take the following configuration (`tsconfig.json`) as an example:\n\n```json\n{\n  \"compilerOptions\": {\n    \"strict\": true,\n    \"noStrictGenericChecks\": false\n  }\n}\n```\n\n## Plugin definition\n\n> **Note**\n> When using plugin types, `withTypeProvider` is not required to register the plugin.\n\n```ts\nconst plugin: FastifyPluginAsyncJsonSchemaToTs = async function (\n  fastify,\n  _opts\n) {\n  fastify.get(\n    \"/\",\n    {\n      schema: {\n        body: {\n          type: \"object\",\n          properties: {\n            x: { type: \"string\" },\n            y: { type: \"number\" },\n            z: { type: \"boolean\" },\n          },\n          required: [\"x\", \"y\", \"z\"],\n        } as const,\n      },\n    },\n    (req) => {\n      // The `x`, `y`, and `z` types are automatically inferred\n      const { x, y, z } = req.body;\n    }\n  );\n};\n```\n\n## Setting FromSchema for the validator and serializer\n\nYou can set the `FromSchema` settings for things like [`references`](https://github.com/ThomasAribart/json-schema-to-ts#references) and [`deserialization`](https://github.com/ThomasAribart/json-schema-to-ts#deserialization) for the validation and serialization schema by setting `ValidatorSchemaOptions` and `SerializerSchemaOptions` type parameters.\nYou can use the `deserialize` option in `SerializerSchemaOptions` to allow Date objects in place of date-time strings or other special serialization rules handled by [fast-json-stringify](https://github.com/fastify/fast-json-stringify?tab=readme-ov-file#specific-use-cases).\n\n```ts\nconst userSchema = {\n  type: \"object\",\n  additionalProperties: false,\n  properties: {\n    givenName: { type: \"string\" },\n    familyName: { type: \"string\" },\n  },\n  required: [\"givenName\", \"familyName\"],\n} as const satisfies JSONSchema;\n\nconst sharedSchema = {\n  $id: \"shared-schema\",\n  definitions: {\n    user: userSchema,\n  },\n} as const satisfies JSONSchema;\n\nconst userProfileSchema = {\n  $id: \"userProfile\",\n  type: \"object\",\n  additionalProperties: false,\n  properties: {\n    user: {\n      $ref: \"shared-schema#/definitions/user\",\n    },\n    joinedAt: { type: \"string\", format: \"date-time\" },\n  },\n  required: [\"user\", \"joinedAt\"],\n} as const satisfies JSONSchema\n\n\ntype UserProfile = FromSchema<typeof userProfileSchema, {\n  references: [typeof sharedSchema]\n  deserialize: [{ pattern: { type: \"string\"; format: \"date-time\" }; output: Date }]\n}>;\n\n// Use JsonSchemaToTsProvider with shared schema references\nconst fastify = Fastify().withTypeProvider<\n  JsonSchemaToTsProvider<{\n    ValidatorSchemaOptions: {\n      references: [typeof sharedSchema]\n    }\n  }>\n>();\n\nconst fastify = Fastify().withTypeProvider<\n  JsonSchemaToTsProvider<{\n    ValidatorSchemaOptions: { references: [typeof sharedSchema] }\n    SerializerSchemaOptions: {\n      references: [typeof userProfileSchema]\n      deserialize: [{ pattern: { type: \"string\"; format: \"date-time\" }; output: Date }]\n    }\n  }>\n>()\n\nfastify.get(\n  \"/profile\",\n  {\n    schema: {\n      body: {\n        type: \"object\",\n        properties: {\n          user: {\n            $ref: \"shared-schema#/definitions/user\",\n          },\n        },\n        required: ['user'],\n      },\n      response: {\n        200: { $ref: \"userProfile#\" },\n      },\n    } as const,\n  },\n  (req, reply) => {\n    // `givenName` and `familyName` are correctly typed as strings\n    const { givenName, familyName } = req.body.user;\n\n    // Construct a compatible response type\n    const profile: UserProfile = {\n      user: { givenName: \"John\", familyName: \"Doe\" },\n      joinedAt: new Date(), // Returning a Date object\n    };\n\n    // A type error is surfaced if profile doesn't match the serialization schema\n    reply.send(profile)\n  }\n)\n```\n\n## Using References in a Plugin Definition\n\nWhen defining a plugin, shared schema references and deserialization options can also be used with `FastifyPluginAsyncJsonSchemaToTs` and `FastifyPluginCallbackJsonSchemaToTs`.\n\n### Example\n\n```ts\nconst schemaPerson = {\n  $id: \"schema:person\",\n  type: \"object\",\n  additionalProperties: false,\n  properties: {\n    givenName: { type: \"string\" },\n    familyName: { type: \"string\" },\n    joinedAt: { type: \"string\", format: \"date-time\" },\n  },\n  required: [\"givenName\", \"familyName\"],\n} as const satisfies JSONSchema;\n\nconst plugin: FastifyPluginAsyncJsonSchemaToTs<{\n  ValidatorSchemaOptions: { references: [typeof schemaPerson] }\n  SerializerSchemaOptions: {\n    references: [typeof schemaPerson]\n    deserialize: [{ pattern: { type: \"string\"; format: \"date-time\" }; output: Date }]\n  };\n}> = async function (fastify, _opts) {\n  fastify.addSchema(schemaPerson)\n\n  fastify.get(\n    \"/profile\",\n    {\n      schema: {\n        body: {\n          type: \"object\",\n          properties: {\n            user: {\n              $ref: \"schema:person\",\n            },\n          },\n          required: ['user'],\n        },\n        response: {\n          200: { $ref: \"schema:person\" },\n        },\n      }, // as const satisfies JSONSchema is not required thanks to FastifyPluginAsyncJsonSchemaToTs\n    },\n    (req, reply) => {\n      // `givenName`, `familyName`, and `joinedAt` are correctly typed as strings and validated for format.\n      const { givenName, familyName, joinedAt } = req.body.user;\n\n      // Send a serialized response\n      reply.send({\n        givenName: \"John\",\n        familyName: \"Doe\",\n        // Date objects form DB queries can be returned directly and transformed to string by fast-json-stringify\n        joinedAt: new Date(),\n      })\n    }\n  )\n}\n\nconst callbackPlugin: FastifyPluginCallbackJsonSchemaToTs<{\n  ValidatorSchemaOptions: { references: [typeof schemaPerson] }\n  SerializerSchemaOptions: {\n    references: [typeof schemaPerson]\n    deserialize: [{ pattern: { type: \"string\"; format: \"date-time\" }; output: Date }]\n  };\n}> = (fastify, options, done) => {\n  // Type check for custom options\n  expectType<string>(options.optionA)\n\n  // Schema is already added above\n  // fastify.addSchema(schemaPerson);\n\n  fastify.get(\n    \"/callback-profile\",\n    {\n      schema: {\n        body: {\n          type: \"object\",\n          properties: {\n            user: { $ref: \"schema:person\" },\n          },\n          required: [\"user\"],\n        },\n        response: {\n          200: { $ref: \"schema:person\" },\n        },\n      },\n    },\n    (req, reply) => {\n      const { givenName, familyName, joinedAt } = req.body.user\n\n      reply.send({\n        givenName,\n        familyName,\n        joinedAt: new Date(),\n      });\n    }\n  );\n\n  done()\n};\n```\n","readmeFilename":"README.md"}