{"id":16746690,"url":"https://github.com/mkon/invalid_model-serializer","last_synced_at":"2025-03-21T22:31:43.973Z","repository":{"id":35049334,"uuid":"171122664","full_name":"mkon/invalid_model-serializer","owner":"mkon","description":"Serialize models with validation errors to json-api errors.","archived":false,"fork":false,"pushed_at":"2025-03-11T12:55:51.000Z","size":73,"stargazers_count":2,"open_issues_count":3,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-18T05:43:55.623Z","etag":null,"topics":["json-api","rails","ruby"],"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/mkon.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":"2019-02-17T13:01:52.000Z","updated_at":"2022-05-04T19:44:31.000Z","dependencies_parsed_at":"2024-02-05T11:29:49.162Z","dependency_job_id":"99df1d2f-d10f-4e0e-aa70-a44c7473eccf","html_url":"https://github.com/mkon/invalid_model-serializer","commit_stats":{"total_commits":44,"total_committers":4,"mean_commits":11.0,"dds":0.4545454545454546,"last_synced_commit":"345366fab58e7bbe96d594a63802a6187a6a2853"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkon%2Finvalid_model-serializer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkon%2Finvalid_model-serializer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkon%2Finvalid_model-serializer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkon%2Finvalid_model-serializer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkon","download_url":"https://codeload.github.com/mkon/invalid_model-serializer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244880285,"owners_count":20525506,"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":["json-api","rails","ruby"],"created_at":"2024-10-13T02:08:08.617Z","updated_at":"2025-03-21T22:31:43.702Z","avatar_url":"https://github.com/mkon.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# InvalidModel Serializer\n\nYou are using one of the many ruby `json_api` serializer gems like `active_model_serializers` or `fast_jsonapi`, but are not satisfied with the rendering of validation errors?\n\nThis gem is trying to fit this gap.\n\n## Usage\n\nAdd the gem to your Gemfile\n\n```ruby\ngem 'invalid_model-serializer'\n```\n\nTo generate a `json-api` compliant error hash simply call\n```ruby\nInvalidModel::Serializer.new(invalid_model).serializable_hash\n```\n\nWhich should parse your `ActiveModel` compatible errors and produce something like:\n\n```json\n{\n  \"errors\": [\n    {\n      \"code\": \"validation_error/too_short\",\n      \"detail\": \"Name is too short (minimum is 6 characters)\",\n      \"meta\": {\n        \"count\": 6\n      },\n      \"source\": {\n        \"pointer\": \"/data/attributes/name\"\n      },\n      \"status\": \"400\"\n    }\n  ]\n}\n```\n\n### Rails\n\nIn a rails controller you could for example use:\n\n```ruby\ndef create\n  ...\n  if @record.save\n    head :no_content\n  else\n    render json: InvalidModel::Serializer.new(@record).serializable_hash, status: :bad_request\n  end\nend\n```\n\n### Options\n\nYou can pass options to the serializer as 2nd argument. The following keys are supported:\n* `code_format`: Override the default format. This string will be passed through a `format` method so you can use some placeholders like `type` and `attribute`.\n* `status`: Set a different status, default is `400`\n* `each_serializer`: Use your own serializer for error objects.\n\n### Configuration\n\nAdditionally you can set `code_format` and `status` globally via:\n```ruby\nInvalidModel::Serializer.configure do |config|\n  config.default_code_format = 'validation_error/%{model}.%{attribute}.%{type}'\n  config.default_status = '422'\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkon%2Finvalid_model-serializer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkon%2Finvalid_model-serializer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkon%2Finvalid_model-serializer/lists"}