{"id":13772750,"url":"https://github.com/radekbusa/Pragma-Validators","last_synced_at":"2025-05-11T05:33:32.398Z","repository":{"id":215834946,"uuid":"315075059","full_name":"radekbusa/Pragma-Validators","owner":"radekbusa","description":"A set of declarative validators for Pharo accessors, inspired by JSR-380 Java Bean Validation annotations","archived":false,"fork":false,"pushed_at":"2020-11-22T18:35:57.000Z","size":10,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-17T08:44:05.539Z","etag":null,"topics":["api","pharo","rest-api","smalltalk","validation","validator"],"latest_commit_sha":null,"homepage":"","language":"Smalltalk","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/radekbusa.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}},"created_at":"2020-11-22T15:56:58.000Z","updated_at":"2024-08-05T17:39:23.000Z","dependencies_parsed_at":"2024-01-12T18:25:11.705Z","dependency_job_id":"e3e493ff-cfd4-42b2-a597-3701c680e484","html_url":"https://github.com/radekbusa/Pragma-Validators","commit_stats":null,"previous_names":["radekbusa/pragma-validators"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radekbusa%2FPragma-Validators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radekbusa%2FPragma-Validators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radekbusa%2FPragma-Validators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radekbusa%2FPragma-Validators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/radekbusa","download_url":"https://codeload.github.com/radekbusa/Pragma-Validators/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253523690,"owners_count":21921815,"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":["api","pharo","rest-api","smalltalk","validation","validator"],"created_at":"2024-08-03T17:01:07.480Z","updated_at":"2025-05-11T05:33:32.126Z","avatar_url":"https://github.com/radekbusa.png","language":"Smalltalk","readme":"# ✅ Pragma-Validators\nA set of declarative validators for Pharo accessors, inspired by JSR-380 Java Bean Validation annotations.\n\n## 🪄 Usage in a nutshell\n1. Make a class, declare several inst vars and generate their corresponsing accessors.\n```smalltalk\nObject subclass: #RegistrationRequest\n    instanceVariableNames: 'username name password emails'\n    classVariableNames: ''\n    package: 'MyApplication-DataTransfer'\n```\n\n2. Annotate the accessors with desired validators. \u003csup\u003e1),2)\u003c/sup\u003e\n\n2.1 Simple validation\n```smalltalk\nusername\n    \u003cvalidateAs: 'string'\u003e \"should be a string\"\n    \u003cvalidateAs: 'notBlank'\u003e \"notBlank ~ should not be an empty string or whitespace\"\n    ^ username\n```\n2.2 Collection validation (note that ALL collection elements must conform to the declared validation pragmas)\n```smalltalk\nemails\n    \u003cvalidateAs: '#string'\u003e\n    \u003cvalidateAs: '#email'\u003e \"the '#' signifies that emails shoule be a collection\"\n                           \"the 'email' signifies that each element of the collection\"\n                           \"should be a string containing a valid email\"\n    ^ emails\n```\n\t\n3. Validate the object once filled. If the validations find a problem, `PragmaValidationError` will be raised.\n```smalltalk\n| r |\nr := RegistrationRequest new username: 'john'; emails: {'john@smalltalk.com'. 'jsmith@acme.com'}; validate.\n```\n\n1) Note that annotating a mutator or an accessor with a protocol different than \"accessing\" will not work.\n\n2)The accessors are called in the process of validation, thus one must add additional code to them with caution.\n\n## 📑 Supported validations\n\n| Validation       | Usage Example                    | Description                                                                                    |\n|------------------|----------------------------------|------------------------------------------------------------------------------------------------|\n| `notNil`         | `\u003cvalidateAs: 'notNil'\u003e`         | Accessor value is not nil                                                                      |\n| `assertTrue`     | `\u003cvalidateAs: 'assertTrue'\u003e`     | Accessor value                                                                                 |\n| `size:MIN,MAX`   | `\u003cvalidateAs: 'size:1,3'\u003e`       | Accessor value has a size between the attributes MIN and MAX; can be applied to any collection |\n| `min:VAL`        | `\u003cvalidateAs: 'min:100'\u003e`        | Accessor value has a value no smaller than VAL                                                 |\n| `max:VAL`        | `\u003cvalidateAs: 'max:1000'\u003e`       | Accessor value has a value no larger than VAL                                                  |\n| `email`          | `\u003cvalidateAs: 'email'\u003e`          | Accessor value is a valid email address                                                        |\n| `notEmpty`       | `\u003cvalidateAs: 'notEmpty'\u003e`       | Accessor value is not null or empty; can be applied to any collection                          |\n| `notBlank`       | `\u003cvalidateAs: 'notBlank'\u003e`       | Accessor value is not null, empty string or string containing solely whitespace                |\n| `positive`       | `\u003cvalidateAs: 'positive'\u003e`       | Accessor value is strictly positive number                                                     |\n| `positiveOrZero` | `\u003cvalidateAs: 'positiveOrZero'\u003e` | Accessor value is strictly positive number, or 0                                               |\n| `negative`       | `\u003cvalidateAs: 'negative'\u003e`       | Accessor value is strictly negative number                                                     |\n| `negativeOrZero` | `\u003cvalidateAs: 'negativeOrZero'\u003e` | Accessor value is strictly negative number, or 0                                               |\n| `datetimeString` | `\u003cvalidateAs: 'datetimeString'\u003e` | Accessor value is a string containing date and time                                            |\n| `past`           | `\u003cvalidateAs: 'past'\u003e`           | Accessor value is a string containing date and time which is in the past                       |\n| `future`         | `\u003cvalidateAs: 'future'\u003e`         | Accessor value is a string containing date and time which is in the future                     |\n\n## 🎁 Installation\n```smalltalk\nMetacello new\n    baseline: 'PragmaValidators';\n    repository: 'github://radekbusa/Pragma-Validators';\n    load.\n```\n\n## 🔌 Integration example\nLet's say that we want to use the pragma validators for validating JSON request bodies in our RESTful API.\n\n1. In a controller or a Teapot filter, write:\n```smalltalk\n| body parsedBody |\nbody := aRequest entity string.\nparsedBody := NeoJSONReader fromString: body as: RegistrationRequest.\nparsedBody validate. \"will validate each incoming request body\"\n```\n\n## 🧩 Compatibility\nTested in Pharo 7, 8 and 9.\n\n## 👨‍💻 Author\nRadek Busa is the author and maintainer of this project.\n* Tech blog: [www.medium.com/@radekbusa](http://www.medium.com/@radekbusa)\n* Hire me for your next Smalltalk project: [www.radekbusa.eu](http://www.radekbusa.eu)\n\n\u003e \"I love building enterprise-grade software products in no time and Pharo greatly contributes to that with its amazing debugger, test-driven environment and other great stuff, such as refactoring tools. *My vision is to build libraries for ultra-productive enterprise microservice development with minimalistic and easy-to-grasp APIs for Smalltalk in 2020s.*\"\n\nIf you endorse my vision and/or this project helped you, please don't hesitate to donate. Your donations will be welcome!\n\n[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/donate?hosted_button_id=Z5NNZTU7VASJQ)\n","funding_links":["https://www.paypal.com/donate?hosted_button_id=Z5NNZTU7VASJQ"],"categories":["Web"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradekbusa%2FPragma-Validators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fradekbusa%2FPragma-Validators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradekbusa%2FPragma-Validators/lists"}