Module: Scorpio::OpenAPI::V3::Server

Defined in:
lib/scorpio/openapi/v3/server.rb

Overview

Instance Method Summary collapse

Instance Method Details

#expanded_url(given_server_variables) ⇒ Addressable::URI

expands this server's #url using the given_server_variables. any variables that are in the url but not in the given server variables are filled in using the default value for the variable.

Parameters:

  • given_server_variables (Hash<String, String>)

Returns:

  • (Addressable::URI)

    the expanded url



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/scorpio/openapi/v3/server.rb', line 16

def expanded_url(given_server_variables)
  if variables
    server_variables = (given_server_variables.keys | variables.keys).map do |key|
      server_variable = variables[key]
      if server_variable && server_variable.enum
        unless server_variable.enum.include?(given_server_variables[key])
          warn # TODO BLAME
        end
      end
      if given_server_variables.key?(key)
        {key => given_server_variables[key]}
      elsif server_variable.key?('default')
        {key => server_variable.default}
      else
        {}
      end
    end.inject({}, &:update)
  else
    server_variables = given_server_variables
  end
  template = Addressable::Template.new(url)
  template.expand(server_variables)
end