{"id":13455804,"url":"https://github.com/simplyhexagonal/json-schema-to-mongoose-schema","last_synced_at":"2025-05-12T15:51:00.868Z","repository":{"id":71910330,"uuid":"428629082","full_name":"simplyhexagonal/json-schema-to-mongoose-schema","owner":"simplyhexagonal","description":"Function to convert JSON Schema (draft v4+) to Mongoose (v5, v6) Schema","archived":false,"fork":false,"pushed_at":"2022-05-03T22:27:24.000Z","size":196,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-05-06T20:28:35.749Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simplyhexagonal.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-11-16T11:31:10.000Z","updated_at":"2023-02-09T15:17:27.000Z","dependencies_parsed_at":"2023-09-24T03:50:37.413Z","dependency_job_id":null,"html_url":"https://github.com/simplyhexagonal/json-schema-to-mongoose-schema","commit_stats":{"total_commits":32,"total_committers":1,"mean_commits":32.0,"dds":0.0,"last_synced_commit":"4bbf0189c174f93b855c91eaa513c084c96eecee"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplyhexagonal%2Fjson-schema-to-mongoose-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplyhexagonal%2Fjson-schema-to-mongoose-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplyhexagonal%2Fjson-schema-to-mongoose-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplyhexagonal%2Fjson-schema-to-mongoose-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simplyhexagonal","download_url":"https://codeload.github.com/simplyhexagonal/json-schema-to-mongoose-schema/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253525070,"owners_count":21922022,"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-07-31T08:01:11.404Z","updated_at":"2025-05-12T15:51:00.826Z","avatar_url":"https://github.com/simplyhexagonal.png","language":"TypeScript","funding_links":["https://www.buymeacoffee.com/jeanlescure","https://opencollective.com/simplyhexagonal"],"categories":["TypeScript"],"sub_categories":[],"readme":"# JSON Schema to Mongoose Schema\n![Tests](https://github.com/simplyhexagonal/json-schema-to-mongoose-schema/workflows/tests/badge.svg)\n\nThis package was inspired by [convert-json-schema-to-mongoose](https://github.com/kristianmandrup/convert-json-schema-to-mongoose), but it's a bit more flexible and addresses the following:\n\n- ability to parse JSON schemas that are greater than [JSON-Schema draft-04](https://tools.ietf.org/html/draft-04)\n- parses sub-schemas into their own nested `Schema` instances to avoid required properties in them to cause false validation errors on their optional parents\n- ability to parse `\"anyOf\"` properties*\n- fully type-safe\n- thoroughly tested\n\n_*as long as all alternatives are of `\"type\": \"object\"` and properties with the same name have the same value types across alternatives_\n\nThere are examples of highly complex valid schemas within the [__fixtures__](https://github.com/simplyhexagonal/json-schema-to-mongoose-schema/tree/main/__fixtures__) directory.\n\n**IMPORTANT:** `$ref` is currently **not** supported.\n\nWe use this project along [typescript-json-schema](https://github.com/YousefED/typescript-json-schema) to have our Typescript interfaces be the single\nsource of truth that generate the JSON schema that we then translate to Mongoose schema for each\nentity within our apps.\n\n## Open source notice\n\nThis project is open to updates by its users, [I](https://github.com/jeanlescure) ensure that PRs are relevant to the community.\nIn other words, if you find a bug or want a new feature, please help us by becoming one of the\n[contributors](#contributors-) ✌️ ! See the [contributing section](#contributing)\n\n## Like this module? ❤\n\nPlease consider:\n\n- [Buying me a coffee](https://www.buymeacoffee.com/jeanlescure) ☕\n- Supporting Simply Hexagonal on [Open Collective](https://opencollective.com/simplyhexagonal) 🏆\n- Starring this repo on [Github](https://github.com/simplyhexagonal/json-schema-to-mongoose-schema) 🌟\n\n## Install\n\n_(Note: this package depends on lodash and mongoose)_\n\n```sh\npnpm i lodash mongoose @simplyhexagonal/json-schema-to-mongoose-schema\n\n# or\nyarn add lodash mongoose @simplyhexagonal/json-schema-to-mongoose-schema\n\n# or\nnpm install lodash mongoose @simplyhexagonal/json-schema-to-mongoose-schema\n```\n\n## Usage\n\n```ts\nimport jsonSchemaToMongooseSchema from '@simplyhexagonal/json-schema-to-mongoose-schema';\n\nconst userSchema = require('./schemas/User.json');\n// {\n//   \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n//   \"definitions\": {\n//     \"User\": {\n//       ...\n//     }\n//   }\n// }\n\nconst mongooseSchema = jsonSchemaToMongooseSchema(userSchema, 'User');\n\n// Then simply use your newly generated mongoose schema\nconst model = await mongoose.model(modelName, mongooseSchema);\n```\n\n## Contributing\n\nYes, thank you! This plugin is community-driven, most of its features are from different authors.\nPlease update the docs and tests and add your name to the `package.json` file.\n\n## Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://jeanlescure.cr\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/3330339?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eJean Lescure\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#maintenance-jeanlescure\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e \u003ca href=\"https://github.com/simplyhexagonal/json-schema-to-mongoose-schema/commits?author=jeanlescure\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#userTesting-jeanlescure\" title=\"User Testing\"\u003e📓\u003c/a\u003e \u003ca href=\"https://github.com/simplyhexagonal/json-schema-to-mongoose-schema/commits?author=jeanlescure\" title=\"Tests\"\u003e⚠️\u003c/a\u003e \u003ca href=\"#example-jeanlescure\" title=\"Examples\"\u003e💡\u003c/a\u003e \u003ca href=\"https://github.com/simplyhexagonal/json-schema-to-mongoose-schema/commits?author=jeanlescure\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-enable --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n## License\n\nCopyright (c) 2021-Present [JSON Schema to Mongoose Schema Contributors](https://github.com/simplyhexagonal/json-schema-to-mongoose-schema/#contributors-).\u003cbr/\u003e\nLicensed under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplyhexagonal%2Fjson-schema-to-mongoose-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimplyhexagonal%2Fjson-schema-to-mongoose-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplyhexagonal%2Fjson-schema-to-mongoose-schema/lists"}