Module: Gapic::Schema::ServiceConfigParser

Defined in:
lib/gapic/schema/service_config_parser.rb

Overview

Contains logic for parsing a subset of service.yaml used for the service generation

Constant Summary collapse

CONFIG_VERSION_KEY =
"config_version"
NAME_KEY =
"name"
VERSION_KEY =
"version"
ID_KEY =
"id"
TITLE_KEY =
"title"
APIS_KEY =
"apis"
HTTP_KEY =
"http"
HTTP_RULES_KEY =
"rules"
HTTP_RULES_SELECTOR_KEY =
"selector"
HTTP_RULES_VERBS_ALLOWED =
["get", "post", "put", "patch", "delete"].freeze
HTTP_RULES_BODY_KEY =
"body"
HTTP_RULES_ADDITIONAL_BINDINGS_KEY =
"additional_bindings"

Class Method Summary collapse

Class Method Details

.parse_service_yaml(service_yaml_text) ⇒ ::Google::Api::Service

Returns the parsed Google::Api::Service object. Only supports a limited subset of fields.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/gapic/schema/service_config_parser.rb', line 45

def parse_service_yaml service_yaml_text
  return nil unless service_yaml_text && !service_yaml_text.empty?
  service_yaml = YAML.safe_load service_yaml_text
  service = Google::Api::Service.new

  if service_yaml.key? CONFIG_VERSION_KEY
    config_ver = Google::Protobuf::UInt32Value.new
    config_ver.value = service_yaml[CONFIG_VERSION_KEY]
    service.config_version = config_ver
  end

  service.name = service_yaml[NAME_KEY] if service_yaml.key? NAME_KEY
  service.id = service_yaml[ID_KEY] if service_yaml.key? ID_KEY
  service.title = service_yaml[TITLE_KEY] if service_yaml.key? TITLE_KEY

  service.apis = parse_apis service_yaml[APIS_KEY] if service_yaml.key? APIS_KEY
  service.http = parse_http service_yaml[HTTP_KEY] if service_yaml.key? HTTP_KEY
  service
end