Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Fixed missing agent write tools on installs from the published gems (#15038)
Damian Legawiec88d063ea6f0a
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex da25a201fe..06891ae202 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -61,6 +61,13 @@ jobs:- name: Configure RubyGems credentialsuses: rubygems/configure-rubygems-credentials@main+ # The agent tools read the API references at runtime, and docs/ is+ # outside every gem.+ - name: Pack the API references into spree_api+ run: |+ mkdir -p spree/api/openapi+ cp docs/api-reference/admin.yaml docs/api-reference/store.yaml spree/api/openapi/+- name: Build and push gems to RubyGemsworking-directory: spreerun: bundle exec rake gem:releasediff --git a/spree/api/.gitignore b/spree/api/.gitignoreindex d87d4be66f..5f318cfb16 100644--- a/spree/api/.gitignore+++ b/spree/api/.gitignore@@ -15,3 +15,4 @@ spec/reportstest/tmptest/version_tmptmp+/openapi/diff --git a/spree/api/lib/spree/api/agent_workflow_endpoints.rb b/spree/api/lib/spree/api/agent_workflow_endpoints.rbindex 9561ac5c64..562a28adb6 100644--- a/spree/api/lib/spree/api/agent_workflow_endpoints.rb+++ b/spree/api/lib/spree/api/agent_workflow_endpoints.rb@@ -95,8 +95,8 @@ module Spreepath.gsub(/:([a-z_]+)/) { "{#{Regexp.last_match(1)}}" }end- # A packaged installation has no docs/ directory, and a body the- # document does not describe is simply passed through unchecked.+ # A body the document does not describe is simply passed through+ # unchecked.## `AgentWriteSchemas` already holds this file parsed, so it is read# through there rather than a second time: the document is nearly adiff --git a/spree/api/lib/spree/api/agent_write_schemas.rb b/spree/api/lib/spree/api/agent_write_schemas.rbindex 107cd4ce90..47097648f7 100644--- a/spree/api/lib/spree/api/agent_write_schemas.rb+++ b/spree/api/lib/spree/api/agent_write_schemas.rb@@ -33,12 +33,14 @@ module Spreeself.for(key).keysend- # Where the generated document lives, relative to this engine. Resolved- # lazily: the engine class does not exist yet while this file loads.+ # Where the generated document lives: `docs/` in a source checkout,+ # or the copy the release packs into the gem. Resolved lazily: the+ # engine class does not exist yet while this file loads.## @return [Pathname]def spec_path- Spree::Api::Engine.root.join('..', '..', 'docs', 'api-reference', 'admin.yaml')+ source = Spree::Api::Engine.root.join('..', '..', 'docs', 'api-reference', 'admin.yaml')+ source.exist? ? source : Spree::Api::Engine.root.join('openapi', 'admin.yaml')end# The parsed document, for a reader that needs more of it than the@@ -63,9 +65,7 @@ module Spreeend# A missing or unparseable document is not a boot failure: the generic- # write tools simply offer nothing, which is the safe direction. An- # installation running from the packaged gems has no docs/ directory at- # all.+ # write tools simply offer nothing, which is the safe direction.def load_schemaspath = spec_pathreturn {} unless File.exist?(path)diff --git a/spree/api/spec/lib/spree/api/agent_write_schemas_spec.rb b/spree/api/spec/lib/spree/api/agent_write_schemas_spec.rbnew file mode 100644index 0000000000..1ead4a6dd6--- /dev/null+++ b/spree/api/spec/lib/spree/api/agent_write_schemas_spec.rb@@ -0,0 +1,18 @@+require 'spec_helper'++RSpec.describe Spree::Api::AgentWriteSchemas do+ # The published gems carry no docs/ directory; the release packs the+ # reference into the gem's openapi/ instead.+ it 'reads the reference packed into the gem when there is no source checkout' do+ Dir.mktmpdir do |dir|+ gem_root = Pathname(dir).join('gems', 'spree_api')+ allow(Spree::Api::Engine).to receive(:root).and_return(gem_root)++ expect(described_class.spec_path).to eq(gem_root.join('openapi', 'admin.yaml'))+ end+ end++ it 'prefers docs/ in a source checkout' do+ expect(described_class.spec_path.to_s).to end_with('docs/api-reference/admin.yaml')+ end+enddiff --git a/spree/api/spree_api.gemspec b/spree/api/spree_api.gemspecindex f310b5c6da..182381de95 100644--- a/spree/api/spree_api.gemspec+++ b/spree/api/spree_api.gemspec@@ -19,7 +19,7 @@ Gem::Specification.new do |s|s.required_ruby_version = '>= 3.2'- s.files = Dir["{app,config,db,lib,vendor}/**/*", "Rakefile", "LICENSE", "README.md"].reject { |f| f.match(/^spec/) && !f.match(/^spec\/fixtures/) }+ s.files = Dir["{app,config,db,lib,vendor}/**/*", "openapi/*.yaml", "Rakefile", "LICENSE", "README.md"].reject { |f| f.match(/^spec/) && !f.match(/^spec\/fixtures/) }s.require_paths = ['lib']s.add_development_dependency 'rswag-specs'