{"id":26733476,"url":"https://github.com/amcaplan/swagger_shield","last_synced_at":"2025-04-14T12:41:31.234Z","repository":{"id":59156954,"uuid":"109757193","full_name":"amcaplan/swagger_shield","owner":"amcaplan","description":"Shield Your API Endpoints from Improperly Formatted Requests!","archived":false,"fork":false,"pushed_at":"2017-11-29T20:42:21.000Z","size":59,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-24T20:03:57.061Z","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/amcaplan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-06T22:25:08.000Z","updated_at":"2019-09-13T18:38:06.000Z","dependencies_parsed_at":"2022-09-13T20:10:18.122Z","dependency_job_id":null,"html_url":"https://github.com/amcaplan/swagger_shield","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amcaplan%2Fswagger_shield","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amcaplan%2Fswagger_shield/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amcaplan%2Fswagger_shield/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amcaplan%2Fswagger_shield/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amcaplan","download_url":"https://codeload.github.com/amcaplan/swagger_shield/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248883078,"owners_count":21177147,"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":[],"created_at":"2025-03-28T01:49:50.724Z","updated_at":"2025-04-14T12:41:31.209Z","avatar_url":"https://github.com/amcaplan.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/amcaplan/swagger_shield.svg?branch=master)](https://travis-ci.org/amcaplan/swagger_shield)\n[![Gem Version](https://badge.fury.io/rb/swagger_shield.svg)](https://badge.fury.io/rb/swagger_shield)\n\n# SwaggerShield\n\nTired of getting weird errors when users (or your own clients) submit random\njunk to your Rails API?  `SwaggerShield` is here to save the day!\n\n## Usage\n\n```ruby\n# You can add to any controller, or to ApplicationController if you want\n# SwaggerShield to protect your whole app.\nclass ApplicationController \u003c ActionController::API\n  SwaggerShield.protect!(\n    self,\n\n    # replace with the location of your actual swagger YAML file:\n    swagger_file: File.join('config', 'swagger.yml'),\n\n    # add on any valid \"if\" or \"unless\" conditionals that can be applied to a\n    # Rails before_action\n    if: -\u003e { current_user.test_user? },\n    unless: -\u003e { params[:skip_swagger_shield] }\n  )\nend\n```\n\nNow, everything will work as before, as long as the requests are properly\nformatted.  But if requests don't match your Swagger spec:\n\n![You Shall Not Pass!](https://i0.wp.com/gifrific.com/wp-content/uploads/2017/11/you-shall-not-pass-gandalf-lotr.gif)\n\nOK, maybe it's not that dramatic.  But your client will see an error pointing to\nexactly what they messed up in the request:\n\n```json\n{\n  \"errors\": [\n    {\n      \"status\": \"422\",\n      \"detail\": \"The property '#/widget/price' of type string did not match the following type: integer\",\n      \"source\": {\n        \"pointer\": \"#/widget/price\"\n      }\n    }\n  ]\n}\n```\n\n(Only errors in JSON API format are supported, hopefully that'll be updated\nsoon...)\n\n## Warning!\n\nThis project is under active development, being built up in stages as bits\nbecome necessary for projects that make money.  So there's still plenty of stuff\nto implement; use at your own risk.\n\nThat said, the project will gratefully accept the implementation of new types,\nbetter error messaging, etc., basically anything you find useful in your own\nwork which seems generally applicable.  So please [contribute](#development)!\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'swagger_shield'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install swagger_shield\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\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/amcaplan/swagger_shield. 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](http://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the SwaggerShield project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/amcaplan/swagger_shield/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famcaplan%2Fswagger_shield","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famcaplan%2Fswagger_shield","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famcaplan%2Fswagger_shield/lists"}