{"id":15013054,"url":"https://github.com/mberlanda/jsonschema_serializer","last_synced_at":"2025-04-12T04:21:08.045Z","repository":{"id":56879603,"uuid":"132598989","full_name":"mberlanda/jsonschema_serializer","owner":"mberlanda","description":"The gem is to generate JsonSchema","archived":false,"fork":false,"pushed_at":"2020-05-11T07:14:12.000Z","size":108,"stargazers_count":10,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T14:09:00.716Z","etag":null,"topics":["jsonschema","jsonschema-generator","ruby","serialization"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/jsonschema_serializer","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/mberlanda.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-08T11:27:30.000Z","updated_at":"2022-02-11T14:00:04.000Z","dependencies_parsed_at":"2022-08-20T11:40:43.255Z","dependency_job_id":null,"html_url":"https://github.com/mberlanda/jsonschema_serializer","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mberlanda%2Fjsonschema_serializer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mberlanda%2Fjsonschema_serializer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mberlanda%2Fjsonschema_serializer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mberlanda%2Fjsonschema_serializer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mberlanda","download_url":"https://codeload.github.com/mberlanda/jsonschema_serializer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248514411,"owners_count":21116961,"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":["jsonschema","jsonschema-generator","ruby","serialization"],"created_at":"2024-09-24T19:43:40.088Z","updated_at":"2025-04-12T04:21:08.013Z","avatar_url":"https://github.com/mberlanda.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JsonschemaSerializer\n\n[![Build Status](https://travis-ci.org/mberlanda/jsonschema_serializer.svg?branch=master)](https://travis-ci.org/mberlanda/jsonschema_serializer)\n[![Gem Version](https://badge.fury.io/rb/jsonschema_serializer.svg)](https://badge.fury.io/rb/jsonschema_serializer)\n[![Maintainability](https://api.codeclimate.com/v1/badges/7312071a0865c70f5d60/maintainability)](https://codeclimate.com/github/mberlanda/jsonschema_serializer/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/7312071a0865c70f5d60/test_coverage)](https://codeclimate.com/github/mberlanda/jsonschema_serializer/test_coverage)\n\nThis purpose of this gem is to generate [JsonSchema](http://json-schema.org/).\nThis can be achieved with a builder class or an `ActiveRecord` wrapper.\nThe gem is available for both Rails 4, 5 or in Ruby standalone projects.\n\nSince the project is still at an early stage, please do not hesitate to [open issues / feature requests](https://github.com/mberlanda/jsonschema_serializer/issues) or fork this repo for pull requests.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'jsonschema_serializer'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install jsonschema_serializer\n\n## Usage\n\nYou can generate a schema as follows:\n\n```ruby\nschema = JsonschemaSerializer::Builder.build do |b|\n\n  subscriber = b._object title: :subscriber, required: [:age] do |prop|\n    prop.merge! b.string :first_name, title: 'First Name'\n    prop.merge! b.string :last_name, title: 'Last Name'\n    prop.merge! b.integer :age, title: 'Age'\n  end\n\n  b.title \"a title\"\n  b.description \"a description\"\n  b.required :a, :b, :c\n  b.properties.tap do |p|\n    p.merge! b.string :a, description: \"abc\"\n    p.merge! b.array :subscribers, description: \"subscribers\", items: subscriber\n  end\nend\n\nschema.to_json\n```\n\nAllowed parameters for data types:\n\n- `array`  : `:default, :description, items: {}||[{}], :minItems, :maxItems, :title`\n- `boolean`: `:default, :description, :title`\n- `integer`: `:default, :description, enum: [], :minimum, :maximum, :multipleOf, :title`\n- `number` : `:default, :description, enum: [], :minimum, :maximum, :multipleOf, :title`\n- `string` : `:default, :description, :format, :minLength, :title`\n\nYou can alternatively use an experimental builder for `ActiveRecord`\n\n\n```ruby\nserializer = JsonschemaSerializer::ActiveRecord\n\nschema = serializer.from_model(MyActiveRecordClass)\nschema = serializer.from_model(MyActiveRecordClass, only: %[desired1 desired2])\nschema = serializer.from_model(MyActiveRecordClass, except: %[ignored1 ignored2])\n\n# You can manipulate the resulting schema\n\nschema.tap do |s|\n  s.title \"a title\"\n  s.description \"a description\"\nend\n\nschema.to_json\n```\n\n## Rails\n\nAt this stage, a first usage within a Rails application could be a rake task dumping the schemas inside the public folder.\n\n```ruby\n# lib/tasks/jsonschemas.rake\nrequire 'fileutils'\n\ntask dump_jsonschemas: :environment do\n  Rails.application.eager_load!\n  models = ActiveRecord::Base.descendants\n\n  output_path = Rails.root.join('public', 'data')\n  # Ensure that the destination path exists\n  FileUtils.mkdir_p(output_path)\n\n  models.each do |model|\n    # Skip abstract classes\n    if model.table_name\n      file_path = output_path.join(\"#{model.model_name.param_key}.json\")\n      schema = JsonschemaSerializer::ActiveRecord.from_model(model)\n\n      puts \"Creating #{file_path} ...\"\n      File.open(file_path, 'w') { |f| f.write(schema.to_json) }\n    else\n      puts \"Skipping abstract class #{model.to_s} ...\"\n    end\n  end\nend\n\n```\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\nIn order to test against serveral ruby and rails versions, you can simply run `scripts/run_all_tests`. In the gnome-terminal you may need to run `/bin/bash --login scripts/run_all_test`.\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/mberlanda/jsonschema_serializer.\nPlease ensure to keep the test coverage at 100% and follow the angularjs [commit message conv.entions](https://gist.github.com/stephenparish/9941e89d80e2bc58a153#subject-line).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmberlanda%2Fjsonschema_serializer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmberlanda%2Fjsonschema_serializer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmberlanda%2Fjsonschema_serializer/lists"}