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
@@ -36,6 +36,7 @@ module Gapic
36
36
  @service = service
37
37
  @parent_service = parent_service
38
38
  @rest = ServiceRestPresenter.new self, api
39
+ @nonstandard_lro = api.nonstandard_lro_model_for service.full_name
39
40
  end
40
41
 
41
42
  def gem
@@ -50,6 +51,13 @@ module Gapic
50
51
  PackagePresenter.new @gem_presenter, @api, @service.parent.package
51
52
  end
52
53
 
54
+ ##
55
+ # @return [Boolean]
56
+ #
57
+ def is_deprecated?
58
+ @service.is_deprecated?
59
+ end
60
+
53
61
  ##
54
62
  # @return [Enumerable<Gapic::Presenters::MethodPresenter>]
55
63
  #
@@ -252,6 +260,34 @@ module Gapic
252
260
  @references ||= @service.resources.map { |resource| ResourcePresenter.new resource }.sort_by(&:name)
253
261
  end
254
262
 
263
+ ##
264
+ # Deduplicate resource presenters by combining resources with the same
265
+ # name. If multiple resources have the same name (though possibly
266
+ # different namespaces, e.g. `location.googleapis.com/Location` vs
267
+ # `documentai.googleapis.com/Location`), this combines (and dedups) their
268
+ # patterns into a single resource presenter.
269
+ #
270
+ # Used for generating path helpers while avoiding duplicate method names.
271
+ #
272
+ def deduped_references
273
+ @deduped_references ||= begin
274
+ hash = {}
275
+ references.each do |resource|
276
+ if hash.key? resource.name
277
+ existing = hash[resource.name]
278
+ resource.patterns.each do |pat|
279
+ unless existing.patterns.any? { |epat| epat.pattern_template == pat.pattern_template }
280
+ existing.patterns << pat
281
+ end
282
+ end
283
+ else
284
+ hash[resource.name] = resource.dup
285
+ end
286
+ end
287
+ hash.values
288
+ end
289
+ end
290
+
255
291
  def paths?
256
292
  references.any?
257
293
  end
@@ -315,18 +351,44 @@ module Gapic
315
351
  "#{ActiveSupport::Inflector.underscore name}_stub"
316
352
  end
317
353
 
354
+ ##
355
+ # Whether an AIP-151 LRO subclient needs to be generated for this service
356
+ #
357
+ # @return [Boolean]
318
358
  def lro?
319
359
  methods.find(&:lro?)
320
360
  end
321
361
 
362
+ ##
363
+ # A variable name used for the AIP-151 LRO subclients
364
+ #
365
+ # @return [String]
322
366
  def lro_client_var
323
367
  "operations_client"
324
368
  end
325
369
 
370
+ ##
371
+ # An instance variable name used for the AIP-151 LRO subclients
372
+ #
373
+ # @return [String]
326
374
  def lro_client_ivar
327
375
  "@#{lro_client_var}"
328
376
  end
329
377
 
378
+ ##
379
+ # A presenter for the LRO subclient if needed
380
+ #
381
+ # @return [Gapic::Presenters::Service::LroClientPresenter, nil]
382
+ def lro_client_presenter
383
+ return nil unless lro?
384
+ Gapic::Presenters::Service::LroClientPresenter.new service: "google.longrunning.operations",
385
+ client_class_name: "Operations",
386
+ client_class_docname: operations_name_full,
387
+ client_var_name: lro_client_var,
388
+ require_str: operations_file_path,
389
+ service_description: "long-running operations"
390
+ end
391
+
330
392
  def operations_name
331
393
  "Operations"
332
394
  end
@@ -361,8 +423,8 @@ module Gapic
361
423
  @api.grpc_service_config.service_level_configs[grpc_full_name]
362
424
  end
363
425
 
364
- def service_config_presenter
365
- ServiceConfigPresenter.new grpc_service_config
426
+ def grpc_service_config_presenter
427
+ GrpcServiceConfigPresenter.new grpc_service_config
366
428
  end
