{"id":17973850,"url":"https://github.com/morintd/ts-generate-schema","last_synced_at":"2025-03-25T14:31:44.303Z","repository":{"id":37049392,"uuid":"312812410","full_name":"morintd/ts-generate-schema","owner":"morintd","description":"Generate json-schema files from your typescript definitions","archived":false,"fork":false,"pushed_at":"2022-11-12T14:41:50.000Z","size":1018,"stargazers_count":8,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-26T09:36:59.484Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/morintd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-14T12:27:13.000Z","updated_at":"2023-03-08T20:08:57.000Z","dependencies_parsed_at":"2023-01-20T11:10:31.069Z","dependency_job_id":null,"html_url":"https://github.com/morintd/ts-generate-schema","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morintd%2Fts-generate-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morintd%2Fts-generate-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morintd%2Fts-generate-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morintd%2Fts-generate-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/morintd","download_url":"https://codeload.github.com/morintd/ts-generate-schema/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222083668,"owners_count":16928134,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-29T17:03:51.869Z","updated_at":"2024-10-29T17:03:52.528Z","avatar_url":"https://github.com/morintd.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ts-generate-schema\n\nGenerate json-schema files from your typescript definitions\n\n![npm](https://img.shields.io/npm/v/ts-generate-schema)\n[![Build](https://circleci.com/gh/morintd/ts-generate-schema.svg?style=shield)](https://app.circleci.com/pipelines/github/morintd/ts-generate-schema)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/5577363312610be54f84/test_coverage)](https://codeclimate.com/github/morintd/ts-generate-schema/test_coverage)\n[![Maintainability](https://api.codeclimate.com/v1/badges/5577363312610be54f84/maintainability)](https://codeclimate.com/github/morintd/ts-generate-schema/maintainability)\n![npm](https://img.shields.io/npm/dm/ts-generate-schema)\n\n## Features\n\n- Generate json-schema files from one single command :\n\n  - Run `npx ts-generate-schema src/**/*-response.dto.ts` in your root folder.\n  - After writing the following TypeScript definition :\n    \u003e src/types/login-user-response.dto.ts\n\n  ```typescript\n  export type LoginUserResponseDTO = {\n    user: {\n      id: string;\n      email: string;\n      username: string;\n      firstname: string;\n    };\n    token: {\n      expiresIn: number;\n      accessToken: string;\n    };\n  };\n  ```\n\n  - Get this file in return :\n\n  \u003e src/types/schema/login-user-response-dto.jsc.ts\n\n  ```typescript\n  export default {\n    type: 'object',\n    properties: {\n      user: {\n        type: 'object',\n        properties: {\n          id: {\n            type: 'string',\n          },\n          email: {\n            type: 'string',\n          },\n          username: {\n            type: 'string',\n          },\n          firstname: {\n            type: 'string',\n          },\n        },\n        required: ['email', 'firstname', 'id', 'username'],\n      },\n      token: {\n        type: 'object',\n        properties: {\n          expiresIn: {\n            type: 'number',\n          },\n          accessToken: {\n            type: 'string',\n          },\n        },\n        required: ['accessToken', 'expiresIn'],\n      },\n    },\n    required: ['token', 'user'],\n    $schema: 'http://json-schema.org/draft-07/schema#',\n  };\n  ```\n\n## Usage\n\n- Install with `npm i -D ts-generate-schema` or `yarn add -D ts-generate-schema`\n- Add the following scripts in your **package.json**.\n\n```json\n\"schema\": \"ts-generate-schema \u003cpattern\u003e\"\n```\n\n- You can also use it globally:\n  - With `npm i -g ts-generate-schema` and simply running `ts-generate-schema \u003cpattern\u003e` anywhere\n  - with `npx`, `npx ts-generate-schema \u003cpattern\u003e`\n\n### Command Line\n\n`\u003cpattern\u003e` is a [glob](https://github.com/isaacs/node-glob#readme) pattern to find files to handle.\n\nI would recommand giving those files a special extension (such as _-response.dto.ts_ for request) and use `ts-generate-schema src/**/*-response.dto.ts`\n\n```\nUsage: ts-generate-schema \u003cpattern\u003e\nOptions:\n  --help     Show help                                                 [boolean]\n  --version  Show version number                                       [boolean]\n  --to       Extension of generated json-schema     [string] [default: \"jsc.ts\"]\n  --export   How to export generated json-schema from file\n                                            [string] [default: \"export default\"]\n  --out       Path to the generated schema directory     [string] [default: \"schema\"]\n```\n\n## Motivation\n\nI'm passionate about software architecture, quality and scaling.\n\nI've recently been working on a web and mobile project where I made tons of API calls. I came to the conlusion that my way of handling API calls was ... not good enough.\n\nAnd, at some point in every project I worked on, we had a server getting an update without the front-end team being perfectly notified about it.\n\nMy aim was to be able to know when a request we received was different from our primary API. As I'm a TypeScript lover and user, I quickly found some way to use TS definitions as json-schemas with a validator such as AJV.\n\nNevertheless, libraries providing us with TypeScript to JSON Schema functionalities were too low level to be used as they are.\n\nI had axios and interceptors to setup my strategies, AJV to handle validation and now this library to quickly generate my JSON-schemas from my TypeScript definitions.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorintd%2Fts-generate-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorintd%2Fts-generate-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorintd%2Fts-generate-schema/lists"}