{"id":15233410,"url":"https://github.com/symphonicityy/mongoengine-jsonschema","last_synced_at":"2025-04-10T05:30:40.265Z","repository":{"id":174386836,"uuid":"651719127","full_name":"symphonicityy/mongoengine-jsonschema","owner":"symphonicityy","description":"MongoEngine JSON Schema Generator","archived":false,"fork":false,"pushed_at":"2023-08-01T11:00:12.000Z","size":46,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T06:51:32.337Z","etag":null,"topics":["json-schema","json-schema-generator","mongoengine"],"latest_commit_sha":null,"homepage":"","language":"Python","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/symphonicityy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-09T22:42:54.000Z","updated_at":"2024-10-31T08:53:38.000Z","dependencies_parsed_at":"2023-08-29T11:19:27.179Z","dependency_job_id":null,"html_url":"https://github.com/symphonicityy/mongoengine-jsonschema","commit_stats":null,"previous_names":["symphonicityy/mongoengine-jsonschema"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/symphonicityy%2Fmongoengine-jsonschema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/symphonicityy%2Fmongoengine-jsonschema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/symphonicityy%2Fmongoengine-jsonschema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/symphonicityy%2Fmongoengine-jsonschema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/symphonicityy","download_url":"https://codeload.github.com/symphonicityy/mongoengine-jsonschema/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248162928,"owners_count":21057838,"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":["json-schema","json-schema-generator","mongoengine"],"created_at":"2024-09-29T05:08:40.290Z","updated_at":"2025-04-10T05:30:40.220Z","avatar_url":"https://github.com/symphonicityy.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON Schema Generator for MongoEngine Documents\n\n## 📖 About the project\n\n### What is this and why?\nThis package provides a mixin class that extends a MongoEngine document's functionality by adding a `.json_schema()` method and allows generating a JSON schema directly from the document. Generated schema then can be used in API documentation or form validation and automatic form generation on a web application frontend, etc.\n\nGenerated schema should be compatible with [JSON schema specification](https://json-schema.org/specification.html) version Draft-7 and newer.\n\nTested on\n- Python 3.10\n- MongoEngine 0.27.0\n\nbut should work on Python \u003e= `3.7` and MongoEngine \u003e= `0.20.0` without any problems.\n\n## 🛠 Installation\n\n```sh\npip install mongoengine-jsonschema\n```\n\n## 💻 Getting started\nAdd `JsonSchemaMixin` to your document class as parent. Resolution order matters, so always place MongoEngine document first.\n```python\nimport mongoengine as me\nfrom mongoengine_jsonschema import JsonSchemaMixin\n\nclass Person(me.Document, JsonSchemaMixin):\n    name = me.StringField(required=True, min_length=1, max_length=32)\n    age = me.IntField(min_value=0)\n\n```\nThen you can generate JSON schema by calling `.json_schema()` method.\n```python\nPerson.json_schema()\n```\nwhich returns the schema as a Python dictionary\n```python\n{\n    '$id': '/schemas/Person',\n    'title': 'Person',\n    'type': 'object',\n    'properties': {\n        'age': {\n            'type': 'integer',\n            'title': 'Age',\n            'minimum': 0\n        },\n        'name': {\n            'type': 'string',\n            'title': 'Name',\n            'minLength': 1,\n            'maxLength': 32\n        }\n    },\n    'required': ['name'],\n    'additionalProperties': False\n}\n```\n\n### Example\nCheck out [example.md](https://github.com/symphonicityy/mongoengine-jsonschema/blob/main/example.md) for a more extensive example.\n\n### Features\n- Inheritance is supported. Make sure you add mixin to parent class.\n- `additionalProperties` is set to `False` for `DynamicDocument` and `DynamicEmbeddedDocument` classes.\n- `required` keyword can be removed by setting `strict` argument to `False` (`.json_schema(strict=False)`). This is useful for partial validation when updating documents using HTTP PATCH method.\n- Constraints for special `StringField` types such as `EmailField`, `URLField`, `UUIDField`, `DateTimeField` etc. are applied to schema using `format` and/or `pattern` keywords.\n- Fields derived from `GeoJsonBaseField` can be validated for both array and object types as supported by MongoEngine.\n- Field arguments/constraints `required`, `min_length`, `max_length`, `min_value`, `max_value`, `default`, `choices`, `regex` and `url_regex` (for `URLField`) are supported and reflected to schema.\n- Excluding a field from schema is possible with setting field argument `exclude_from_schema` to `True`. Example: \n    ```python \n    name = me.StringField(exclude_from_schema=True)\n    ```\n- Auto-generates human-friendly (first-letter capitalized, separate words) `title` from both document (PascalCase) and field names (snake_case). Keeps uppercase acronyms as is, e.g. `page_URL` -\u003e `Page URL`.\n- For `ListField` types, `required=True` means it cannot be empty, therefore, schema defines this constraint with `minItems` keyword.\n- Custom schemas can be defined directly in model class with `_JSONSCHEMA` class attribute. Setting a `_JSONSCHEMA` attribute will bypass JSON schema generation.\n\n### Limitations\n- `FileField`, `ImageField` fields are not supported\n- `PolygonField` and `MultiPolygonField` must start and end at the same point, but this is not enforced by generated schema\n- `schemes` argument is ignored for `URLField`\n- `domain_whitelist`, `allow_utf8_user`, `allow_ip_domain` arguments are ignored for `EmailField`\n- The following fields are defined in schema as strings and may require field specific conversion before assigning to a document's attribute:\n    - `ObjectIdField`\n    - `BinaryField`\n    - `DateTimeField`\n    - `ComplexDateTimeField`\n    - `DateField`\n    - `ReferenceField`\n    - `LazyReferenceField`\n    - `CachedReferenceField`\n    - `GenericReferenceField`\n    - `GenericLazyReferenceField`\n\n\n## 👥 Contact \u003ca name=\"contact\"/\u003e\n- Email: [myusuferoglu@gmail.com](\u003cmailto:myusuferoglu@gmail.com\u003e)\n- GitHub: [symphonicityy](https://github.com/symphonicityy)\n- Project Link: (https://github.com/symphonicityy/mongoengine-jsonschema)\n\n## 🤝 Contributing \u003ca name=\"contributing\"/\u003e\nContributions, issues, and feature requests are welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsymphonicityy%2Fmongoengine-jsonschema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsymphonicityy%2Fmongoengine-jsonschema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsymphonicityy%2Fmongoengine-jsonschema/lists"}