From ce6915fa732bd36bd0d237d071e2a7395317b9c8 Mon Sep 17 00:00:00 2001 From: Alex Tucker Date: Fri, 4 Oct 2024 16:53:35 +0100 Subject: [PATCH 01/18] Minimal, backwards compatible change to take path to application.yaml or endpointSpecs directory. --- lib/sapi_client/application.rb | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/sapi_client/application.rb b/lib/sapi_client/application.rb index 9cfaaf3..2c2aead 100644 --- a/lib/sapi_client/application.rb +++ b/lib/sapi_client/application.rb @@ -5,14 +5,17 @@ module SapiClient # enclosed endpoint specifications to perform various operations, such as creating # methods we can call class Application - def initialize(base_url, application_spec) - unless File.exist?(application_spec) - raise(SapiError, "Could not find application spec #{application_spec}") + def initialize(base_url, application_or_endpoints) + unless File.exist?(application_or_endpoints) + raise(SapiError, "Could not find application spec #{application_or_endpoints}") end @base_url = base_url - @application_spec_file = application_spec - @specification = YAML.load_file(application_spec) + @application_spec_file = application_or_endpoints if File.file?(application_or_endpoints) + @endpoints_path = application_or_endpoints if File.directory?(application_or_endpoints) + @specification = (@application_spec_file && YAML.load_file(application_or_endpoints)) || { + 'sapi-nt' => { 'config' => { 'loadSpecPath' => 'classpath:endpointSpecs' } } + } end attr_reader :base_url, :specification @@ -30,11 +33,15 @@ def application_spec_dir end def load_spec_path - configuration['loadSpecPath'].sub(/^classpath:/, '') + @endpoints_path || configuration['loadSpecPath'].sub(/^classpath:/, '') end def endpoint_group_files - Dir["#{application_spec_dir}/#{load_spec_path}/*.yaml"] + if @endpoints_path.nil? + Dir["#{application_spec_dir}/#{load_spec_path}/*.yaml"] + else + Dir["#{@endpoints_path}/*.yaml"] + end end def endpoints From d72396d11c8390c3df2a4e844dcc82f0ed98dc15 Mon Sep 17 00:00:00 2001 From: Alex Tucker Date: Fri, 4 Oct 2024 16:54:20 +0100 Subject: [PATCH 02/18] Allow tests to run in IntelliJ --- test/test_helper.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 7b59187..2b563e2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -36,7 +36,9 @@ config.default_cassette_options = default_cassette_options end -Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(color: true)] +unless ENV['RM_INFO'] + Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(color: true)] +end # Helper to get the test API port number from the environment, or return a default def sapi_api_port From 5c66065f5467b7bd32d3cad107752d4ba281aec5 Mon Sep 17 00:00:00 2001 From: Alex Tucker Date: Fri, 4 Oct 2024 16:55:25 +0100 Subject: [PATCH 03/18] Test passing either application.yaml or endpointSpecs directory. --- test/sapi_client/application_test.rb | 151 ++++++++++++----------- test/sapi_client/endpoint_values_test.rb | 29 +++-- test/sapi_client/regressions_test.rb | 23 ++-- 3 files changed, 112 insertions(+), 91 deletions(-) diff --git a/test/sapi_client/application_test.rb b/test/sapi_client/application_test.rb index 450096a..8a7088c 100644 --- a/test/sapi_client/application_test.rb +++ b/test/sapi_client/application_test.rb @@ -6,90 +6,97 @@ module SapiClient class ApplicationTest < Minitest::Test describe 'Application' do - let(:spec) { 'test/fixtures/unified-view/application.yaml' } - let(:base_url) { "http://localhost:#{sapi_api_port}" } + [ + 'test/fixtures/unified-view/application.yaml', + 'test/fixtures/unified-view/endpointSpecs' + ].each do |spec_file_or_dir | + let(:spec) { spec_file_or_dir } + let(:base_url) { "http://localhost:#{sapi_api_port}" } - describe '#initialize' do - it 'should load the application specification given' do - app = SapiClient::Application.new(base_url, spec) - _(app.specification).must_be_kind_of Hash - end - - it 'should raise an error if the spec file does not exist' do - _( - -> { SapiClient::Application.new(base_url, 'wimbledon/wombles.yaml') } - ).must_raise(SapiError) - end - - it 'should store the base URL' do - app = SapiClient::Application.new(base_url, spec) - _(app.base_url).must_equal base_url - end - end + describe "with #{spec_file_or_dir}" do + describe '#initialize' do + it 'should load the application specification given' do + app = SapiClient::Application.new(base_url, spec) + _(app.specification).must_be_kind_of Hash + end - describe '#configuration' do - it 'should report the application configuration' do - app = SapiClient::Application.new(base_url, spec) - _(app.configuration).must_be_kind_of Hash - assert app.configuration.key?('loadSpecPath') - end - end + it 'should raise an error if the spec file does not exist' do + _( + -> { SapiClient::Application.new(base_url, 'wimbledon/wombles.yaml') } + ).must_raise(SapiError) + end - describe '#endpoint_group_files' do - it 'should return the names of all of the endpoint specification files' do - app = SapiClient::Application.new(base_url, spec) - file_names = app.endpoint_group_files - _(file_names.length).must_be :>, 5 - _(file_names).must_include('test/fixtures/unified-view/endpointSpecs/establishment.yaml') - end - end + it 'should store the base URL' do + app = SapiClient::Application.new(base_url, spec) + _(app.base_url).must_equal base_url + end + end - describe '#endpoints' do - it 'should return a list of all of the endpoint specification objects' do - app = SapiClient::Application.new(base_url, spec) - eps = app.endpoints - _(eps).must_be_kind_of Array - _(eps.length).must_be :>, 5 + describe '#configuration' do + it 'should report the application configuration' do + app = SapiClient::Application.new(base_url, spec) + _(app.configuration).must_be_kind_of Hash + assert app.configuration.key?('loadSpecPath') + end + end - _(eps.map(&:raw_path)).must_include '/business/id/establishment' - end - end + describe '#endpoint_group_files' do + it 'should return the names of all of the endpoint specification files' do + app = SapiClient::Application.new(base_url, spec) + file_names = app.endpoint_group_files + _(file_names.length).must_be :>, 5 + _(file_names).must_include('test/fixtures/unified-view/endpointSpecs/establishment.yaml') + end + end - describe '#instance' do - it 'should create an instance with methods corresponding to endpoints' do - app = SapiClient::Application.new(base_url, spec) - inst = app.instance - methods = inst.public_methods - _(methods).must_include(:establishment_list) - _(methods).must_include(:establishment_list_spec) - end + describe '#endpoints' do + it 'should return a list of all of the endpoint specification objects' do + app = SapiClient::Application.new(base_url, spec) + eps = app.endpoints + _(eps).must_be_kind_of Array + _(eps.length).must_be :>, 5 - it 'should wrap a list of instances' do - class ::Establishment # rubocop:disable Lint/ConstantDefinitionInBlock - def initialize(_json) - @invoked = true + _(eps.map(&:raw_path)).must_include '/business/id/establishment' end - attr_reader :invoked end - app = SapiClient::Application.new(base_url, spec) - inst = app.instance + describe '#instance' do + it 'should create an instance with methods corresponding to endpoints' do + app = SapiClient::Application.new(base_url, spec) + inst = app.instance + methods = inst.public_methods + _(methods).must_include(:establishment_list) + _(methods).must_include(:establishment_list_spec) + end - VCR.use_cassette('application.test_instance_wrapping') do - establishments = inst.establishment_list(_limit: 1) - _(establishments.first).must_be_kind_of(Establishment) - assert establishments.first.invoked - end - end + it 'should wrap a list of instances' do + class ::Establishment # rubocop:disable Lint/ConstantDefinitionInBlock + def initialize(_json) + @invoked = true + end + attr_reader :invoked + end + + app = SapiClient::Application.new(base_url, spec) + inst = app.instance - it 'should retrieve a hierarchy' do - VCR.use_cassette('application.test_hierarchy') do - app = SapiClient::Application.new( - 'http://fsa-rp-test.epimorphics.net', - 'test/fixtures/regulated-products/application.yaml' - ) - hierarchy = app.instance.feed_category_hierarchy_hierarchy({}, :skos) - _(hierarchy.roots.size).must_equal(5) + VCR.use_cassette('application.test_instance_wrapping') do + establishments = inst.establishment_list(_limit: 1) + _(establishments.first).must_be_kind_of(Establishment) + assert establishments.first.invoked + end + end + + it 'should retrieve a hierarchy' do + VCR.use_cassette('application.test_hierarchy') do + app = SapiClient::Application.new( + 'http://fsa-rp-test.epimorphics.net', + 'test/fixtures/regulated-products/application.yaml' + ) + hierarchy = app.instance.feed_category_hierarchy_hierarchy({}, :skos) + _(hierarchy.roots.size).must_equal(5) + end + end end end end diff --git a/test/sapi_client/endpoint_values_test.rb b/test/sapi_client/endpoint_values_test.rb index 5d394e3..5ae5a31 100644 --- a/test/sapi_client/endpoint_values_test.rb +++ b/test/sapi_client/endpoint_values_test.rb @@ -46,19 +46,26 @@ class EndpointValuesTest < Minitest::Test end describe '#to_a' do - let(:spec) { 'test/fixtures/unified-view/application.yaml' } - let(:base_url) { "http://localhost:#{sapi_api_port}" } + [ + 'test/fixtures/unified-view/application.yaml', + 'test/fixtures/unified-view/endpointSpecs' + ].each do |spec_file_or_dir| + let(:spec) { 'test/fixtures/unified-view/application.yaml' } + let(:base_url) { "http://localhost:#{sapi_api_port}" } - it 'should invoke the endpoint with the parameters' do - app = SapiClient::Application.new(base_url, spec) - inst = app.instance + describe "#with #{spec_file_or_dir}" do + it 'should invoke the endpoint with the parameters' do + app = SapiClient::Application.new(base_url, spec) + inst = app.instance - VCR.use_cassette('endpoint_values.test_to_a') do - evs = SapiClient::EndpointValues.new(inst, :establishment_list) - evs.limit(1) - establishments = evs.to_a - _(establishments).must_be_kind_of(Array) - _(establishments.length).must_equal(1) + VCR.use_cassette('endpoint_values.test_to_a') do + evs = SapiClient::EndpointValues.new(inst, :establishment_list) + evs.limit(1) + establishments = evs.to_a + _(establishments).must_be_kind_of(Array) + _(establishments.length).must_equal(1) + end + end end end end diff --git a/test/sapi_client/regressions_test.rb b/test/sapi_client/regressions_test.rb index baefa32..cc8f5fd 100644 --- a/test/sapi_client/regressions_test.rb +++ b/test/sapi_client/regressions_test.rb @@ -7,17 +7,24 @@ module SapiClient class RegressionsTest < Minitest::Test describe 'Regression tests' do describe 'https://github.com/epimorphics/sapi-client-ruby/issues/44' do - let(:spec) { 'test/fixtures/cbd_api/application.yaml' } - let(:base_url) { 'https://fsa-cbd-test.epimorphics.net' } + [ + 'test/fixtures/cbd_api/application.yaml', + 'test/fixtures/cbd_api/endpointSpecs' + ].each do |spec_file_or_dir| + describe "#with {spec_file_or_dir}" do + let(:spec) { 'test/fixtures/cbd_api/application.yaml' } + let(:base_url) { 'https://fsa-cbd-test.epimorphics.net' } - it 'should return a list containing SapiResource items' do - app = SapiClient::Application.new(base_url, spec) - inst = app.instance + it 'should return a list containing SapiResource items' do + app = SapiClient::Application.new(base_url, spec) + inst = app.instance - VCR.use_cassette('regression_tests.issue-44') do - listings = inst.listing_list(_limit: 1) + VCR.use_cassette('regression_tests.issue-44') do + listings = inst.listing_list(_limit: 1) - _(listings.first).must_be_kind_of SapiClient::SapiResource + _(listings.first).must_be_kind_of SapiClient::SapiResource + end + end end end end From 6fffedd6924ebf8c78a2960eec83fbc3d6a615d3 Mon Sep 17 00:00:00 2001 From: Alex Tucker Date: Fri, 4 Oct 2024 16:58:16 +0100 Subject: [PATCH 04/18] Bump minor version --- lib/sapi_client/version.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sapi_client/version.rb b/lib/sapi_client/version.rb index 3b7e17c..2bb4d1a 100644 --- a/lib/sapi_client/version.rb +++ b/lib/sapi_client/version.rb @@ -2,7 +2,7 @@ module SapiClient MAJOR = 1 - MINOR = 1 - FIX = 3 + MINOR = 2 + FIX = 0 VERSION = "#{MAJOR}.#{MINOR}.#{FIX}" end From ea7d75f6287ffb91ef412bd02b15b4fdd3a98dc8 Mon Sep 17 00:00:00 2001 From: Alex Tucker Date: Fri, 4 Oct 2024 16:58:49 +0100 Subject: [PATCH 05/18] bundle install makes minor updates --- Gemfile.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5c304dd..f3925db 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - sapi-client-ruby (1.1.3) + sapi-client-ruby (1.2.0) faraday_middleware (~> 1.0.0) i18n (~> 1.5) @@ -12,9 +12,9 @@ GEM ast (2.4.2) builder (3.2.4) byebug (11.1.3) - concurrent-ruby (1.3.1) + concurrent-ruby (1.3.4) docile (1.4.0) - faraday (1.10.3) + faraday (1.10.4) faraday-em_http (~> 1.0) faraday-em_synchrony (~> 1.0) faraday-excon (~> 1.1) @@ -32,14 +32,14 @@ GEM faraday-httpclient (1.0.1) faraday-multipart (1.0.4) multipart-post (~> 2) - faraday-net_http (1.0.1) + faraday-net_http (1.0.2) faraday-net_http_persistent (1.2.0) faraday-patron (1.0.0) faraday-rack (1.0.0) faraday-retry (1.0.3) faraday_middleware (1.0.0) faraday (~> 1.0) - i18n (1.14.5) + i18n (1.14.6) concurrent-ruby (~> 1.0) minitest (5.15.0) minitest-reporters (1.5.0) From fac3c6b2bada9707549d754bac636d39486088f4 Mon Sep 17 00:00:00 2001 From: Alex Tucker Date: Fri, 4 Oct 2024 17:19:53 +0100 Subject: [PATCH 06/18] Fix lints and missing string interpolation that rubocop misdiagnosed. --- test/sapi_client/application_test.rb | 2 +- test/sapi_client/regressions_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/sapi_client/application_test.rb b/test/sapi_client/application_test.rb index 8a7088c..31e9f75 100644 --- a/test/sapi_client/application_test.rb +++ b/test/sapi_client/application_test.rb @@ -9,7 +9,7 @@ class ApplicationTest < Minitest::Test [ 'test/fixtures/unified-view/application.yaml', 'test/fixtures/unified-view/endpointSpecs' - ].each do |spec_file_or_dir | + ].each do |spec_file_or_dir| let(:spec) { spec_file_or_dir } let(:base_url) { "http://localhost:#{sapi_api_port}" } diff --git a/test/sapi_client/regressions_test.rb b/test/sapi_client/regressions_test.rb index cc8f5fd..82bcdf0 100644 --- a/test/sapi_client/regressions_test.rb +++ b/test/sapi_client/regressions_test.rb @@ -11,7 +11,7 @@ class RegressionsTest < Minitest::Test 'test/fixtures/cbd_api/application.yaml', 'test/fixtures/cbd_api/endpointSpecs' ].each do |spec_file_or_dir| - describe "#with {spec_file_or_dir}" do + describe "#with #{spec_file_or_dir}" do let(:spec) { 'test/fixtures/cbd_api/application.yaml' } let(:base_url) { 'https://fsa-cbd-test.epimorphics.net' } From bc4f79adfcaced10e625245abbaba2202230c329 Mon Sep 17 00:00:00 2001 From: Alex Tucker Date: Fri, 4 Oct 2024 17:20:58 +0100 Subject: [PATCH 07/18] Ensure instance vars are nil if not used. --- lib/sapi_client/application.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sapi_client/application.rb b/lib/sapi_client/application.rb index 2c2aead..3c5c3aa 100644 --- a/lib/sapi_client/application.rb +++ b/lib/sapi_client/application.rb @@ -11,8 +11,8 @@ def initialize(base_url, application_or_endpoints) end @base_url = base_url - @application_spec_file = application_or_endpoints if File.file?(application_or_endpoints) - @endpoints_path = application_or_endpoints if File.directory?(application_or_endpoints) + @application_spec_file = File.file?(application_or_endpoints) ? application_or_endpoints : nil + @endpoints_path = File.directory?(application_or_endpoints) ? application_or_endpoints : nil @specification = (@application_spec_file && YAML.load_file(application_or_endpoints)) || { 'sapi-nt' => { 'config' => { 'loadSpecPath' => 'classpath:endpointSpecs' } } } From 1121e0f34aea5ea9f6e3ce754eb0ab301565f197 Mon Sep 17 00:00:00 2001 From: Alex Tucker Date: Sun, 6 Oct 2024 11:22:34 +0100 Subject: [PATCH 08/18] Remove some space chars. --- lib/sapi_client/application.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sapi_client/application.rb b/lib/sapi_client/application.rb index 3c5c3aa..66772b1 100644 --- a/lib/sapi_client/application.rb +++ b/lib/sapi_client/application.rb @@ -11,8 +11,8 @@ def initialize(base_url, application_or_endpoints) end @base_url = base_url - @application_spec_file = File.file?(application_or_endpoints) ? application_or_endpoints : nil - @endpoints_path = File.directory?(application_or_endpoints) ? application_or_endpoints : nil + @application_spec_file = File.file?(application_or_endpoints) ? application_or_endpoints : nil + @endpoints_path = File.directory?(application_or_endpoints) ? application_or_endpoints : nil @specification = (@application_spec_file && YAML.load_file(application_or_endpoints)) || { 'sapi-nt' => { 'config' => { 'loadSpecPath' => 'classpath:endpointSpecs' } } } From 10f0cad90f73713c7c3cf46c6f8cfe4f1506a094 Mon Sep 17 00:00:00 2001 From: Alex Tucker Date: Mon, 7 Oct 2024 10:12:53 +0100 Subject: [PATCH 09/18] Update error message. --- lib/sapi_client/application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sapi_client/application.rb b/lib/sapi_client/application.rb index 66772b1..f9b62f1 100644 --- a/lib/sapi_client/application.rb +++ b/lib/sapi_client/application.rb @@ -7,7 +7,7 @@ module SapiClient class Application def initialize(base_url, application_or_endpoints) unless File.exist?(application_or_endpoints) - raise(SapiError, "Could not find application spec #{application_or_endpoints}") + raise(SapiError, "Could not find spec file/directory #{application_or_endpoints}") end @base_url = base_url From 3d29797446253bb27fb232c97ace5c2d7bdfa60c Mon Sep 17 00:00:00 2001 From: Alex Tucker Date: Mon, 7 Oct 2024 10:13:26 +0100 Subject: [PATCH 10/18] Update wording in cli app. --- exe/sapi | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/exe/sapi b/exe/sapi index b6c0182..e6fc03e 100755 --- a/exe/sapi +++ b/exe/sapi @@ -7,12 +7,12 @@ require 'sapi_client' options = { base: ENV['SAPI_BASE_URL'], - spec: ENV['SAPI_SPEC_FILE'] + spec: ENV['SAPI_SPEC_FILE'] || ENV['SAPI_SPEC'] } -def spec_file(options) +def spec_file_or_dir(options) unless File.exist?(options[:spec]) - puts "Could not find spec file #{options[:spec]}" + puts "Could not find spec file/directory #{options[:spec]}" exit(1) end @@ -22,13 +22,13 @@ end def usage <<~USAGE Usage: - sapi [-b SAPI_BASE_URL] [-s SAPI_SPEC_FILE] inspect - sapi [-b SAPI_BASE_URL] [-s SAPI_SPEC_FILE] + sapi [-b SAPI_BASE_URL] [-s SAPI_SPEC] inspect + sapi [-b SAPI_BASE_URL] [-s SAPI_SPEC] Full list of options: sapi -h - Base URL and spec file can also be set as environment variables. + Base URL and spec file/dir can also be set as environment variables. v#{SapiClient::VERSION} USAGE @@ -49,7 +49,7 @@ end def sapi_application(options) SapiClient::Application - .new(options.delete(:base), spec_file(options)) + .new(options.delete(:base), spec_file_or_dir(options)) end def inspect_sapi(options) @@ -90,7 +90,8 @@ OptionParser.new do |parser| options[:base] = url end - parser.on('-s', '--spec-file SAPI_SPEC_FILE', 'The location of the specification file') do |file_name| + parser.on('-s', '--spec-file SAPI_SPEC', + 'The directory with specification files, or location of sapi-nt application.yaml') do |file_name| options[:spec] = file_name end From d3a7982a72e0f250cc05047e89164b4df606dcf9 Mon Sep 17 00:00:00 2001 From: Alex Tucker Date: Mon, 7 Oct 2024 10:13:55 +0100 Subject: [PATCH 11/18] bundle update --- Gemfile.lock | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index f3925db..452e5ce 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,10 +10,10 @@ GEM specs: ansi (1.5.0) ast (2.4.2) - builder (3.2.4) + builder (3.3.0) byebug (11.1.3) concurrent-ruby (1.3.4) - docile (1.4.0) + docile (1.4.1) faraday (1.10.4) faraday-em_http (~> 1.0) faraday-em_synchrony (~> 1.0) @@ -41,7 +41,7 @@ GEM faraday (~> 1.0) i18n (1.14.6) concurrent-ruby (~> 1.0) - minitest (5.15.0) + minitest (5.25.1) minitest-reporters (1.5.0) ansi builder @@ -49,15 +49,16 @@ GEM ruby-progressbar mocha (1.13.0) multipart-post (2.4.1) - parallel (1.21.0) - parser (3.1.1.0) + parallel (1.26.3) + parser (3.3.5.0) ast (~> 2.4.1) + racc + racc (1.8.1) rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.2.1) - rexml (3.2.8) - strscan (>= 3.0.9) - rubocop (1.26.0) + regexp_parser (2.9.2) + rexml (3.3.8) + rubocop (1.26.1) parallel (~> 1.10) parser (>= 3.1.0.0) rainbow (>= 2.2.2, < 4.0) @@ -66,18 +67,17 @@ GEM rubocop-ast (>= 1.16.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.16.0) - parser (>= 3.1.1.0) - ruby-progressbar (1.11.0) + rubocop-ast (1.32.3) + parser (>= 3.3.1.0) + ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) simplecov (0.21.2) docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) - simplecov-html (0.12.3) + simplecov-html (0.13.1) simplecov_json_formatter (0.1.4) - strscan (3.1.0) - unicode-display_width (2.1.0) + unicode-display_width (2.6.0) vcr (6.0.0) PLATFORMS From 26b7ef1ca41f8910fe5c4c7cfa255e86ee1b9b5e Mon Sep 17 00:00:00 2001 From: Alex Tucker Date: Mon, 7 Oct 2024 10:14:21 +0100 Subject: [PATCH 12/18] Add CHANGELOG entry --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ccbf6e..557788e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes will be documented in this file. +## 1.2.0 - 2024-10-06 + +- (AlexT) allow passing endpoint specifications directory in initializer + Bump deps including minitest 5.15.0 -> 5.25.1 and rexml 3.2.8 -> 3.3.8. + ## 1.1.3 - 2024-06-03 - (AlexT) require 'ostruct' to fix tests in Ruby 3.3.1. Use Matrix tests to check From 218ccd1e1fc292678d06806ab30eda8866f0de50 Mon Sep 17 00:00:00 2001 From: Alex Tucker Date: Mon, 7 Oct 2024 10:15:54 +0100 Subject: [PATCH 13/18] Update README and add note on model spec files. --- README.md | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9db3921..f27c923 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ modelspec for the API, which is used to generate a custom API class using Ruby metaprogramming _N.B. This respository's primary branch name has been updated, please see the -[#important](#important) section below for more information._ +[Main branch](#main-branch) section below for more information._ ## Usage @@ -19,7 +19,7 @@ application's `Gemfile`: ```ruby source "https://rubygems.pkg.github.com/epimorphics" do - gem "sapi-client-ruby", "~> 1.0.0" + gem "sapi-client-ruby", "~> 1.2.0" end ``` @@ -51,16 +51,22 @@ about creating a PAT. To aid debugging and exploring a Sapi-NT endpoint, this library has a command-line tool `sapi`. As required inputs, the tool needs both the base URL for the Sapi-NT API instance (e.g. `http://localhost:8080`), and the location of -the Sapi-NT configuration root file. These can either be passed as command-line -arguments, or as environment variables: +the Sapi-NT modelspec files (see [Modelspec files](#modelspec-files) below). +These can either be passed as command-line arguments, or as environment variables: ```sh sapi -b http://localhost:8080 -s test/fixtures/unified-view/application.yaml inspect - +``` +or +```sh export SAPI_BASE_URL=http://localhost:8080 export SAPI_SPEC_FILE=test/fixtures/unified-view/application.yaml sapi inspect ``` +or, using the endpoint specs directory +```sh +sapi -b http://localhost:8080 -s test/fixtures/unified-view/endpointSpecs inspect +``` See `sapi --help` for more details. @@ -241,7 +247,9 @@ $ sapi establishment_item MBTM1R-A8K4VZ-2FJCYJ -j ### Using Sapi-client from code Create a new instance of the `SapiClient::Application`, initialised with the -base URL and the location of the root YAML file for the application: +base URL and either the location of the root YAML file for the application, or +the directory containing the endpoint specification YAML files (see [Modelspec +files](#modelspec-files) below). ```ruby irb(main):001:0> app = SapiClient::Application.new('http://localhost:8080', 'test/fixtures/unified-view/application.yaml') @@ -286,7 +294,7 @@ resources. To associate the values of an endpoint with a facade class, there are a number of options: -- a class may be be passed via the `wrapper` option when invoking an API +- a class may be passed via the `wrapper` option when invoking an API endpoint method. E.g: `myEndpoint.establishment_list(_limit: 1, wrapper: MyClass)` - if no explicit `wrapper option is available`, the endpoint will look for a @@ -349,7 +357,22 @@ The events emitted are: ## Developer notes -### Important +### Modelspec files + +Both `sapi-nt` and `sapi-client-ruby` are configured using a set of "modelspec" +files that detail the endpoint URL templates, arguments and responses of a given +API. + +`sapi-nt` uses an `application.yaml` configuration file that, amongst other things, +points to the location of the directory of these modelspec (YAML) files, although +often these are resources in a JAR file, so use Java's classpath machinery. + +As a step away from too closely coupling `sapi-nt` and `sapi-client-ruby`, we now +additionally allow initialization of the `SapiClient::Application` using the +location of the directory containing the modelspec files, usually called +`endpointSpecs`. + +### Main branch If you have already cloned the repository to your local instance, you will need to run the following commands to update the primary branch name: From 88399d91191280508b7ace87670f59c3aaff9f73 Mon Sep 17 00:00:00 2001 From: Alex Tucker Date: Mon, 7 Oct 2024 10:35:35 +0100 Subject: [PATCH 14/18] Revert "Allow tests to run in IntelliJ" This reverts commit d72396d11c8390c3df2a4e844dcc82f0ed98dc15. --- test/test_helper.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 2b563e2..7b59187 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -36,9 +36,7 @@ config.default_cassette_options = default_cassette_options end -unless ENV['RM_INFO'] - Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(color: true)] -end +Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(color: true)] # Helper to get the test API port number from the environment, or return a default def sapi_api_port From ec284894b788f191f495ae591a5a0ee5472a6da6 Mon Sep 17 00:00:00 2001 From: Alex Tucker Date: Mon, 7 Oct 2024 11:08:29 +0100 Subject: [PATCH 15/18] Allow mocha updates to get to 2.4.5 to get over incompatibilities with newer minitest. --- CHANGELOG.md | 3 ++- Gemfile.lock | 11 ++++++----- sapi-client-ruby.gemspec | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 557788e..99e43d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,8 @@ All notable changes will be documented in this file. ## 1.2.0 - 2024-10-06 - (AlexT) allow passing endpoint specifications directory in initializer - Bump deps including minitest 5.15.0 -> 5.25.1 and rexml 3.2.8 -> 3.3.8. + Bump deps including minitest 5.15.0 -> 5.25.1, mocha 1.13.0 -> 2.4.5 and + rexml 3.2.8 -> 3.3.8. ## 1.1.3 - 2024-06-03 diff --git a/Gemfile.lock b/Gemfile.lock index 452e5ce..cfa7c9c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,12 +42,13 @@ GEM i18n (1.14.6) concurrent-ruby (~> 1.0) minitest (5.25.1) - minitest-reporters (1.5.0) + minitest-reporters (1.7.1) ansi builder minitest (>= 5.0) ruby-progressbar - mocha (1.13.0) + mocha (2.4.5) + ruby2_keywords (>= 0.0.5) multipart-post (2.4.1) parallel (1.26.3) parser (3.3.5.0) @@ -86,9 +87,9 @@ PLATFORMS DEPENDENCIES bundler (~> 2.1.4) byebug (~> 11.1.3) - minitest (~> 5.0) - minitest-reporters (~> 1.5.0) - mocha (~> 1.13.0) + minitest (~> 5.25) + minitest-reporters (~> 1.7) + mocha (~> 2.4) rake (~> 13.0.1) rubocop (~> 1.26.0) sapi-client-ruby! diff --git a/sapi-client-ruby.gemspec b/sapi-client-ruby.gemspec index 3665fa8..4844c02 100644 --- a/sapi-client-ruby.gemspec +++ b/sapi-client-ruby.gemspec @@ -36,9 +36,9 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'bundler', '~> 2.1.4' spec.add_development_dependency 'byebug', '~> 11.1.3' - spec.add_development_dependency 'minitest', '~> 5.0' - spec.add_development_dependency 'minitest-reporters', '~> 1.5.0' - spec.add_development_dependency 'mocha', '~> 1.13.0' + spec.add_development_dependency 'minitest', '~> 5.25' + spec.add_development_dependency 'minitest-reporters', '~> 1.7' + spec.add_development_dependency 'mocha', '~> 2.4' spec.add_development_dependency 'rake', '~> 13.0.1' spec.add_development_dependency 'rubocop', '~> 1.26.0' spec.add_development_dependency 'simplecov', '~> 0.21.1' From 55c29e9cedb8e53176427edcb6891b4d6674f4d0 Mon Sep 17 00:00:00 2001 From: Alex Tucker Date: Mon, 7 Oct 2024 14:00:33 +0100 Subject: [PATCH 16/18] Relax version constraints in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f27c923..8408368 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ application's `Gemfile`: ```ruby source "https://rubygems.pkg.github.com/epimorphics" do - gem "sapi-client-ruby", "~> 1.2.0" + gem "sapi-client-ruby", "~> 1.2" end ``` From a807e8d3c8c513c709c6b303db3750cb8f40013e Mon Sep 17 00:00:00 2001 From: Alex Tucker Date: Tue, 8 Oct 2024 10:13:17 +0100 Subject: [PATCH 17/18] Reapply "Allow tests to run in IntelliJ" This reverts commit 88399d91191280508b7ace87670f59c3aaff9f73. --- test/test_helper.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 7b59187..2b563e2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -36,7 +36,9 @@ config.default_cassette_options = default_cassette_options end -Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(color: true)] +unless ENV['RM_INFO'] + Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(color: true)] +end # Helper to get the test API port number from the environment, or return a default def sapi_api_port From 5dd006a297b96c1992a382a2d616f1200dfb05ca Mon Sep 17 00:00:00 2001 From: Alex Tucker Date: Tue, 8 Oct 2024 10:17:11 +0100 Subject: [PATCH 18/18] Merge in changes from 1.1.4 --- CHANGELOG.md | 2 +- Gemfile.lock | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bda8821..b68ac0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes will be documented in this file. - (AlexT) allow passing endpoint specifications directory in initializer Bump deps including minitest 5.15.0 -> 5.25.1, mocha 1.13.0 -> 2.4.5 and - rexml 3.2.8 -> 3.3.8. + minitest-reporters 1.5.0 -> 1.7.1. ## 1.1.4 - 2024-10-08 diff --git a/Gemfile.lock b/Gemfile.lock index 3338a5a..84bef53 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - sapi-client-ruby (1.1.4) + sapi-client-ruby (1.2.0) faraday_middleware (~> 1.0.0) i18n (~> 1.5) @@ -10,7 +10,7 @@ GEM specs: ansi (1.5.0) ast (2.4.2) - builder (3.2.4) + builder (3.3.0) byebug (11.1.3) concurrent-ruby (1.3.4) docile (1.4.0) @@ -41,13 +41,14 @@ GEM faraday (~> 1.0) i18n (1.14.6) concurrent-ruby (~> 1.0) - minitest (5.15.0) - minitest-reporters (1.5.0) + minitest (5.25.1) + minitest-reporters (1.7.1) ansi builder minitest (>= 5.0) ruby-progressbar - mocha (1.13.0) + mocha (2.4.5) + ruby2_keywords (>= 0.0.5) multipart-post (2.4.1) parallel (1.21.0) parser (3.1.1.0) @@ -86,9 +87,9 @@ PLATFORMS DEPENDENCIES bundler (~> 2.1.4) byebug (~> 11.1.3) - minitest (~> 5.0) - minitest-reporters (~> 1.5.0) - mocha (~> 1.13.0) + minitest (~> 5.25) + minitest-reporters (~> 1.7) + mocha (~> 2.4) rake (~> 13.0.1) rubocop (~> 1.26.0) sapi-client-ruby!