Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
4a9e54d
Refactor database schema definitions for clarity and consistency
seenanair Jun 17, 2025
dea548e
Update Gemfile to simplify SQLite3 version handling
seenanair Jun 18, 2025
ff8bc72
Add missing require statement for Rails generators in controller and …
seenanair Jun 18, 2025
e83a160
Add JSONAPI::CompatibilityHelper module for version-safe deprecation …
seenanair Jun 18, 2025
0eb11bc
Refactor deprecation warnings to use CompatibilityHelper and ensure c…
seenanair Jun 18, 2025
652fdb5
Add nil check for relation_position to prevent processing errors
seenanair Jun 18, 2025
45328e3
Update test_helper.rb to improve deprecation handling and unify fixtu…
seenanair Jun 18, 2025
35aef58
Refactor CI configuration to simplify Ruby and Rails versions
seenanair Jun 18, 2025
a7f21c4
Update gemspec and version to reflect Sanger Institute ownership and …
seenanair Jun 18, 2025
d999a78
Add wrapper file for sanger-jsonapi-resources to ensure compatibility…
seenanair Jun 18, 2025
3100a4b
Add Ruby 3.4 to CI matrix for testing compatibility
seenanair Jun 18, 2025
98a6958
Merge pull request #4 from sanger/y25-318-from-master
seenanair Jun 30, 2025
54e8f69
Add compatibility for obsolete Rack status symbols
yoldas Sep 16, 2025
a098867
Change version to 0.2.1
yoldas Sep 16, 2025
ffc23d8
Merge pull request #6 from sanger/y25-319-from-master-as-psd-we-need-…
yoldas Sep 19, 2025
fe5e1f1
Rails 8.1 fix
dasunpubudumal Jan 26, 2026
c2f0662
Rails 8.1 fixes
dasunpubudumal Jan 26, 2026
b80866e
Debugs
dasunpubudumal Jan 26, 2026
7086a63
Debugs
dasunpubudumal Jan 26, 2026
5b08066
Debugs
dasunpubudumal Jan 26, 2026
2d15270
Debugs
dasunpubudumal Jan 26, 2026
143cc16
Debugs
dasunpubudumal Jan 26, 2026
4a7d666
Debugs
dasunpubudumal Jan 26, 2026
6f2d402
Debugs
dasunpubudumal Jan 26, 2026
5465f91
Debugs
dasunpubudumal Jan 26, 2026
71b84c2
Debugs
dasunpubudumal Jan 26, 2026
bde2c2a
Rails 8.1 compatibility fix
dasunpubudumal Jan 26, 2026
fe5f506
Refactor routing_ext.rb to use modern block style for resource handling
dasunpubudumal Jan 26, 2026
928771a
Refactor routing_ext.rb to use modern block style for resource handling
dasunpubudumal Jan 26, 2026
4c72d7f
Refactor routing_ext.rb to handle Rails version compatibility in reso…
dasunpubudumal Jan 26, 2026
cc52b3b
Bump version to 0.3.0
dasunpubudumal Jan 26, 2026
e247112
Merge pull request #10 from sanger/rails-8.1-fix
dasunpubudumal Jan 26, 2026
33321fa
Adding CONTRIBUTING.md
TWJW-SANGER Mar 16, 2026
8a4ffcd
Merge pull request #11 from sanger/Y26-054
TWJW-SANGER Mar 16, 2026
4a9b175
Updating contributing section in README.md to reference CONTRIBUTING.md
TWJW-SANGER Apr 1, 2026
3313b33
Merge pull request #12 from sanger/Y26-054
TWJW-SANGER Apr 1, 2026
8f9c257
style: lint ci
StephenHulme Aug 20, 2026
b284212
ci: actions/checkout version
StephenHulme Aug 20, 2026
6e868d4
ci: update Rails versions in test matrix
StephenHulme Aug 20, 2026
f802996
build: update min versions
StephenHulme Jul 3, 2026
9cee43c
build: limit rails versions to 7.2, 8.0+, not including 9+
StephenHulme Aug 20, 2026
88487bb
build: add rack 2 as a dependency
StephenHulme Aug 20, 2026
41c6eaa
release: bump version
StephenHulme Aug 11, 2026
8dbb966
test: repair old ruby 2 -> 3 errors
StephenHulme Aug 11, 2026
917c37c
build: add minitest-mock as a development dependency
StephenHulme Jul 3, 2026
d5afb85
test: repair test runner not being invoked
StephenHulme Aug 11, 2026
ed2929e
build: add minitest reporters for better test feedback
StephenHulme Aug 11, 2026
20f32ec
test: reduce verbosity of minitest output
StephenHulme Aug 11, 2026
5ec8202
test: separate rails version text
StephenHulme Aug 17, 2026
1154079
test: ignore temporary test files
StephenHulme Aug 12, 2026
8ace43f
test: update deprecation warning test
StephenHulme Aug 17, 2026
de41a93
fix: use Rails 8 style deprecation warning messages
StephenHulme Aug 17, 2026
1dab6ce
fix: improve handling of deprecation warnings
StephenHulme Aug 17, 2026
fd893ea
fix: repair deprecated code
StephenHulme Aug 17, 2026
49b976e
test: remove test-db as part of the rake task run
StephenHulme Aug 20, 2026
3d5dabb
build: add test support for Rails 7.1 for overlap with previous release
StephenHulme Aug 20, 2026
105fb13
docs: update README with Sanger release process
StephenHulme Aug 17, 2026
805e177
docs: update Rails versions aim
StephenHulme Aug 20, 2026
6017814
test: use the best reporter for each test environment
StephenHulme Aug 20, 2026
3463786
test: add patch to Rails version specifier for correct resolution
StephenHulme Aug 20, 2026
315d19c
test: file deprecation behaviour silencing for Rails 7.2
StephenHulme Aug 20, 2026
5bc93eb
fix: remove Rails 4 routing
StephenHulme Aug 20, 2026
6c55de1
fix: add support for keyword options in resources
StephenHulme Aug 20, 2026
ad1a448
test: update error message for Rails 8.1
StephenHulme Aug 17, 2026
042816e
test: handle different database True when on SQLite 8.1
StephenHulme Aug 20, 2026
ff5107f
build: set development rails to 8.1
StephenHulme Aug 20, 2026
815578c
build: add rack 3 as a dependency
StephenHulme Aug 11, 2026
11bf1fa
fix: unprocessable_entity -> unprocessable_content
StephenHulme Aug 11, 2026
40961b6
fix: replace updated Rack status_code function with legacy version
StephenHulme Aug 11, 2026
8f9a01c
test: add additional unprocessable content tests
StephenHulme Aug 11, 2026
5f5149f
test: add json-api error tests
StephenHulme Aug 12, 2026
2b1943a
fix: raise ArgumentError for nil status
StephenHulme Aug 12, 2026
e2add4f
release: bump patch version
StephenHulme Aug 20, 2026
00eb7de
ci: add Ruby 4 to test matrix
StephenHulme Aug 20, 2026
f66d967
release: bump patch version
StephenHulme Aug 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 12 additions & 52 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,38 @@ name: CI

