{"id":15797871,"url":"https://github.com/qequ/schematics","last_synced_at":"2025-03-31T19:45:32.242Z","repository":{"id":115065193,"uuid":"597603369","full_name":"qequ/schematics","owner":"qequ","description":"a library to validate data using schemas","archived":false,"fork":false,"pushed_at":"2023-10-16T22:07:28.000Z","size":11,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-12T00:42:58.979Z","etag":null,"topics":["crystal","crystal-lang","crystal-shard","validation","validation-library"],"latest_commit_sha":null,"homepage":"","language":"Crystal","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/qequ.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-02-05T03:15:39.000Z","updated_at":"2023-10-16T22:18:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"b588295c-7f7b-4e01-9665-9af3d34c0e8f","html_url":"https://github.com/qequ/schematics","commit_stats":{"total_commits":10,"total_committers":2,"mean_commits":5.0,"dds":"0.19999999999999996","last_synced_commit":"8dded2b0e7398b7af784c6b95ebc5d70e9ee1853"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qequ%2Fschematics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qequ%2Fschematics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qequ%2Fschematics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qequ%2Fschematics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qequ","download_url":"https://codeload.github.com/qequ/schematics/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246531986,"owners_count":20792735,"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":["crystal","crystal-lang","crystal-shard","validation","validation-library"],"created_at":"2024-10-05T00:21:34.562Z","updated_at":"2025-03-31T19:45:32.220Z","avatar_url":"https://github.com/qequ.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# schematics\n\na library to validate data using schemas expressed as Crystal classes\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n   ```yaml\n   dependencies:\n     schematics:\n       github: qequ/schematics\n   ```\n\n2. Run `shards install`\n\n## Usage\n\n```crystal\nrequire \"schematics\"\n```\n\nInstantiate a new Schema class and define the fields you want to validate:\n\n```crystal\n    schema = Schema.new(String)\n    schema.validate(\"hello\") # =\u003e true\n```\n\nYou can also validate complex arrays\n\n```crystal\n    schema = Schema.new(Array(String))\n    schema.validate([\"hello\", \"world\"]) # =\u003e true\n```\n\n```crystal\n    schema = Schema.new([Array(String), Int32, [[Bool]]])\n    schema.validate([[\"hello\", \"world\"], 1, [[true]]]) # =\u003e true\n```\n\n### Hashes\n\nValidating hashes with basic types:\n\n```crystal\nschema = Schema.new(Hash(String, Int32))\nschema.validate({\"a\" =\u003e 1, \"b\" =\u003e 2}) # =\u003e true\n```\n\nHashes with different key types should fail:\n\n```crystal\nschema = Schema.new(Hash(String, Int32))\nschema.validate({\"a\" =\u003e 1, 1 =\u003e 2}) # =\u003e false\n```\n\nNested hashes:\n\n```crystal\nschema = Schema.new(Hash(String, Hash(String, Int32)))\nschema.validate({\"a\" =\u003e {\"b\" =\u003e 1}, \"c\" =\u003e {\"d\" =\u003e 2}}) # =\u003e true\n```\n\nHashes with mixed types:\n\n```crystal\nschema = Schema.new(Hash(String, Array(Int32)))\nschema.validate({\"a\" =\u003e [1,2,3], \"b\" =\u003e [4,5,6]}) # =\u003e true\n```\n\n### Structs\n\nYou can validate data against a struct:\n\n```crystal\nstruct Person\nproperty name : String\nproperty age : Int32\n\ndef initialize(@name : String, @age : Int32)\nend\nend\n\nschema = Schema.new(Person)\nperson_instance = Person.new(name: \"John\", age: 30)\nschema.validate(person_instance) # =\u003e true\n```\n\n\nFor more examples and advanced use cases, check the specs.\n\n\n\n## Development\n\nUntil this version Schematics only validates Basic data types (int, string, bool, etc) and Arrays of those types or nested arrays.\n\nUpcoming versions should parse more complex types like Hashes, Structs, etc.\n\n### TODO\n\n- [x] Add support for Hashes\n- [x] Add support for Structs\n- [ ] Add support for custom types\n- [ ] Add support for custom validations\n\n\n## Contributing\n\n1. Fork it (\u003chttps://github.com/qequ/schematics/fork\u003e)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [Alvaro Frias Garay](https://github.com/qequ) - creator and maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqequ%2Fschematics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqequ%2Fschematics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqequ%2Fschematics/lists"}