367
429
 
368
430
  ##
@@ -373,8 +435,12 @@ module Gapic
373
435
  @service.name
374
436
  end
375
437
 
438
+ ##
439
+ # The full proto name for this service
440
+ #
441
+ # @return [String]
376
442
  def grpc_full_name
377
- @service.address.join "."
443
+ @service.full_name
378
444
  end
379
445
 
380
446
  ##
@@ -423,8 +489,175 @@ module Gapic
423
489
  result || methods.find { |meth| !meth.client_streaming? }
424
490
  end
425
491
 
492
+ ##
493
+ # Returns this service presenter if there is a grpc client. Otherwise,
494
+ # returns the corresponding rest service presenter if there isn't a grpc
495
+ # client but there is a rest client. Otherwise, returns nil if there is
496
+ # neither client.
497
+ #
498
+ # @return [ServicePresenter,ServiceRestPresenter,nil]
499
+ #
500
+ def usable_service_presenter
501
+ if @api.generate_grpc_clients?
502
+ self
503
+ elsif @api.generate_rest_clients? && methods_rest_bindings?
504
+ rest
505
+ end
506
+ end
507
+
508
+ ##
509
+ # Whether there are mixin services that should be referenced
510
+ # in the client for this service
511
+ #
512
+ # @return [Boolean]
513
+ #
514
+ def mixins?
515
+ @gem_presenter.mixins?
516
+ end
517
+
518
+ ##
519
+ # The mixin services that should be referenced
520
+ # in the client for this service
521
+ #
522
+ # @return [Enumerable<Gapic::Model::Mixins::Mixin>]
523
+ #
524
+ def mixins
525
+ @gem_presenter.mixins_model.mixins
526
+ end
527
+
528
+ ##
529
+ # Name of the nonstandard LRO module
530
+ #
531
+ # @return [String]
532
+ #
533
+ def nonstandard_lro_name
534
+ "NonstandardLro"
535
+ end
536
+
537
+ ##
538
+ # Full name of the nonstandard LRO module
539
+ #
540
+ # @return [String]
541
+ #
542
+ def nonstandard_lro_name_full
543
+ fix_namespace @api, "#{service_name_full}::#{nonstandard_lro_name}"
544
+ end
545
+
546
+ ##
547
+ # Full file path to the nonstandard LRO module
548
+ #
549
+ # @return [String]
550
+ #
551
+ def nonstandard_lro_file_path
552
+ "#{nonstandard_lro_require}.rb"
553
+ end
554
+
555
+ ##
556
+ # File name of the nonstandard LRO module
557
+ #
558
+ # @return [String]
559
+ #
560
+ def nonstandard_lro_file_name
561
+ nonstandard_lro_file_path.split("/").last
562
+ end
563
+
564
+ ##
565
+ # The require string for the nonstandard LRO module
566
+ #
567
+ # @return [String]
568
+ #
569
+ def nonstandard_lro_require
570
+ ruby_file_path @api, "#{service_name_full}::#{nonstandard_lro_name}"
571
+ end
572
+
573
+ ##
574
+ # Nonstandard lro model for this service
575
+ #
576
+ # @return [Gapic::Model::Service::NonstandardLro, Gapic::Model::Service::NoLro]
577
+ def nonstandard_lro
578
+ @nonstandard_lro
579
+ end
580
+
581
+ ##
582
+ # The Ruby name for the polling method of the nonstandard LRO provided by this service
583
+ #
584
+ # @return [String]
585
+ def nonstandard_lro_polling_method_name
586
+ return unless nonstandard_lro_provider?
587
+ methods.find { |m| m.grpc_method_name == nonstandard_lro.polling_method_name }.name
588
+ end
589
+
590
+ ##
591
+ # Whether this service is a provider of the nonstandard LRO functionality
592
+ #
593
+ # @return [Boolean]
594
+ def nonstandard_lro_provider?
595
+ @nonstandard_lro.nonstandard_lro?
596
+ end
597
+
598
+ ##
599
+ # Whether one or more methods of this service use the nonstandard LRO functionality
600
+ #
601
+ # @return [Boolean]
602
+ def nonstandard_lro_consumer?
603
+ methods.find(&:nonstandard_lro?) || false
604
+ end
605
+
606
+ ##
607
+ # The client presenters of the nonstandard LROs that are used by the methods of this service
608
+ #
609
+ # @return [Enumerable<Gapic::Presenters::Service::LroClientPresenter>]
610
+ def nonstandard_lros
611
+ return [] unless nonstandard_lro_consumer?
612
+ nonstandard_lros_models.map do |lro|
613
+ lro_wrapper = @api.lookup lro.service_full_name
614
+ lro_service = ServicePresenter.new(@gem_presenter, @api, lro_wrapper).usable_service_presenter
615
+
616
+ service_description = "long-running operations via #{lro_service.name}"
617
+ Gapic::Presenters::Service::LroClientPresenter.new service: lro.service_full_name,
618
+ client_class_name: lro_service.client_name_full,
619
+ client_class_docname: lro_service.client_name_full,
620
+ client_var_name: lro_service.service_directory_name,
621
+ require_str: lro_service.service_require,
622
+ service_description: service_description,
623
+ helper_type: lro_service.nonstandard_lro_name_full
624
+ end
625
+ end
626
+
627
+ ##
628
+ # Whether there are any subclients to generate with this service.
629
+ # Subclients are the clients to other services (e.g. an LRO provider service).
630
+ #
631
+ # @return [Boolean]
632
+ def subclients?
633
+ subclients.any?
634
+ end
635
+
636
+ ##
637
+ # Subclients for this service
638
+ # Subclients are the clients to other services (e.g. an LRO provider service).
639
+ #
640
+ # The following is typically generated for a subclient:
641
+ # - a require statement for the subclient's class
642
+ # - a class-level variable in the host service's client
643
+ # - a code to initialize this variable with a subclient's class instance in the host service's constructor
644
+ #
645
+ # @return [Enumerable<Gapic::Presenters::Service::LroClientPresenter, Gapic::Model::Mixins::Mixin>]
646
+ def subclients
647
+ ([] << lro_client_presenter << mixins << nonstandard_lros).flatten.compact
648
+ end
649
+
426
650
  private
