From d2bc4d68613cf493315f7ae875d9bf942ac3ad14 Mon Sep 17 00:00:00 2001 From: MarioRuiz Date: Tue, 21 Apr 2026 11:50:06 +0000 Subject: [PATCH] fix: require fileutils for OpenApiImport.from (v0.12.1) Avoid uninitialized constant when the gem is required without another stdlib dependency loading FileUtils first. Bump to 0.12.1 and add a regression spec. Made-with: Cursor --- CHANGELOG.md | 5 +++++ lib/open_api_import.rb | 2 ++ lib/open_api_import/open_api_import.rb | 4 ++-- open_api_import.gemspec | 2 +- spec/open_api_import/fileutils_require_spec.rb | 9 +++++++++ 5 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 spec/open_api_import/fileutils_require_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e9b0c8..575b89a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.12.1] - 2026-03-24 + +### Fixed +- Require `fileutils` from the gem entrypoint and call `::FileUtils.rm_f` so `OpenApiImport.from` does not raise `uninitialized constant OpenApiImport::FileUtils` when nothing else has loaded the stdlib first + ## [0.12.0] - 2026-03-17 ### Added diff --git a/lib/open_api_import.rb b/lib/open_api_import.rb index d880697..3aa7df5 100644 --- a/lib/open_api_import.rb +++ b/lib/open_api_import.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "fileutils" + require_relative "open_api_import/utils" require_relative "open_api_import/filter" require_relative "open_api_import/pretty_hash_symbolized" diff --git a/lib/open_api_import/open_api_import.rb b/lib/open_api_import/open_api_import.rb index 5f39bba..07cef76 100644 --- a/lib/open_api_import/open_api_import.rb +++ b/lib/open_api_import/open_api_import.rb @@ -5,7 +5,7 @@ class OpenApiImport class ParseError < StandardError; end - VERSION = "0.12.0" + VERSION = "0.12.1" extend LibOpenApiImport @@ -53,7 +53,7 @@ def self.from(swagger_file, create_method_name: :operation_id, include_responses end file_errors = "#{file_to_convert}.errors.log" - FileUtils.rm_f(file_errors) + ::FileUtils.rm_f(file_errors) import_errors = "" required_constants = [] diff --git a/open_api_import.gemspec b/open_api_import.gemspec index 1502e7e..1059b1d 100644 --- a/open_api_import.gemspec +++ b/open_api_import.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |s| s.name = "open_api_import" - s.version = "0.12.0" + s.version = "0.12.1" s.summary = "OpenApiImport -- Import a Swagger or Open API file and create a Ruby Request Hash file including all requests and responses with all the examples. The file can be in JSON or YAML" s.description = "OpenApiImport -- Import a Swagger or Open API file and create a Ruby Request Hash file including all requests and responses with all the examples. The file can be in JSON or YAML" s.authors = ["Mario Ruiz"] diff --git a/spec/open_api_import/fileutils_require_spec.rb b/spec/open_api_import/fileutils_require_spec.rb new file mode 100644 index 0000000..8502606 --- /dev/null +++ b/spec/open_api_import/fileutils_require_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require "open_api_import" + +RSpec.describe "OpenApiImport stdlib dependencies" do + it "loads FileUtils when requiring the gem (regression for OpenApiImport.from)" do + expect(defined?(FileUtils)).to eq("constant") + end +end