Ability to apply rules to external schema

@solnic I have a better example/test which is similar to my schema/rule use case. The first test fails but the second passes fine. As I was trying to debug, I realized that the fix will require a change in dry-schema due to what #key_map returns in ClassInterface.

I really like this gem and would like to help and contribute for a fix but I am not sure 100% sure what would be the best course of action. Could you give me some guidance?

  context 'when schema is nested and reused' do
    let(:contract_class) do
      Class.new(Dry::Validation::Contract) do
        def self.name
          "TestContract"
        end

        UserSchema = Dry::Schema.Params do
          required(:email).filled(:string)
          optional(:login).filled(:string)
          optional(:details).hash do
            optional(:address).hash do
              required(:street).value(:string)
            end
          end
        end

        IdentifierSchema = Dry::Schema.Params do
          required(:external_id).filled(:string)
          optional(:aternate_id).filled(:string)
        end

        UserRequestSchema = Dry::Schema.Params do
          required(:user).hash do
            IdentifierSchema
            UserSchema
          end
        end

        params(UserRequestSchema)
      end
    end

    context 'when the rule being applied to a key is in a reused nested schema' do
      let(:request) { { user: { external_id: '12345abc', email: 'jane@doe.org', login: 'ab'} }}

      before do
        contract_class.rule(user: :login) do
          key.failure("is too short") if values[user: :login].size < 3
        end
      end

      it 'applies the rule when passed schema checks' do
        expect(contract.(request).errors.to_h)
          .to eql(user: { login: ["is too short"] })
      end
    end

    context 'when schema has no rules' do
      let(:request) { { user: { external_id: '12345abc', email: 'jane@doe.org' } } }

      it 'validates as successful' do
        expect(contract.(request).success?).to eq true
      end
    end
  end