427
651
 
652
+ ##
653
+ # The nonstandard LRO models for the nonstandard LROs that are used by the methods of this service
654
+ #
655
+ # @return [Enumerable<Gapic::Model::Method::Lro>]
656
+ def nonstandard_lros_models
657
+ return [] unless nonstandard_lro_consumer?
658
+ methods.select(&:nonstandard_lro?).map(&:lro).uniq(&:service_full_name)
659
+ end
660
+
428
661
  def default_config key
429
662
  return unless @service.parent.parent.configuration[:defaults]
430
663
  return unless @service.parent.parent.configuration[:defaults][:service]
@@ -37,12 +37,69 @@ module Gapic
37
37
  end
38
38
 
39
39
  ##
40
+ # Ruby name of this service
41
+ #
42
+ # @return [String]
43
+ #
44
+ def name
45
+ main_service.name
46
+ end
47
+
48
+ ##
49
+ # Full Ruby name of this service
50
+ #
40
51
  # @return [String]
41
52
  #
42
53
  def service_name_full
43
54
  fix_namespace api, "#{main_service.service_name_full}::Rest"
44
55
  end
45
56
 
57
+ ##
58
+ # Require path for this service
59
+ #
60
+ # @return [String]
61
+ #
62
+ def service_require
63
+ ruby_file_path @api, service_name_full
64
+ end
65
+
66
+ ##
67
+ # Folder name for this service
68
+ #
69
+ # @return [String]
70
+ #
71
+ def service_directory_name
72
+ service_require.split("/")[-2]
73
+ end
74
+
75
+ ##
76
+ # @return [String]
77
+ #
78
+ def service_stub_name
79
+ "ServiceStub"
80
+ end
81
+
82
+ ##
83
+ # @return [String]
84
+ #
85
+ def service_stub_name_full
86
+ fix_namespace api, "#{service_name_full}::#{service_stub_name}"
87
+ end
88
+
89
+ ##
90
+ # @return [String]
91
+ #
92
+ def service_stub_require
93
+ ruby_file_path api, service_stub_name_full
94
+ end
95
+
96
+ ##
97
+ # @return [String]
98
+ #
99
+ def service_stub_file_path
100
+ "#{service_stub_require}.rb"
101
+ end
102
+
46
103
  ##
