gapic-generator 0.9.1 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +57 -0
  3. data/lib/gapic/generator/version.rb +1 -1
  4. data/lib/gapic/generators/default_generator.rb +3 -1
  5. data/lib/gapic/generators/default_generator_parameters.rb +6 -2
  6. data/lib/gapic/grpc_service_config/{service_config.rb → config.rb} +2 -2
  7. data/lib/gapic/grpc_service_config/parser.rb +8 -8
  8. data/lib/gapic/model/method/http_annotation.rb +123 -0
  9. data/lib/gapic/model/method/lro.rb +160 -0
  10. data/lib/gapic/model/method/routing.rb +263 -0
  11. data/lib/gapic/model/mixins.rb +181 -0
  12. data/lib/gapic/model/model_error.rb +26 -0
  13. data/lib/gapic/model/service/nonstandard_lro_provider.rb +293 -0
  14. data/lib/gapic/model.rb +22 -0
  15. data/lib/gapic/path_pattern/pattern.rb +46 -0
  16. data/lib/gapic/path_pattern/segment.rb +97 -9
  17. data/lib/gapic/presenters/gem_presenter.rb +46 -3
  18. data/lib/gapic/presenters/{service_config_presenter.rb → grpc_service_config_presenter.rb} +1 -1
  19. data/lib/gapic/presenters/method/rest_pagination_info.rb +246 -0
  20. data/lib/gapic/presenters/method_presenter.rb +56 -5
  21. data/lib/gapic/presenters/method_rest_presenter.rb +99 -48
  22. data/lib/gapic/presenters/resource_presenter.rb +8 -0
  23. data/lib/gapic/presenters/service/lro_client_presenter.rb +90 -0
  24. data/lib/gapic/presenters/service_presenter.rb +236 -3
  25. data/lib/gapic/presenters/service_rest_presenter.rb +117 -10
  26. data/lib/gapic/presenters/snippet_presenter.rb +2 -1
  27. data/lib/gapic/presenters.rb +3 -1
  28. data/lib/gapic/schema/api.rb +61 -2
  29. data/lib/gapic/schema/loader.rb +4 -1
  30. data/lib/gapic/schema/service_config_parser.rb +118 -0
  31. data/lib/gapic/schema/wrappers.rb +149 -0
  32. data/lib/google/api/auth.pb.rb +75 -0
  33. data/lib/google/api/backend.pb.rb +59 -0
  34. data/lib/google/api/billing.pb.rb +53 -0
  35. data/lib/google/api/context.pb.rb +47 -0
  36. data/lib/google/api/control.pb.rb +38 -0
  37. data/lib/google/api/documentation.pb.rb +56 -0
  38. data/lib/google/api/endpoint.pb.rb +42 -0
  39. data/lib/google/api/label.pb.rb +49 -0
  40. data/lib/google/api/launch_stage.pb.rb +37 -0
  41. data/lib/google/api/log.pb.rb +47 -0
  42. data/lib/google/api/logging.pb.rb +48 -0
  43. data/lib/google/api/metric.pb.rb +90 -0
  44. data/lib/google/api/monitored_resource.pb.rb +68 -0
  45. data/lib/google/api/monitoring.pb.rb +48 -0
  46. data/lib/google/api/quota.pb.rb +63 -0
  47. data/lib/google/api/routing.pb.rb +58 -0
  48. data/lib/google/api/service.pb.rb +90 -0
  49. data/lib/google/api/source_info.pb.rb +44 -0
  50. data/lib/google/api/system_parameter.pb.rb +51 -0
  51. data/lib/google/api/usage.pb.rb +47 -0
  52. data/lib/google/cloud/extended_operations.pb.rb +57 -0
  53. data/lib/google/protobuf/any.pb.rb +1 -1
  54. data/lib/google/protobuf/api.pb.rb +69 -0
  55. data/lib/google/protobuf/descriptor.pb.rb +1 -1
  56. data/lib/google/protobuf/duration.pb.rb +41 -0
  57. data/lib/google/protobuf/source_context.pb.rb +39 -0
  58. data/lib/google/protobuf/struct.pb.rb +65 -0
  59. data/lib/google/protobuf/type.pb.rb +128 -0
  60. data/lib/google/protobuf/wrappers.pb.rb +80 -0
  61. data/templates/default/gem/yardopts.erb +1 -1
  62. data/templates/default/lib/_package.erb +4 -0
  63. data/templates/default/lib/_service.erb +6 -0
  64. data/templates/default/lib/rest/_rest.erb +0 -2
  65. data/templates/default/service/client/_client.erb +37 -27
  66. data/templates/default/service/client/_config.erb +13 -14
  67. data/templates/default/service/client/_nonstandard_lro.erb +57 -0
  68. data/templates/default/service/client/_paths.erb +1 -1
  69. data/templates/default/service/client/_self_configure_defaults.erb +2 -2
  70. data/templates/default/service/client/method/_def.erb +2 -0
  71. data/templates/default/service/client/method/def/_options_defaults.erb +4 -9
  72. data/templates/default/service/client/method/def/_response.erb +2 -0
  73. data/templates/default/service/client/method/def/_response_nonstandard_lro.erb +23 -0
  74. data/templates/default/service/client/method/def/_routing_params.erb +36 -0
  75. data/templates/default/service/client/method/docs/_deprecated.erb +5 -0
  76. data/templates/default/service/client/method/docs/_snippets.erb +6 -0
  77. data/templates/default/service/nonstandard_lro.erb +6 -0
  78. data/templates/default/service/rest/client/_client.erb +45 -27
  79. data/templates/default/service/rest/client/_config.erb +48 -0
  80. data/templates/default/service/rest/client/method/_def.erb +1 -1
  81. data/templates/default/service/rest/client/method/def/_options_defaults.erb +5 -2
  82. data/templates/default/service/rest/client/method/def/_response.erb +8 -0
  83. data/templates/default/service/rest/client/method/def/_response_nonstandard_lro.erb +23 -0
  84. data/templates/default/service/rest/client/method/def/_response_normal.erb +4 -15
  85. data/templates/default/service/rest/client/method/def/_response_paged.erb +7 -0
  86. data/templates/default/service/rest/client/method/docs/_result.erb +3 -3
  87. data/templates/default/service/rest/service_stub/_service_stub.erb +25 -0
  88. data/templates/default/service/rest/{grpc_transcoding/method → service_stub/grpc_transcoding_method}/_def.erb +4 -1
  89. data/templates/default/service/rest/{grpc_transcoding/method → service_stub/grpc_transcoding_method}/def/_query_string_param.erb +0 -0
  90. data/templates/default/service/rest/service_stub/method/_def.erb +20 -0
  91. data/templates/default/service/rest/service_stub/method/def/_request.erb +2 -0
  92. data/templates/default/service/rest/service_stub/method/def/_response.erb +17 -0
  93. data/templates/default/service/rest/service_stub.erb +6 -0
  94. data/templates/default/service/rest/test/client.erb +1 -1
  95. data/templates/default/service/test/client_paths.erb +1 -1
  96. data/templates/default/service/test/method/_assert_response.erb +3 -0
  97. metadata +74 -11
  98. data/templates/default/service/rest/client/_requires.erb +0 -1
  99. data/templates/default/service/rest/grpc_transcoding/_grpc_transcoding.erb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61762b2051b75312bfc67ef070e136d8cf95cad1635e1b22270ed8a5b6cfbc99
