ahx / openapi_first

openapi_first is a Ruby gem for request / response validation and contract-testing against an OpenAPI API description. It makes APIFirst easy and reliable.
MIT License
95 stars 11 forks source link

Error: "can't modify frozen Hash" #276

Open etobia opened 6 days ago

etobia commented 6 days ago

I'm using the example from the docs to register my OAS document for use in minitest.

However, when I call register I get a FrozenError on this line, presumably because the DEFINITIONS hash is frozen?

gems/openapi_first-2.0.2/lib/openapi_first/test.rb:14:in `register': can't modify frozen Hash: {} (FrozenError)

If I patch the OpenapiFirst::Test module the subsequent call to register works, but I wonder if I'm missing something in my setup.

  module OpenapiFirst
    module Test
      class << self
        alias original_definitions definitions

        def definitions
          @mutable_definitions ||= original_definitions.dup
        end
      end
    end
  end

Thoughts?

ahx commented 6 days ago

Hi @etobia . Thanks for the report. I don’t think your setup is wrong. The „freeze“ must have been added by my misconfigured linter by accident. And apparently this part is missing a test. I am on a trip right now, but I have hotfixed this on main. Can you see if works for you now?

etobia commented 6 days ago

Thanks for the quick response @ahx. I just tried 8c46ba7 and it appears to be working!

ahx commented 5 days ago

Great to hear, @etobia. I am on a trip until July 15th and unfortunately I won’t be able to release a new version until then. But I will once I am back.

etobia commented 5 days ago

No worries at all. Thanks again!