47
104
  # @return [String]
48
105
  #
@@ -95,38 +152,88 @@ module Gapic
95
152
  ##
96
153
  # @return [String]
97
154
  #
98
- def transcoding_helper_name
99
- "GrpcTranscoding"
155
+ def test_client_file_path
156
+ main_service.service_file_path.sub ".rb", "_test.rb"
100
157
  end
101
158
 
102
159
  ##
103
160
  # @return [String]
104
161
  #
105
- def transcoding_helper_name_full
106
- fix_namespace api, "#{service_name_full}::#{transcoding_helper_name}"
162
+ def credentials_class_xref
163
+ main_service.credentials_class_xref
107
164
  end
108
165
 
109
166
  ##
110
167
  # @return [String]
111
168
  #
112
- def transcoding_helper_require
113
- ruby_file_path api, transcoding_helper_name_full
169
+ def configure_client_call
170
+ "#{client_name_full}.configure"
114
171
  end
115
172
 
116
173
  ##
174
+ # Name of the nonstandard LRO module
175
+ #
117
176
  # @return [String]
118
177
  #
119
- def transcoding_helper_file_path
120
- "#{transcoding_helper_require}.rb"
178
+ def nonstandard_lro_name
179
+ "NonstandardLro"
121
180
  end
122
181
 
123
182
  ##
183
+ # Full name of the nonstandard LRO module
184
+ #
124
185
  # @return [String]
125
186
  #
126
- def test_client_file_path
127
- main_service.service_file_path.sub ".rb", "_test.rb"
187
+ def nonstandard_lro_name_full
188
+ fix_namespace @api, "#{service_name_full}::#{nonstandard_lro_name}"
128
189
  end
129
190
 
191
+ ##
192
+ # Full file path to the nonstandard LRO module
193
+ #
194
+ # @return [String]
195
+ #
196
+ def nonstandard_lro_file_path
197
+ "#{nonstandard_lro_require}.rb"
198
+ end
199
+
200
+ ##
201
+ # File name of the nonstandard LRO module
202
+ #
203
+ # @return [String]
204
+ #
205
+ def nonstandard_lro_file_name
206
+ nonstandard_lro_file_path.split("/").last
207
+ end
208
+
209
+ ##
210
+ # The require string for the nonstandard LRO module
211
+ #
212
+ # @return [String]
213
+ #
214
+ def nonstandard_lro_require
215
+ ruby_file_path @api, "#{service_name_full}::#{nonstandard_lro_name}"
216
+ end
217
+
218
+ ##
219
+ # The method to use for quick start samples. Normally this is simply the
220
+ # first non-client-streaming method defined, but it can be overridden via
221
+ # a gem config.
222
+ #
223
+ # @return [Gapic::Presenters::MethodRestPresenter] if there is a method
224
+ # appropriatke for quick start
225
+ # @return [nil] if there is no method appropriate for quick start
226
+ #
227
+ def quick_start_method
228
+ main_service.quick_start_method&.rest
229
+ end
230
+
231
+ ##
232
+ # @return [Enumerable<Gapic::Presenters::MethodPresenter>]
233
+ #
234
+ def methods
235
+ main_service.methods
236
+ end
130
237
 
131
238
  private
132
239
 