4
- data.tar.gz: cd867c0065831c6b5252dc0b5097417f24a74716f4e15cd243a1371ac80e5a5d
3
+ metadata.gz: a8baa3144f849b60f36cb51b7c7bed258165e9b3a646816aad586912001e4ddc
4
+ data.tar.gz: f1dc6fb877e18c0eed6c461bf6937d3756409da0bb259484149c377244953a70
5
5
  SHA512:
6
- metadata.gz: b8c833fe9bbb2d35c8fb0e7b307e1f0aeb0f5774fe0f174e2505bc0460fcc13ae06bf6e2761fe1e00d7e44079327fbc761f7423b72c51e58ef23c4f4220edebb
7
- data.tar.gz: 89e7871eac1c9e01d870c2e367e67e16ac5c49580259d828c922324250a88955da88014496a8da7ff22964e18941046153158df4d8a023a7fb9a158a86c06cea
6
+ metadata.gz: 90b475c396bcdd3ecdadec8fb27e3e8089e6c8525ad75d2f83142525684b898a38765ebde17d22262e2acaac56b8452e6d77b6a6f2ccc4fab4c21ad3997c9019
7
+ data.tar.gz: 84b4aab4d800b042c4be22f3159ca77fa1cc3489a903b79844d239202c56ffb0c02db39957afa7c0bee28b168547ff1e5afda93d373450f5f8a0e14feb969147
data/CHANGELOG.md CHANGED
@@ -1,5 +1,62 @@
1
1
  # Release History for gapic-generator
