Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fsubal/jbreaker
Write jbuilder and JSON Schema in the same one file.
https://github.com/fsubal/jbreaker
Last synced: about 1 month ago
JSON representation
Write jbuilder and JSON Schema in the same one file.
- Host: GitHub
- URL: https://github.com/fsubal/jbreaker
- Owner: fsubal
- License: mit
- Created: 2023-11-26T09:02:49.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-30T13:39:42.000Z (about 1 year ago)
- Last Synced: 2025-01-03T01:59:18.317Z (about 2 months ago)
- Language: Ruby
- Size: 74.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Jbreaker
Write jbuilder and JSON Schema in the same one file.
## Usage
Given the following jbuilder,
```ruby
json.id @item.id
json.description @item.description ? simple_format(@item.description) : niljson.shop do
json.partial! 'shops/shop', locals: { shop: shop }
end
```You can migrate it like following.
```ruby
def render(shop:)
json.id @item.id
json.description @item.description ? simple_format(@item.description) : niljson.shop do
json.partial! 'shops/shop', locals: { shop: shop }
end
end
```And you can have the corresponding JSON Schema in the same file.
```ruby
def render(shop:)
json.id @item.id
json.description @item.description ? simple_format(@item.description) : niljson.shop do
json.partial! 'shops/shop', locals: { shop: shop }
end
enddef self.schema
t.object({
id: t.number,
description: t.string(nullable: true),
shop: t.ref('shops/shop'),
})
end
```## Installation
Add this line to your application's Gemfile:
```ruby
gem "jbreaker"
```And then execute:
```bash
$ bundle
```Or install it yourself as:
```bash
$ gem install jbreaker
```## Contributing
Contribution directions go here.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).