{"id":15801847,"url":"https://github.com/zhandao/zero-params_processor","last_synced_at":"2025-07-28T00:32:40.862Z","repository":{"id":56899321,"uuid":"105352964","full_name":"zhandao/zero-params_processor","owner":"zhandao","description":"Process parameters base on OpenApi3 JSON documentation, such as: validation and type conversion","archived":false,"fork":false,"pushed_at":"2020-09-20T12:57:35.000Z","size":70,"stargazers_count":2,"open_issues_count":6,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-09T13:28:29.787Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/zhandao.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-30T07:55:31.000Z","updated_at":"2019-03-31T06:28:54.000Z","dependencies_parsed_at":"2022-08-21T01:50:22.986Z","dependency_job_id":null,"html_url":"https://github.com/zhandao/zero-params_processor","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/zhandao/zero-params_processor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhandao%2Fzero-params_processor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhandao%2Fzero-params_processor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhandao%2Fzero-params_processor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhandao%2Fzero-params_processor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhandao","download_url":"https://codeload.github.com/zhandao/zero-params_processor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhandao%2Fzero-params_processor/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267446806,"owners_count":24088561,"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","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-10-05T01:41:05.319Z","updated_at":"2025-07-28T00:32:40.571Z","avatar_url":"https://github.com/zhandao.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Zero::ParamsProcessor\n\n[![Build Status](https://travis-ci.org/zhandao/zero-params_processor.svg?branch=test)](https://travis-ci.org/zhandao/zero-params_processor)\n[![Maintainability](https://api.codeclimate.com/v1/badges/4d2fd3c04abf75a1158b/maintainability)](https://codeclimate.com/github/zhandao/zero-params_processor/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/4d2fd3c04abf75a1158b/test_coverage)](https://codeclimate.com/github/zhandao/zero-params_processor/test_coverage)\n\n```ruby\n# declare aop callback which provided by zpp\nbefore_action :process_params!\n\n# if you defined following spec in your api doc\n# `query!` bang method means it's a required param\nquery! :time, Date, gt: '2018/1/1'.to_date, permit: true\n\n# THEN in your controller action, you will get:\n# 1. param validate: require, Date type and range\n# 2. value convert: JSON has not Date type, you must\n#\t   do a convert from String, but it can do it for you:\nparams[:time] = params[:time].to_date # after some format checkers\n# 3. set instance variable: allows you get the param by `@time`\n#      instead of `params[:time]`\n# 4. permitted: if you defined a lot of params with `permit: true`,\n#      you will be allowed to get them by calling `permitted`, like:\nBook.create(permitted)\n```\n\n## ONLY FOR the RAILS app that using Zero-Rails_OpenApi, like [Zero-Rails](https://github.com/zhandao/zero-rails)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'zero-params_processor'#, github: 'zhandao/zero-params_processor'\n```\n\nAnd then execute:\n\n    $ bundle\n\n## Usage\n\n```ruby\nbefore_action { process_params_by :validate!, :convert }\nbefore_action :process_params! # all actions will be called\n```\nAction options: %i[ validate! convert set_instance_var set_permitted ]\n\n### validate!\n\nCheck each input parameter based on `OpenApi.docs` (Zero-Rails_OpenApi's cattr), it will\nraise `ParamsProcessor::ValidationFailed \u003c StandardError` if check failed.\n\nNote: If it did not find the corresponding open-api information in `OpenApi.docs`,\nthe check will be skipped.\n\n### convert\n\nConvert each input parameter to the specified type base on `OpenApi.docs`. For example:\n\nWe declare the parameter like this:\n```ruby\nquery :price, Integer\nquery :like,  Boolean\nquery :time,  Date\n```\nIn case params[:price] == `'1'`, the Converter will make it to be `1` (a Integer).  \nIn case params[:like] == `0`, the Converter will make it to be `false`.  \nIn case params[:time] == `'2018/1/1'`, the Converter will make it to be `Date.new(2018, 1, 1)`.  \n\n### set_instance_var\n\nLet (converted) input parameters to be instance variables of the current controller.\n\nAfter that, you can access the params value like: `@price`, `@like`, `@time`.\n\n### set_permitted\n\nPermit the parameters that having `permit: true` attribute in `OpenApi.docs`. Like this:\n\n```ruby\nquery :price, Integer, pmt: true\n```\n\nThen, the :price parameter will be permitted.\n\nAfter this action, you can access all the permitted input via method `permitted`. Like:\n\n```ruby\nBook.create(permitted)\n```\n\nNote: `not_permit: true` attribute will lead to a slightly different behavior: All the\nparameter that are not having `not_permit: true` will be permitted. For example:\n\n```ruby\nquery :price, Integer\nquery :like, Boolean, npmt: true\nquery :time, Date\n```\n\nThen, the :price and :time will be permitted.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/zero-params_processor. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Zero::ParamsProcessor project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/zero-params_processor/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhandao%2Fzero-params_processor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhandao%2Fzero-params_processor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhandao%2Fzero-params_processor/lists"}