Class: Gapic::Model::Method::HttpAnnotation

Inherits:
Object
  • Object
show all
Defined in:
lib/gapic/model/method/http_annotation.rb

Overview

The information used in the generation process that can be gathered from the google.api.http annotation. google.api.http is used in two distinct ways:

  • REST libs use it as part of the transcoding to set up the REST call
  • gRPC libs use it as a source of implicit routing headers

Defined Under Namespace

Classes: HttpBinding

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proto_http) ⇒ HttpAnnotation

Returns a new instance of HttpAnnotation.

Parameters:

  • proto_http (::Google::Api::HttpRule)

    The base http annotation



42
43
44
# File 'lib/gapic/model/method/http_annotation.rb', line 42

def initialize proto_http
  @bindings = parse_bindings proto_http
end

Instance Attribute Details

#bindingsArray<HttpBinding> (readonly)

The Http bindings found in the annotation this includes main binding in the annotation itself, as well as those in the additional_bindings.

Returns:



36
37
38
# File 'lib/gapic/model/method/http_annotation.rb', line 36

def bindings
  @bindings
end

Class Method Details

.create_with_override(proto_method, service_config = nil) ⇒ Object

Parameters:

  • proto_method (::Gapic::Schema::Method)

    The proto method this annotation model applies to

  • service_config (::Google::Api::Service) (defaults to: nil)

    The service config that might contain an override for the http annotation. This is used for mixins: when generating Operations sublients, and when setting up overrides for other mixin clients in the host services's classes. For non-mixin service generation it is assumed that the service config is merged into protos before generation.



82
83
84
85
86
87
88
89
# File 'lib/gapic/model/method/http_annotation.rb', line 82

def self.create_with_override proto_method, service_config = nil
  proto_http = proto_method.http

  http_override = service_config&.http&.rules&.find { |http_rule| http_rule.selector == proto_method.full_name }

  http = http_override || proto_http
  HttpAnnotation.new http
end

Instance Method Details

#routing_paramsArray<String>

The implicit routing parameter names.

Returns:

  • (Array<String>)


58
59
60
# File 'lib/gapic/model/method/http_annotation.rb', line 58

def routing_params
  routing_params_with_patterns.map { |param, _| param }
end

#routing_params?Boolean

Whether any implicit routing parameters are present.

Returns:

  • (Boolean)


50
51
52
# File 'lib/gapic/model/method/http_annotation.rb', line 50

def routing_params?
  routing_params.any?
end

#routing_params_with_patternsArray<Array<String>>

The implicit routing parameter names and their corresponding paterns, including the * pattern implied for the named segments without an explicitly specified pattern.

Returns:

  • (Array<Array<String>>)


68
69
70
# File 'lib/gapic/model/method/http_annotation.rb', line 68

def routing_params_with_patterns
  bindings.first&.routing_params_with_patterns || []
end