Sha256: 9ed3ed13135bab7b7deaf56baf804ccff9c44539bff144458930416c79fd0406

Contents?: true

Size: 1.11 KB

Versions: 8

Compression:

Stored size: 1.11 KB

Contents

require "pact_broker/api/contracts/base_contract"

module PactBroker
  module Api
    module Contracts
      class EnvironmentSchema < BaseContract
        json do
          optional(:uuid)
          required(:name).filled(:string)
          optional(:displayName).maybe(:string)
          required(:production).filled(included_in?: [true, false])
          optional(:contacts).array(:hash) do
            required(:name).filled(:string)
            optional(:details).hash
          end
        end

        rule(:name).validate(:not_multiple_lines, :no_spaces_if_present)
        rule(:displayName).validate(:not_multiple_lines)

        rule(:name, :uuid) do
          if (environment_with_same_name = PactBroker::Deployments::EnvironmentService.find_by_name(values[:name]))
            if environment_with_same_name.uuid != values[:uuid]
              key.failure(validation_message("environment_name_must_be_unique", name: values[:name]))
            end
          end
        end

        rule(:contacts).each do
          validate_not_multiple_lines(value[:name], key(path.keys + [:name]))
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
pact_broker-2.112.0 lib/pact_broker/api/contracts/environment_schema.rb
pact_broker-2.111.0 lib/pact_broker/api/contracts/environment_schema.rb
pact_broker-2.109.1 lib/pact_broker/api/contracts/environment_schema.rb
pact_broker-2.109.0 lib/pact_broker/api/contracts/environment_schema.rb
pact_broker-2.108.0 lib/pact_broker/api/contracts/environment_schema.rb
pact_broker-2.107.1 lib/pact_broker/api/contracts/environment_schema.rb
pact_broker-2.107.0 lib/pact_broker/api/contracts/environment_schema.rb
pact_broker-2.107.0.beta.1 lib/pact_broker/api/contracts/environment_schema.rb