@@ -52,7 +52,7 @@ module Gapic
52
52
  end
53
53
 
54
54
  def require_path
55
- @method_presenter.service.service_require
55
+ @method_presenter.service.package.package_require
56
56
  end
57
57
 
58
58
  def client_type
@@ -94,6 +94,7 @@ module Gapic
94
94
  api_id ||= final_name
95
95
  api_version = "v0"
96
96
  end
97
+ api_id = api_id.downcase.gsub(/[^a-z0-9]/, "")
97
98
  service_name = @method_presenter.service.module_name
98
99
  method_name = @method_presenter.method.name
99
100
  "#{api_id}_#{api_version}_generated_#{service_name}_#{method_name}_sync"
@@ -14,6 +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/model"
17
18
  require "gapic/presenters/enum_presenter"
18
19
  require "gapic/presenters/enum_value_presenter"
19
20
  require "gapic/presenters/field_presenter"
@@ -25,8 +26,9 @@ require "gapic/presenters/method_rest_presenter"
25
26
  require "gapic/presenters/package_presenter"
26
27
  require "gapic/presenters/resource_presenter"
27
28
  require "gapic/presenters/sample_presenter"
29
+ require "gapic/presenters/service/lro_client_presenter"
28
30
  require "gapic/presenters/service_presenter"
29
- require "gapic/presenters/service_config_presenter"
31
+ require "gapic/presenters/grpc_service_config_presenter"
30
32
  require "gapic/presenters/service_rest_presenter"
31
33
  require "gapic/presenters/snippet_presenter"
32
34
 
@@ -20,6 +20,7 @@ require "gapic/generators/default_generator_parameters"
20
20
  require "gapic/schema/loader"
21
21
  require "gapic/schema/request_param_parser"
22
22
  require "gapic/grpc_service_config/parser"
23
+ require "gapic/schema/service_config_parser"
23
24
 
24
25
  module Gapic
25
26
  module Schema
@@ -60,6 +61,7 @@ module Gapic
60
61
  @files.each { |f| f.parent = self }
61
62
  @configuration = configuration
62
63
  @resource_types = analyze_resources
64
+ @nonstandard_lro_services = analyze_nonstandard_lros
63
65
 
64
66
  parameter_schema ||= Gapic::Generators::DefaultGeneratorParameters.default_schema
65
67
  @protoc_parameters = parse_parameter request.parameter, parameter_schema, error_output
@@ -114,14 +116,17 @@ module Gapic
114
116
  configuration[:overrides][:service].fetch str, str
115
117
  end
116
118
 
119
+ # @return [Enumerable<Gapic::Schema::File>]
117
120
  def generate_files
118
121
  @files.select(&:generate?)
119
122
  end
120
123
 
124
+ # @return [Enumerable<Gapic::Schema::Service>]
121
125
  def services
122
126
  @files.map(&:services).flatten
123
127
  end
124
128
 
129
+ # @return [Enumerable<Gapic::Schema::Message>]
125
130
  def messages
126
131
  @files.map(&:messages).flatten
127
132
  end
@@ -247,7 +252,12 @@ module Gapic
247
252
 
248
253
  # Whether to generate standalone snippets
249
254
  def generate_standalone_snippets?
250
- configuration[:generate_standalone_snippets] ||= false
255
+ configuration.fetch :generate_standalone_snippets, true
256
+ end
257
+
258
+ # Whether to generate inline documentation snippets
259
+ def generate_yardoc_snippets?
260
+ configuration.fetch :generate_yardoc_snippets, true
251
261
  end
252
262
 
253
263
  # Whether to generate gapic metadata (drift manifest) file
@@ -288,6 +298,22 @@ module Gapic
288
298
  @grpc_service_config ||= Gapic::GrpcServiceConfig::Parser.parse grpc_service_config_raw
289
299
  end
290
300
 