2
2
 
3
+ ### 0.11.0 / 2022-03-01
4
+
5
+ * New: Added generation of nonstandard LRO wrapper calls (currently used for Compute)
6
+ * Fixed: Examples in the doc comments for modules are now generated with `@example` tags
7
+ * Fixed: proto files without a proto service can again be generated
8
+ * Ruby prebuilt binaries used in Bazel rules updated to Ruby 2.6.6
9
+
10
+ ### 0.10.6 / 2022-02-02
11
+
12
+ * Point default documentation URL to rubydoc.info.
13
+
14
+ ### 0.10.5 / 2022-01-20
15
+
16
+ * No significant changes
17
+
18
+ ### 0.10.4 / 2022-01-07
19
+
20
+ * Fixed: Set quota_project_id correctly for LRO clients
21
+ * Fixed: Remove old cloud-rad configs and rake tasks
22
+ * Fixed: Properly quote page titles in YARD configs
23
+
24
+ ### 0.10.3 / 2021-11-04
25
+
26
+ * New: Enabled snippet-gen by default
27
+
28
+ ### 0.10.2 / 2021-11-01
29
+
30
+ * New: Added support for service.yaml
31
+ * New: New mixin implementation
32
+ * New: Parse and generate explicit routing headers
33
+ * New: Preliminary support for extended operations for REST LROs
34
+ * Fixed: Potential failures in generated tests when routing headers reference sub-fields
35
+ * Fixed: Renamed service_config to grpc_service_config
36
+
37
+ ### 0.10.1 / 2021-08-27
38
+
39
+ * New: Compute REST libraries are now generated with LRO wrappers
40
+ * Fixed: Rubocop is disabled for sample tests in generated versioned libraries
41
+
42
+ ### 0.10.0 / 2021-08-09
43
+
44
+ * New: Enabled per-RPC configuration for generated REST libraries
45
+ * New: Generated docs include the deprecated YARD tag for deprecated protos
46
+ * New: Scopes can be passed to self-signed JWTs
47
+ * Fixed: Generated gRPC clients honor the client-default timeout config
48
+ * Fixed: Generated docs now use YARD example tags for inline samples related to configuration
49
+ * Fixed: Generated REST clients now require google/cloud/errors
50
+ * Generated libraries now require gapic-common 0.7.0 or later
51
+
52
+ ### 0.9.2 / 2021-07-27
53
+
54
+ * REST libraries are now generated with pagination hepers
55
+ * REST libraries are now generated with correct examples in README.md and other documentation files
56
+ * It is now possible to generate inline snippets in yardocs
57
+ * Fixed the require path in the generated standalone snippets so it reflects the recommended require root rather than the service-specific require path.
58
+ * Prevent "duplicate" resources (with the same name but different namespaces) from producing duplicate helper methods.
59
+
3
60
  ### 0.9.1 / 2021-07-07
4
61
 
5
62
  * Detect multiple resource parents for patterns used by multiple resources
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Gapic
18
18
  module Generator
19
- VERSION = "0.9.1"
19
+ VERSION = "0.11.0"
20
20
  end
21
21
  end
@@ -59,8 +59,10 @@ module Gapic
59
59
  files << g("service/credentials.erb", "lib/#{service.credentials_file_path}", service: service) unless gem.generic_endpoint?
60
60
  files << g("service/paths.erb", "lib/#{service.paths_file_path}", service: service) if service.paths?
61
61
  files << g("service/operations.erb", "lib/#{service.operations_file_path}", service: service) if service.lro? && !@api.generate_rest_clients?
62
+ files << g("service/nonstandard_lro.erb", "lib/#{service.nonstandard_lro_file_path}", service: service) if service.nonstandard_lro_provider? && !service.methods_rest_bindings?
63
+ files << g("service/nonstandard_lro.erb", "lib/#{service.rest.nonstandard_lro_file_path}", service: service) if service.nonstandard_lro_provider? && service.methods_rest_bindings?
62
64
  files << g("service/rest/client.erb", "lib/#{service.rest.client_file_path}", service: service) if @api.generate_rest_clients? and service.methods_rest_bindings?