on:
push:
branches: [ 'master', 'release-0-8', 'release-0-9', 'release-0-10' ]
branches: ["master"]
pull_request:
branches: ['**']
branches: ["**"]

jobs:
tests:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: password
POSTGRES_DB: test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
strategy:
fail-fast: false
matrix:
ruby:
- 2.6
- 2.7
- '3.0'
- 3.1
- 3.2
- "3.2"
- "3.3"
- "3.4"
- "4.0"
rails:
- 7.0.4
- 6.1.7
- 6.0.6
- 5.2.8.1
- 5.1.7
- "7.1"
- "7.2"
- "8.0"
- "8.1"
database_url:
- postgresql://postgres:password@localhost:5432/test
- sqlite3:test_db
exclude:
- ruby: 3.2
rails: 6.0.6
- ruby: 3.2
rails: 5.2.8.1
- ruby: 3.2
rails: 5.1.7
- ruby: 3.1
rails: 6.0.6
- ruby: 3.1
rails: 5.2.8.1
- ruby: 3.1
rails: 5.1.7
- ruby: '3.0'
rails: 6.0.6
- ruby: '3.0'
rails: 5.2.8.1
- ruby: '3.0'
rails: 5.1.7
- ruby: 2.6
rails: 7.0.4
- database_url: postgresql://postgres:password@localhost:5432/test
rails: 5.1.7
env:
RAILS_VERSION: ${{ matrix.rails }}
DATABASE_URL: ${{ matrix.database_url }}
name: Ruby ${{ matrix.ruby }} Rails ${{ matrix.rails }} DB ${{ matrix.database_url }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v7
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: Install dependencies
run: bundle install --jobs 4 --retry 3
bundler-cache: true
- name: Run tests
run: bundle exec rake test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ coverage
test/log
test_db
test_db-journal
test/test_db-*
.idea
*.iml
30 changes: 30 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Contributing

All contributions to this project are subject to the [MIT License](https://foss-haas.mit-license.org/). By submitting a contribution, you agree to license your work under these terms.

## Contribution Process

### 1. Issue First

All contributions from outside the core team require an **Issue First** approach. Before submitting a pull request (PR), you must:

- Open an issue in the repository.
- Ensure the issue includes:
- **Clear problem statement:** Describe the issue or feature request.
- **Reproduction steps:** If reporting a bug, provide steps to reproduce it.
- **Proposed approach:** Outline your suggested solution or implementation.
- **Why this change matters:** Explain the impact or necessity of the change.
- Tag `@sanger/psd-developers` in the issue to bring it to the attention of a maintainer.
- Wait for the issue to be assigned or approved by a maintainer.

### 2. Pull Request

Once your issue is approved:

- Fork the repository and create a branch for your changes.
- Submit a PR referencing the approved issue.
- Ensure your code adheres to the project's coding standards and passes all tests.

### 3. Review

Maintainers will review your PR. Address any feedback before merging.
15 changes: 7 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@ platforms :jruby do
end

version = ENV['RAILS_VERSION'] || 'default'
# If version is like 'x.y' add a '.0' to make it 'x.y.0' for correct resolution
version = "#{version}.0" if version =~ /^\d+\.\d+$/

platforms :ruby do
gem 'pg'

if version.start_with?('4.2', '5.0')
gem 'sqlite3', '~> 1.3.13'
else
gem 'sqlite3', '~> 1.4'
end
gem 'mysql2'
gem 'sqlite3'
gem 'csv'
end

case version
when 'master'
gem 'railties', { git: 'https://github.com/rails/rails.git' }
gem 'arel', { git: 'https://github.com/rails/arel.git' }
when 'default'
gem 'railties', '>= 6.0'
gem 'railties', '~> 8.1.0'
else
gem 'railties', "~> #{version}"
end
end
70 changes: 44 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# JSONAPI::Resources [![Gem Version](https://badge.fury.io/rb/jsonapi-resources.svg)](https://badge.fury.io/rb/jsonapi-resources) [![Build Status](https://secure.travis-ci.org/cerebris/jsonapi-resources.svg?branch=master)](http://travis-ci.org/cerebris/jsonapi-resources) [![Code Climate](https://codeclimate.com/github/cerebris/jsonapi-resources/badges/gpa.svg)](https://codeclimate.com/github/cerebris/jsonapi-resources)

[![Join the chat at https://gitter.im/cerebris/jsonapi-resources](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cerebris/jsonapi-resources?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
# JSONAPI::Resources (Sanger fork)

`JSONAPI::Resources`, or "JR", provides a framework for developing an API server that complies with the
[JSON:API](http://jsonapi.org/) specification.
Expand All @@ -13,7 +11,7 @@ backed by ActiveRecord models or by custom objects.

## Documentation

Full documentation can be found at [http://jsonapi-resources.com](http://jsonapi-resources.com), including the [v0.10 alpha Guide](http://jsonapi-resources.com/v0.10/guide/) specific to this version.
Full documentation can be found at [http://jsonapi-resources.com](http://jsonapi-resources.com), including the [v0.10 alpha Guide](http://jsonapi-resources.com/v0.10/guide/) specific to this version.

## Demo App

Expand All @@ -22,54 +20,74 @@ We have a simple demo app, called [Peeps](https://github.com/cerebris/peeps), av
## Client Libraries

JSON:API maintains a (non-verified) listing of [client libraries](http://jsonapi.org/implementations/#client-libraries)
which *should* be compatible with JSON:API compliant server implementations such as JR.
which _should_ be compatible with JSON:API compliant server implementations such as JR.

## Installation

Add JR to your application's `Gemfile`:

```
```
gem 'jsonapi-resources'
```

And then execute:

```bash
```bash
bundle
```

Or install it yourself as:

```bash
```bash
gem install jsonapi-resources
```

**For further usage see the [v0.10 alpha Guide](http://jsonapi-resources.com/v0.10/guide/)**

## Contributing
## Sanger-specific release process

There are two versions of the gem which we use for production. The version 1 series has unique customisations and is used by Sequencescape. The version 2 series is a more generic version which is used by Traction.

The aim is to support the 3 most recent Rails versions for each series to allow for seamless upgrades between releases.

1. Submit an issue describing any new features you wish it add or the bug you intend to fix
1. Fork it ( http://github.com/cerebris/jsonapi-resources/fork )
1. Create your feature branch (`git checkout -b my-new-feature`)
1. Run the full test suite (`rake test`)
1. Fix any failing tests
1. Commit your changes (`git commit -am 'Add some feature'`)
1. Push to the branch (`git push origin my-new-feature`)
1. Create a new Pull Request
Check which versions we have published at https://rubygems.org/gems/sanger-jsonapi-resources

## Did you find a bug?
### For version 1 series

* **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/cerebris/jsonapi-resources/issues).
- Create a branch from **develop**, apply fixes.
- Change version number in `lib/jsonapi/resources/version.rb` . This file is read by the gemspec during publication.
- Test Sequencescape with the gem from the branch.
- Merge the branch into develop.
- Create a release from the develop branch with the new version number as the tag. Set Release label to _None_.
<!-- list separator -->
- Checkout the newly-created tag on develop.
- Execute `bundle install` to ensure the gemspec is up to date.
- Execute `gem build jsonapi-resources.gemspec` which builds sanger-jsonapi-resources-0.1.x.gem in this case.
- Execute `gem push sanger-jsonapi-resources-0.1.x.gem` which publishes the gem.

* If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/cerebris/jsonapi-resources/issues/new).
Be sure to include a **title and clear description**, as much relevant information as possible,
and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.
### For version 2 series

* If possible, use the relevant bug report templates to create the issue.
Simply copy the content of the appropriate template into a .rb file, make the necessary changes to demonstrate the issue,
and **paste the content into the issue description or attach as a file**:
* [**Rails 5** issues](https://github.com/cerebris/jsonapi-resources/blob/master/lib/bug_report_templates/rails_5_master.rb)
- Create a branch from **master**, apply fixes.
- Change version number in `lib/jsonapi/resources/version.rb` . This file is read by the gemspec during publication.
- Test Traction with the gem from the branch.
- Merge the branch into master.
- Create a release from the master branch with the new version number as the tag. Set Release label to _Latest_.
<!-- list separator -->
- Checkout the newly-created tag on master.
- Execute `bundle install` to ensure the gemspec is up to date.
- Execute `gem build jsonapi-resources.gemspec` which builds sanger-jsonapi-resources-0.2.x.gem in this case.
- Execute `gem push sanger-jsonapi-resources-0.2.x.gem` which publishes the gem.

### Publication

You will be notified by email for each. You will also receive one email for API key setup. The first push will ask email and password for the account, which are in KeePass (search for "gem").

> [!NOTE]
> The email and password for gem publication is a recent addition to the credentials database. Pull latest changes in the credentials repo.

## Contributing

See CONTRIBUTING.md for details.

## License

Expand Down
9 changes: 8 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
#!/usr/bin/env rake
require 'bundler/gem_tasks'
require 'fileutils'
require 'rake/testtask'

task :remove_test_db do
FileUtils.rm_f(File.expand_path('test/test_db', __dir__))
end

Rake::TestTask.new do |t|
t.verbose = true
t.verbose = false
t.warning = false
t.test_files = FileList['test/**/*_test.rb']
end

Rake::Task[:test].enhance([:remove_test_db])

task default: [:test]

desc 'Run benchmarks'
Expand Down
21 changes: 12 additions & 9 deletions jsonapi-resources.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,33 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'jsonapi/resources/version'

Gem::Specification.new do |spec|
spec.name = 'jsonapi-resources'
spec.name = 'sanger-jsonapi-resources'
spec.version = JSONAPI::Resources::VERSION
spec.authors = ['Dan Gebhardt', 'Larry Gebhardt']
spec.email = ['dan@cerebris.com', 'larry@cerebris.com']
spec.authors = ['PSD Team - Wellcome Trust Sanger Institute']
spec.email = ['psd@sanger.ac.uk']
spec.summary = 'Easily support JSON API in Rails.'
spec.description = 'A resource-centric approach to implementing the controllers, routes, and serializers needed to support the JSON API spec.'
spec.homepage = 'https://github.com/cerebris/jsonapi-resources'
spec.description = 'Forked from jsonapi-resources. A resource-centric approach to implementing the controllers, routes, and serializers needed to support the JSON API spec.'
spec.homepage = 'https://github.com/sanger/jsonapi-resources'
spec.license = 'MIT'

spec.files = Dir.glob("{bin,lib}/**/*") + %w(LICENSE.txt README.md)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']
spec.required_ruby_version = '>= 2.3'
spec.required_ruby_version = '>= 3.2'

spec.add_development_dependency 'bundler', '>= 1.17'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'minitest', '~> 5.10', '!= 5.10.2'
spec.add_development_dependency 'minitest'
spec.add_development_dependency 'minitest-mock'
spec.add_development_dependency 'minitest-spec-rails'
spec.add_development_dependency 'minitest-reporters'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'concurrent-ruby-ext'
spec.add_development_dependency 'database_cleaner'
spec.add_dependency 'activerecord', '>= 5.1'
spec.add_dependency 'railties', '>= 5.1'
spec.add_dependency 'activerecord', '>= 7.1', '< 9.0' # versions 7.1, 7.2, 8.0, 8.1, and above, but not 9.0
spec.add_dependency 'railties', '>= 7.1', '< 9.0' # versions 7.1, 7.2, 8.0, 8.1, and above, but not 9.0
spec.add_dependency 'rack', '~> 3.0'
spec.add_dependency 'concurrent-ruby'
end
1 change: 1 addition & 0 deletions lib/generators/jsonapi/controller_generator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'rails/generators'
module Jsonapi
class ControllerGenerator < Rails::Generators::NamedBase
source_root File.expand_path('../templates', __FILE__)
Expand Down
1 change: 1 addition & 0 deletions lib/generators/jsonapi/resource_generator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'rails/generators'
module Jsonapi
class ResourceGenerator < Rails::Generators::NamedBase
source_root File.expand_path('../templates', __FILE__)
Expand Down
12 changes: 8 additions & 4 deletions lib/jsonapi/active_relation_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -666,10 +666,14 @@ def find_related_polymorphic_fragments(source_fragments, relationship, options,
end

relation_position = relation_positions[row[2].downcase.pluralize]
model_fields = relation_position[:model_fields]
cache_field = relation_position[:cache_field]
cache_offset = relation_position[:cache_offset]
field_offset = relation_position[:field_offset]
if relation_position
model_fields = relation_position[:model_fields]
cache_field = relation_position[:cache_field]
cache_offset = relation_position[:cache_offset]
field_offset = relation_position[:field_offset]
else
next # Skip processing if relation_position is nil
end

if cache_field
related_fragments[rid].cache = cast_to_attribute_type(row[cache_offset], cache_field[:type])
Expand Down
10 changes: 5 additions & 5 deletions lib/jsonapi/acts_as_resource_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'csv'

require_relative 'compatibility_helper'
module JSONAPI
module ActsAsResourceController
MEDIA_TYPE_MATCHER = /.+".+"[^,]*|[^,]+/
Expand Down Expand Up @@ -63,16 +63,16 @@ def index_related_resources

def get_related_resource
# :nocov:
ActiveSupport::Deprecation.warn "In #{self.class.name} you exposed a `get_related_resource`"\
" action. Please use `show_related_resource` instead."
JSONAPI::CompatibilityHelper.deprecation_warn("In #{self.class.name} you exposed a `get_related_resource`"\
" action. Please use `show_related_resource` instead.")
show_related_resource
# :nocov:
end

def get_related_resources
# :nocov:
ActiveSupport::Deprecation.warn "In #{self.class.name} you exposed a `get_related_resources`"\
" action. Please use `index_related_resources` instead."
JSONAPI::CompatibilityHelper.deprecation_warn("In #{self.class.name} you exposed a `get_related_resources`"\
" action. Please use `index_related_resources` instead.")
index_related_resources
# :nocov:
end
Expand Down
Loading