{"id":28629186,"url":"https://github.com/odd12258053/dade","last_synced_at":"2025-06-12T11:41:41.406Z","repository":{"id":43223097,"uuid":"459657831","full_name":"odd12258053/dade","owner":"odd12258053","description":"dade is data definition for Rust structures.","archived":false,"fork":false,"pushed_at":"2022-10-14T06:13:55.000Z","size":1324,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-01T15:56:49.616Z","etag":null,"topics":["data","json","json-schema","parsing","rust","validation"],"latest_commit_sha":null,"homepage":"https://odd12258053.github.io/dade/","language":"Rust","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/odd12258053.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}},"created_at":"2022-02-15T16:23:55.000Z","updated_at":"2022-05-01T14:01:24.000Z","dependencies_parsed_at":"2022-09-05T07:10:50.130Z","dependency_job_id":null,"html_url":"https://github.com/odd12258053/dade","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/odd12258053/dade","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odd12258053%2Fdade","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odd12258053%2Fdade/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odd12258053%2Fdade/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odd12258053%2Fdade/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/odd12258053","download_url":"https://codeload.github.com/odd12258053/dade/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odd12258053%2Fdade/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259456998,"owners_count":22860645,"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":["data","json","json-schema","parsing","rust","validation"],"created_at":"2025-06-12T11:41:18.843Z","updated_at":"2025-06-12T11:41:41.371Z","avatar_url":"https://github.com/odd12258053.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dade\n![Test](https://github.com/odd12258053/dade/workflows/Test/badge.svg)\n[![Crates.io](https://img.shields.io/crates/v/dade.svg)](https://crates.io/crates/dade)\n\n`dade` is a framework for defining data structure to Rust structures, like [pydantic](https://pydantic-docs.helpmanual.io) in Python.\n\nFor the easy handle of data, the following will support it.\n+ [x] validation for (primitive) types.\n   + [x] numeric types; u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize, f32, f64\n   + [x] boolean\n   + [x] String\n   + [x] Optional\n   + [x] Vec\n   + [x] nested model\n   + [x] enum\n+ [x] export a data schema conforms JsonSchema.\n+ [x] load a model from JSON.\n+ [x] dump a JSON-string from a model.\n+ [ ] implements for useful types. e.g. URL, email and etc.\n+ [ ] publish a trait that for you implements any custom type with your validation. \n\nSee [documentation](https://odd12258053.github.io/dade/) for more details.\n\n## Roadmap\n+ ~~implements for basic idea.~~\n+ ~~implements for (primitive) types, enum, and more.~~\n+ support configuration of a model, for example, set a given name to a title in JsonSchema, or exclusion another key.\n+ implements for useful types and a trait for custom type.\n\n## Example\n### Basic\nTo define a model, You need the below module.\n\n```rust\nuse dade::{Model, model};\n```\n\nFor example, define user-model.\n```rust\n#[model]\nstruct User {\n    #[field(ge = 1)]\n    id: u64,\n    #[field(min_length = 1, max_length = 100)]\n    name: String,\n    #[field(default = \"en\")]\n    lang: String,\n    #[field(min_length = 1, max_length = 255, default = null)]\n    url: Option\u003cString\u003e,\n    #[field(default = false)]\n    verified: bool,\n}\n```\n\nThen you create an instance of the model by the below.\n\n```rust\nlet input = \"{\\\"id\\\": 1, \\\"name\\\": \\\"James Smith\\\"}\";\nlet user = User::parse(input).unwrap();\n```\n\nAnd you get a Json string for the instance by the below.\n```rust\nlet json_string = user.json(false);\n// json_string = \"{\\\"id\\\":1,\\\"name\\\":\\\"James Smith\\\",\\\"lang\\\":\\\"en\\\",\\\"url\\\":null,\\\"verified\\\":false}\"\n```\n\nIf you want to validate a value, you will get a schema that conforms JsonSchema, for the given model, by the below.\n\n```rust\nlet schema = User::schema();\n```\n\nThe schema is \n```json\n{\n  \"$ref\": \"#/definitions/User\",\n  \"definitions\": {\n    \"User\": {\n      \"title\": \"User\",\n      \"type\": \"object\",\n      \"properties\": {\n        \"id\": {\n          \"type\": \"integer\",\n          \"title\": \"Id\",\n          \"minimum\": 1\n        },\n        \"name\": {\n          \"type\": \"string\",\n          \"title\": \"Name\",\n          \"minLength\": 1,\n          \"maxLength\": 100\n        },\n        \"lang\": {\n          \"type\": \"string\",\n          \"title\": \"Lang\",\n          \"default\": \"en\"\n        },\n        \"url\": {\n          \"type\": \"string\",\n          \"title\": \"Url\",\n          \"default\": null,\n          \"minLength\": 1,\n          \"maxLength\": 255\n        },\n        \"verified\": {\n          \"type\": \"boolean\",\n          \"title\": \"Verified\",\n          \"default\": false\n        }\n      },\n      \"required\": [\"id\", \"name\"]\n    }\n  }\n}\n```\n\n\n### Advance\n* If you want to bind other name\n```rust\n#[model]\nstruct User {\n    id: u64,\n    #[field(alias = \"FirstName\")]\n    first_name: String,\n    #[field(alias = \"LastName\")]\n    last_name: String,\n}\n```\n\n* If you need a nested model \n\n```rust\n#[model]\nstruct Name {\n    first_name: String,\n    last_name: String,\n}\n\n#[model]\nstruct User {\n    id: u64,\n    name: Name,\n}\n```\n\n* If you need a self-reference model\n\n```rust\n#[model]\nstruct Item {\n    id: u64,\n    name: String,\n    value: u128,\n    related_items: Option\u003cVec\u003cBox\u003cItem\u003e\u003e\u003e,\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fodd12258053%2Fdade","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fodd12258053%2Fdade","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fodd12258053%2Fdade/lists"}