63
- files << g("service/rest/grpc_transcoding.erb", "lib/#{service.rest.transcoding_helper_file_path}", service: service) if @api.generate_rest_clients? and service.methods_rest_bindings?
65
+ files << g("service/rest/service_stub.erb", "lib/#{service.rest.service_stub_file_path}", service: service) if @api.generate_rest_clients? and service.methods_rest_bindings?
64
66
  files << g("service/rest/test/client.erb", "test/#{service.rest.test_client_file_path}", service: service) if @api.generate_rest_clients? and service.methods_rest_bindings?
65
67
  files << g("service/test/client.erb", "test/#{service.test_client_file_path}", service: service) unless @api.generate_rest_clients?
66
68
  files << g("service/test/client_paths.erb", "test/#{service.test_paths_file_path}", service: service) if service.paths?
@@ -24,7 +24,9 @@ module Gapic
24
24
  ":gem.:free_tier",
25
25
  ":gem.:yard_strict",
26
26
  ":gem.:generic_endpoint",
27
- ":generate_metadata"
27
+ ":generate_metadata",
28
+ ":generate_standalone_snippets",
29
+ ":generate_yardoc_snippets"
28
30
  ].freeze
29
31
 
30
32
  STRING_PARAMETERS = [
@@ -44,6 +46,7 @@ module Gapic
44
46
  ":gem.:factory_method_suffix",
45
47
  ":defaults.:service.:default_host",
46
48
  "grpc_service_config",
49
+ ":service_yaml",
47
50
  ":overrides.:wrapper_gem_name"
48
51
  ].freeze
49
52
 
@@ -82,7 +85,8 @@ module Gapic
82
85
  "gem-api-shortname" => ":gem.:api_shortname",
83
86
  "gem-factory-method-suffix" => ":gem.:factory_method_suffix",
84
87
  "default-service-host" => ":defaults.:service.:default_host",
85
- "grpc-service-config" => "grpc_service_config"
88
+ "grpc-service-config" => "grpc_service_config",
89
+ "service-yaml" => ":service_yaml"
86
90
  }.freeze
87
91
 