301
+ # Raw text of the service.yaml if given as a parameter
302
+ # or nil if no parameter given
303
+ # @return [String]
304
+ def service_config_raw
305
+ @service_config_raw ||= begin
306
+ filename = protoc_options[:service_yaml]
307
+ ::File.read filename if filename
308
+ end
309
+ end
310
+
311
+ # Parsed service config
312
+ # @return [Google::Api::Service]
313
+ def service_config
314
+ @service_config ||= Gapic::Schema::ServiceConfigParser.parse_service_yaml service_config_raw
315
+ end
316
+
291
317
  # Get a resource given its type string
292
318
  def lookup_resource_type resource_type
293
319
  @resource_types[resource_type]
@@ -313,6 +339,21 @@ module Gapic
313
339
  services.find { |s| s.address == addr }
314
340
  end
315
341
 
342
+ ##
343
+ # Returns a model for the nonstandard LRO for a given service
344
+ # The `analyze_nonstandard_lros` method fills in the model cache
345
+ #
346
+ # @param service_full_name [String]
347
+ #
348
+ # @return [Gapic::Model::Service::NonstandardLroProvider, Gapic::Model::Service::NoNonstandardLro]
349
+ def nonstandard_lro_model_for service_full_name
350
+ if @nonstandard_lro_services.key? service_full_name
351
+ @nonstandard_lro_services[service_full_name]
352
+ else
353
+ Gapic::Model::Service::NoNonstandardLro.instance
354
+ end
355
+ end
356
+
316
357
  ##
317
358
  # Whether configuration has an override for the wrapper gem name
318
359
  # @return [Boolean]
@@ -323,7 +364,7 @@ module Gapic
323
364
 
324
365
  ##
325
366
  # An override for the wrapper gem name in the configuration
326
- # @return [String, Nil]
367
+ # @return [String, nil]
327
368
  def wrapper_gem_name_override
328
369
  return nil unless wrapper_gem_name_override?
329
370
  return nil if configuration[:overrides][:wrapper_gem_name].nil?
@@ -393,6 +434,24 @@ module Gapic
393
434
  end
394
435
  end
395
436
 
437
+ ##
438
+ # Does a pre-analysis of the nonstandard LRO for every service.
439
+ # For the services that provide nonstandard LRO functionality, cashes a model for the future use
440
+ #
441
+ # @return [Hash<String, Gapic::Model::Service::NonstandardLroProvider>]
442
+ def analyze_nonstandard_lros
443
+ service_registry = {}
444
+
445
+ @files.each do |file|
446
+ file.services.each do |service|
447
+ nonstandard_lro = Gapic::Model::Service.parse_nonstandard_lro service
448
+ service_registry[service.full_name] = nonstandard_lro if nonstandard_lro
449
+ end
450
+ end
451
+
452
+ service_registry
453
+ end
454
+
396
455
  # Parse a comma-delimited list of equals-delimited lists of strings, while
397
456
  # mapping backslash-escaped commas and equal signs to literal characters.
398
457
  # @param str [String]
@@ -18,6 +18,8 @@ require "google/api/annotations.pb"
18
18
  require "google/api/client.pb"
19
19
  require "google/api/field_behavior.pb"
20
20
  require "google/api/resource.pb"
21
+ require "google/api/routing.pb"
22
+ require "google/cloud/extended_operations.pb"
21
23
  require "google/longrunning/operations.pb"
22
24
  require "google/protobuf/descriptor.pb"
23
25
  require "gapic/schema/wrappers"
@@ -36,8 +38,9 @@ module Gapic
36
38
  #
37
39
  # @param file_descriptor [Google::Protobuf::FileDescriptorProto] the
38
40
  # descriptor of the proto file.
39
- # @oaram file_to_generate [Boolean] Whether this file is to be
41
+ # @param file_to_generate [Boolean] Whether this file is to be
40
42
  # generated.
43
+ # @return [Gapic::Schema::File]
41
44
  def load_file file_descriptor, file_to_generate
42
45
  # Setup.
43
46
  address = file_descriptor.package.split "."