88
92
  ARRAY_PARAMETERS_ALIASES = {
@@ -21,12 +21,12 @@ module Gapic
21
21
  # applied on the service level (to all the methods) and the configurations
22
22
  # applied to the specific methods
23
23
  #
24
- class ServiceConfig
24
+ class Config
25
25
  attr_reader :service_level_configs
26
26
  attr_reader :service_method_level_configs
27
27
 
28
28
  ##
29
- # Create new ServiceConfig.
29
+ # Create new GrpcServiceConfig.
30
30
  #
31
31
  # @param service_level_configs [Hash<String, Gapic::GrpcServiceConfig::MethodConfig>] service-level configs
32
32
  # in a lookup hash by the service full grpc name
@@ -14,7 +14,7 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
- require "gapic/grpc_service_config/service_config"
17
+ require "gapic/grpc_service_config/config"
18
18
  require "gapic/grpc_service_config/method_config"
19
19
  require "gapic/grpc_service_config/retry_policy"
20
20
  require "gapic/grpc_service_config/parsing_error"
@@ -67,18 +67,18 @@ module Gapic
67
67
  end.freeze
68
68
 
69
69
  ##
70
- # Parses ServiceConfig from a json of a GRPC service config
70
+ # Parses GRPC service configuration from a json
71
71
  #
72
- # @param service_config_json [Hash] a hash that results from JSON.parse
72
+ # @param config_json [Hash] a hash that results from JSON.parse
73
73
  #
74
- # @return [Gapic::GrpcServiceConfig::ServiceConfig] parsed ServiceConfig
74
+ # @return [Gapic::GrpcServiceConfig::Config] parsed GrpcServiceConfig
75
75
  #
76
- def self.parse service_config_json
76
+ def self.parse config_json
77
77
  service_level_result = {}
78
78
  service_method_level_result = {}
79
79
 
80
- if !service_config_json.nil? && key?(service_config_json, METHOD_CONFIG_JSON_KEY)
81
- method_configs_json = get service_config_json, METHOD_CONFIG_JSON_KEY
80
+ if !config_json.nil? && key?(config_json, METHOD_CONFIG_JSON_KEY)
81
+ method_configs_json = get config_json, METHOD_CONFIG_JSON_KEY
82
82
 
83
83
  method_configs_json.each do |method_config_json|
84
84
  method_config = parse_config method_config_json
@@ -99,7 +99,7 @@ module Gapic
99
99
  end
100
100
  end
101
101
 
102
- ServiceConfig.new service_level_result, service_method_level_result
102
+ Config.new service_level_result, service_method_level_result
103
103
  end
104
104
 
105
105
  ##
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2021 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require "gapic/uri_template"
18
+
19
+ module Gapic
20
+ module Model
21
+ module Method
22
+ ##
23
+ # The information used in the generation process that
24
+ # can be gathered from the `google.api.http` annotation.
25
+ # `google.api.http` is used in two distinct ways:
26
+ # - the rest libs use it as part of the transcoding to set up the REST call
27
+ # - both rest and grpc libs use it as a source of implicit routing headers
28
+ #
29
+ class HttpAnnotation
30
+ ##
31
+ # @param proto_method [Gapic::Schema::Method]
32
+ #
33
+ def initialize proto_method
34
+ @proto_method = proto_method
35
+ end
36
+
37
+ ##
38
+ # Whether a http verb is present for this method
39
+ #
40
+ # @return [Boolean]
41
+ def verb?
42
+ !verb.nil?
43
+ end
44
+
45
+ ##
46
+ # The http verb for this method
47
+ #
48
+ # @return [Symbol, Nil]
49
+ def verb
50
+ return nil if @proto_method.http.nil?
51
+
52
+ method = {
53
+ get: @proto_method.http.get,
54
+ post: @proto_method.http.post,
55
+ put: @proto_method.http.put,
56
+ patch: @proto_method.http.patch,
57
+ delete: @proto_method.http.delete
58
+ }.find { |_, value| !value.empty? }
59
+
60
+ method[0] unless method.nil?
61
+ end
62
+
63
+ ##
64
+ # Whether a method path is present and non-empty
65
+ #
66
+ # @return [Boolean]
67
+ def path?
68
+ !path.empty?
69
+ end
70
+
71
+ ##
72
+ # A method path or an empty string if not present
73
+ #
74
+ # @return [String]
75
+ def path
76
+ return "" if @proto_method.http.nil?
77
+
78
+ verb_path = [
79
+ @proto_method.http.get, @proto_method.http.post, @proto_method.http.put,
80
+ @proto_method.http.patch, @proto_method.http.delete
81
+ ].find { |x| !x.empty? }
82
+
83
+ verb_path || @proto_method.http.custom&.path || ""
84
+ end
85
+
86
+ ##
87
+ # Whether any routing params are present
88
+ #
89
+ # @return [Boolean]
90
+ def routing_params?
91
+ routing_params.any?
92
+ end
93
+
94
+ ##
95
+ # The segment key names.
96
+ #
97
+ # @return [Array<String>]
98
+ def routing_params
99
+ Gapic::UriTemplate.parse_arguments path
100
+ end
101
+
102
+ ##
103
+ # Whether method has body specified in proto
104
+ #
105
+ # @return [Boolean]
106
+ def body?
107
+ return false if @proto_method.http.nil?
108
+
109
+ !@proto_method.http.body.empty?
110
+ end
111
+
112
+ ##
113
+ # The body specified for the given method in proto
114
+ # or an empty string if not specified
115
+ #
116
+ # @return [String]
117
+ def body
118
+ @proto_method.http&.body || ""
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,160 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2021 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require "gapic/path_pattern"
18
+
19
+ module Gapic
20
+ module Model
21
+ ##
22
+ # Method-level models
23
+ #
24
+ module Method
25
+ ##
26
+ # Nonstandard (AIP-151 nonconforming) long-running operation method-level model
27
+ #
28
+ # @!attribute [r] service_full_name
29
+ # @return [String] Full grpc name of the provider service for this method's LRO
30
+ # e.g. `google.example.LroProvider`
31
+ #
32
+ # @!attribute [r] operation_request_fields
33
+ # @return [Map<String, String>] Map of the field names of this method's request message
34
+ # that should be saved and later used when constructing the LRO polling request.
35
+ # The values are the names of the fields in the polling request.
36
+ # The semantics are `from -> to`, e.g. `{"foo" => "bar"}` means that
37
+ # when constructing a polling request, the following assignment should be carried out:
38
+ # `lro_polling_request.bar = this_method_request.foo`.
39
+ #
40
+ class NonStandardLro
41
+ # @return [String]
42
+ attr_reader :service_full_name
43
+ # @return [Map<String, String>]
44
+ attr_reader :operation_request_fields
45
+
46
+ ##
47
+ # @param method [Gapic::Schema::Method]
48
+ # @param service_full_name [String] Full grpc name of the provider service for this method's LRO
49
+ def initialize method, service_full_name
50
+ @service_full_name = service_full_name
51
+
52
+ # optionally, there might be things to copy from this method's input object
53
+ # to the LRO service's input object (`operation_request_field` annotation)
54
+ ops_request_fields = method.input.fields.find_all do |f|
55
+ !f.operation_request_field.nil? && !f.operation_request_field.empty?
56
+ end
57
+
58
+ @operation_request_fields = ops_request_fields.map do |field|
59
+ [field.name, field.operation_request_field]
60
+ end.to_h
61
+ end
62
+
63
+ ##
64
+ # @return [Boolean] Whether this is a model for the nonstandard LRO
65
+ #
66
+ def nonstandard_lro?
67
+ true
68
+ end
69
+
70
+ ##
71
+ # @return [Boolean] Whether this is a model for the AIP-151 LRO
72
+ #
73
+ def aip_lro?
74
+ false
75
+ end
76
+ end
77
+
78
+ ##
79
+ # AIP-151 LRO Model
80
+ #
81
+ class AipLro
82
+ include Singleton
83
+ ##
84
+ # @return [Boolean] Whether this is a model for the nonstandard LRO
85
+ #
86
+ def nonstandard_lro?
87
+ false
88
+ end
89
+
90
+ ##
91
+ # @return [Boolean] Whether this is a model for the AIP-151 LRO
92
+ #
93
+ def aip_lro?
94
+ true
95
+ end
96
+ end
97
+
98
+ ##
99
+ # Method does not represent a long-running operation
100
+ #
101
+ class NoLro
102
+ include Singleton
103
+ ##
104
+ # @return [Boolean] Whether this is a model for the nonstandard LRO
105
+ #
106
+ def nonstandard_lro?
107
+ false
108
+ end
109
+
110
+ ##
111
+ # @return [Boolean] Whether this is a model for the AIP-151 LRO
112
+ #
113
+ def aip_lro?
114
+ false
115
+ end
116
+ end
117
+
118
+ class << self
119
+ ##
120
+ # Inspects the method and returns it's long-running operation model
121
+ #
122
+ # @param method [Gapic::Schema::Method]
123
+ # @param api [Gapic::Schema::Api]
124
+ #
125
+ # @raises [Gapic::Model::ModelError]
126
+ #
127
+ # @returns [Gapic::Model::Method::NonStandardLro, Gapic::Model::Method::AipLro, Gapic::Model::Method::NoLro]
128
+ #
129
+ def parse_lro method, api
130
+ is_aip_lro = method.output.full_name == "google.longrunning.Operation"
131
+ return AipLro.instance if is_aip_lro
132
+
133
+ # If a method is annotated with operation_service, this is a nonstandard LRO consumer method
134
+ is_nonstandard_lro = !method.operation_service.nil? && !method.operation_service.empty?
135
+ if is_nonstandard_lro
136
+ # LRO service name is given plain, so it has to be in the same package as this method's service
137
+ service_full_name = (method.address[0..-3] << method.operation_service).join "."
138
+ ops_service_lro = api.nonstandard_lro_model_for service_full_name
139
+ unless ops_service_lro.nonstandard_lro?
140
+ error_text = "A service #{service_full_name} specified as a nonstandard LRO service for " \
141
+ "the method #{method.full_name} was not found."
142
+ raise ModelError, error_text
143
+ end
144
+
145
+ unless method.output.full_name == ops_service_lro.lro_object_full_name
146
+ error_text = "A service #{service_full_name} specified as a nonstandard LRO service for " \
147
+ "the method #{method.full_name} has a different LRO object (#{ops_service_lro.lro_object_full_name}) " \
148
+ "from the method's return type (#{method.output.full_name})."
149
+ raise ModelError, error_text
150
+ end
151
+
152
+ return NonStandardLro.new method, service_full_name
153
+ end
154
+
155
+ NoLro.instance
156
+ end
157
+ end
158
+ end
159
+ end
160
+ end