gapic-generator 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +13 -0
  3. data/CHANGELOG.md +26 -0
  4. data/CODE_OF_CONDUCT.md +43 -0
  5. data/CONTRIBUTING.md +28 -0
  6. data/LICENSE +202 -0
  7. data/README.md +72 -0
  8. data/bin/gapic-generator +103 -0
  9. data/bin/protoc-gen-ruby_gapic +33 -0
  10. data/default-rubocop.yml +10 -0
  11. data/gem_templates/binary.erb +20 -0
  12. data/gem_templates/dockerfile.erb +39 -0
  13. data/gem_templates/entrypoint.erb +24 -0
  14. data/gem_templates/gapic_sh.erb +97 -0
  15. data/gem_templates/gemfile.erb +8 -0
  16. data/gem_templates/gemspec.erb +36 -0
  17. data/gem_templates/generator.erb +37 -0
  18. data/gem_templates/gitignore.erb +10 -0
  19. data/gem_templates/rakefile.erb +29 -0
  20. data/gem_templates/readme.erb +69 -0
  21. data/gem_templates/rubocop.erb +16 -0
  22. data/gem_templates/shared/_header.erb +4 -0
  23. data/gem_templates/shared/_license.erb +13 -0
  24. data/gem_templates/shared/_warning.erb +1 -0
  25. data/gem_templates/test_generator.erb +13 -0
  26. data/gem_templates/test_helper.erb +25 -0
  27. data/gem_templates/version.erb +10 -0
  28. data/lib/gapic/file_formatter.rb +62 -0
  29. data/lib/gapic/gem_builder.rb +98 -0
  30. data/lib/gapic/generator.rb +30 -0
  31. data/lib/gapic/generator/version.rb +21 -0
  32. data/lib/gapic/generators/base_generator.rb +91 -0
  33. data/lib/gapic/generators/default_generator.rb +101 -0
  34. data/lib/gapic/grpc_service_config/method_config.rb +49 -0
  35. data/lib/gapic/grpc_service_config/parser.rb +196 -0
  36. data/lib/gapic/grpc_service_config/parsing_error.rb +25 -0
  37. data/lib/gapic/grpc_service_config/retry_policy.rb +51 -0
  38. data/lib/gapic/grpc_service_config/service_config.rb +42 -0
  39. data/lib/gapic/path_template.rb +35 -0
  40. data/lib/gapic/path_template/parser.rb +83 -0
  41. data/lib/gapic/path_template/segment.rb +67 -0
  42. data/lib/gapic/resource_lookup.rb +91 -0
  43. data/lib/gapic/runner.rb +76 -0
  44. data/lib/gapic/schema.rb +17 -0
  45. data/lib/gapic/schema/api.rb +264 -0
  46. data/lib/gapic/schema/loader.rb +269 -0
  47. data/lib/gapic/schema/wrappers.rb +718 -0
  48. data/lib/google/api/annotations.pb.rb +39 -0
  49. data/lib/google/api/client.pb.rb +43 -0
  50. data/lib/google/api/field_behavior.pb.rb +51 -0
  51. data/lib/google/api/http.pb.rb +60 -0
  52. data/lib/google/api/resource.pb.rb +80 -0
  53. data/lib/google/longrunning/operations.pb.rb +115 -0
  54. data/lib/google/protobuf/any.pb.rb +40 -0
  55. data/lib/google/protobuf/compiler/plugin.pb.rb +72 -0
  56. data/lib/google/protobuf/descriptor.pb.rb +359 -0
  57. data/lib/google/protobuf/empty.pb.rb +36 -0
  58. data/lib/google/rpc/status.pb.rb +46 -0
  59. data/templates/default/gem/_version.erb +2 -0
  60. data/templates/default/gem/changelog.erb +3 -0
  61. data/templates/default/gem/gemfile.erb +4 -0
  62. data/templates/default/gem/gemspec.erb +37 -0
  63. data/templates/default/gem/gitignore.erb +18 -0
  64. data/templates/default/gem/license.erb +22 -0
  65. data/templates/default/gem/rakefile.erb +27 -0
  66. data/templates/default/gem/readme.erb +24 -0
  67. data/templates/default/gem/rubocop.erb +59 -0
  68. data/templates/default/gem/version.erb +6 -0
  69. data/templates/default/gem/yardopts.erb +12 -0
  70. data/templates/default/helpers/default_helper.rb +45 -0
  71. data/templates/default/helpers/filepath_helper.rb +38 -0
  72. data/templates/default/helpers/namespace_helper.rb +44 -0
  73. data/templates/default/helpers/presenter_helper.rb +24 -0
  74. data/templates/default/helpers/presenters/enum_presenter.rb +35 -0
  75. data/templates/default/helpers/presenters/enum_value_presenter.rb +33 -0
  76. data/templates/default/helpers/presenters/field_presenter.rb +146 -0
  77. data/templates/default/helpers/presenters/file_presenter.rb +53 -0
  78. data/templates/default/helpers/presenters/gem_presenter.rb +140 -0
  79. data/templates/default/helpers/presenters/message_presenter.rb +66 -0
  80. data/templates/default/helpers/presenters/method_presenter.rb +293 -0
  81. data/templates/default/helpers/presenters/package_presenter.rb +65 -0
  82. data/templates/default/helpers/presenters/resource_presenter.rb +92 -0
  83. data/templates/default/helpers/presenters/sample_presenter.rb +74 -0
  84. data/templates/default/helpers/presenters/service_presenter.rb +276 -0
  85. data/templates/default/layouts/_ruby.erb +20 -0
  86. data/templates/default/package.erb +6 -0
  87. data/templates/default/proto_docs/_enum.erb +13 -0
  88. data/templates/default/proto_docs/_message.erb +23 -0
  89. data/templates/default/proto_docs/_proto_file.erb +9 -0
  90. data/templates/default/proto_docs/proto_file.erb +6 -0
  91. data/templates/default/proto_docs/readme.erb +5 -0
  92. data/templates/default/service.erb +8 -0
  93. data/templates/default/service/client.erb +6 -0
  94. data/templates/default/service/client/_client.erb +137 -0
  95. data/templates/default/service/client/_config.erb +155 -0
  96. data/templates/default/service/client/_credentials.erb +21 -0
  97. data/templates/default/service/client/_helpers.erb +9 -0
  98. data/templates/default/service/client/_operations.erb +88 -0
  99. data/templates/default/service/client/_paths.erb +8 -0
  100. data/templates/default/service/client/_requires.erb +1 -0
  101. data/templates/default/service/client/_resource.erb +6 -0
  102. data/templates/default/service/client/_self_configure.erb +29 -0
  103. data/templates/default/service/client/_self_configure_retry_policy.erb +15 -0
  104. data/templates/default/service/client/method/_def.erb +21 -0
  105. data/templates/default/service/client/method/def/_options_defaults.erb +29 -0
  106. data/templates/default/service/client/method/def/_request.erb +6 -0
  107. data/templates/default/service/client/method/def/_request_normal.erb +4 -0
  108. data/templates/default/service/client/method/def/_request_streaming.erb +9 -0
  109. data/templates/default/service/client/method/def/_rescue.erb +1 -0
  110. data/templates/default/service/client/method/def/_response.erb +6 -0
  111. data/templates/default/service/client/method/def/_response_normal.erb +8 -0
  112. data/templates/default/service/client/method/def/_response_paged.erb +9 -0
  113. data/templates/default/service/client/method/docs/_error.erb +2 -0
  114. data/templates/default/service/client/method/docs/_request.erb +6 -0
  115. data/templates/default/service/client/method/docs/_request_field.erb +7 -0
  116. data/templates/default/service/client/method/docs/_request_normal.erb +20 -0
  117. data/templates/default/service/client/method/docs/_request_streaming.erb +5 -0
  118. data/templates/default/service/client/method/docs/_response.erb +6 -0
  119. data/templates/default/service/client/method/docs/_sample.erb +20 -0
  120. data/templates/default/service/client/method/docs/_sample_response.erb +24 -0
  121. data/templates/default/service/client/method/docs/_samples.erb +6 -0
  122. data/templates/default/service/client/method/docs/request_field/_arg.erb +10 -0
  123. data/templates/default/service/client/method/docs/request_field/_hash.erb +19 -0
  124. data/templates/default/service/client/method/docs/sample_response/_comment.erb +5 -0
  125. data/templates/default/service/client/method/docs/sample_response/_define.erb +2 -0
  126. data/templates/default/service/client/method/docs/sample_response/_loop.erb +12 -0
  127. data/templates/default/service/client/method/docs/sample_response/_print.erb +2 -0
  128. data/templates/default/service/client/method/docs/sample_response/_write_file.erb +2 -0
  129. data/templates/default/service/client/resource/_def.erb +6 -0
  130. data/templates/default/service/client/resource/_doc.erb +8 -0
  131. data/templates/default/service/client/resource/_multi.erb +28 -0
  132. data/templates/default/service/client/resource/_single.erb +11 -0
  133. data/templates/default/service/credentials.erb +6 -0
  134. data/templates/default/service/operations.erb +6 -0
  135. data/templates/default/service/paths.erb +6 -0
  136. data/templates/default/service/test/client.erb +24 -0
  137. data/templates/default/service/test/client_operations.erb +24 -0
  138. data/templates/default/service/test/method/_assert_response.erb +11 -0
  139. data/templates/default/service/test/method/_bidi.erb +100 -0
  140. data/templates/default/service/test/method/_client.erb +84 -0
  141. data/templates/default/service/test/method/_normal.erb +69 -0
  142. data/templates/default/service/test/method/_server.erb +85 -0
  143. data/templates/default/service/test/method/_setup.erb +21 -0
  144. data/templates/default/service/test/smoke.erb +12 -0
  145. data/templates/default/shared/_header.erb +4 -0
  146. data/templates/default/shared/_license.erb +21 -0
  147. data/templates/default/shared/_warning.erb +1 -0
  148. metadata +349 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7438b616f56c0f6c150b04d5facd7b77dea1ad988f4892bf2143f455a236653d
4
+ data.tar.gz: d3d836af88d5bc7ebc433c1a5da15690bd62ba2aabee75b8a647f2aa6e729287
5
+ SHA512:
6
+ metadata.gz: b8a752648197f7b2065bdcde4d9d5462660e8f073adcdd8687b1d9d8c55de34d86dfa69f8e118d51fb8d9a21d3a5c65a95586f633ed33b6db17529443eb429a8
7
+ data.tar.gz: 68dda5a00441de0c2e8645f9c3c0862d68bf8d96b5e379990c076edde6ea607466bdf95aeb9178e4e45c7be4b0384a94438745abd7596e9a90cd56eea4a5d289
@@ -0,0 +1,13 @@
1
+ --no-private
2
+ --title=GAPIC base generator
3
+ --markup markdown
4
+ --markup-provider redcarpet
5
+ --main README.md
6
+
7
+ ./lib/**/*.rb
8
+ -
9
+ CONTRIBUTING.md
10
+ CHANGELOG.md
11
+ CODE_OF_CONDUCT.md
12
+ LICENSE
13
+ README.md
@@ -0,0 +1,26 @@
1
+ # Release History for gapic-generator
2
+
3
+ ### 0.1.0 / 2020-03-07
4
+
5
+ * Generate default timeout and retry configs based on GRPC service configs.
6
+ * Send x-goog-user-project header based on quota_project_id.
7
+
8
+ ### 0.0.6 / 2020-03-03
9
+
10
+ * Generated config classes now have full yardoc
11
+ * Yardoc types for enums reference the fully namespaced module
12
+
13
+ ### 0.0.5 / 2020-02-25
14
+
15
+ * Require simplecov explicitly from generated test files
16
+
17
+ ### 0.0.4 / 2020-02-19
18
+
19
+ * Fixed generation of methods with empty requests.
20
+ * Fixed references to the gem version constant if the library name doesn't match the proto path.
21
+ * Disable line length cop for the generated gemspec file.
22
+
23
+ ### 0.0.3 / 2020-02-05
24
+
25
+ * Fixed generated test failures on map fields
26
+ * Fixed generated test failures on single-precision float fields
@@ -0,0 +1,43 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project,
4
+ and in the interest of fostering an open and welcoming community,
5
+ we pledge to respect all people who contribute through reporting issues,
6
+ posting feature requests, updating documentation,
7
+ submitting pull requests or patches, and other activities.
8
+
9
+ We are committed to making participation in this project
10
+ a harassment-free experience for everyone,
11
+ regardless of level of experience, gender, gender identity and expression,
12
+ sexual orientation, disability, personal appearance,
13
+ body size, race, ethnicity, age, religion, or nationality.
14
+
15
+ Examples of unacceptable behavior by participants include:
16
+
17
+ * The use of sexualized language or imagery
18
+ * Personal attacks
19
+ * Trolling or insulting/derogatory comments
20
+ * Public or private harassment
21
+ * Publishing other's private information,
22
+ such as physical or electronic
23
+ addresses, without explicit permission
24
+ * Other unethical or unprofessional conduct.
25
+
26
+ Project maintainers have the right and responsibility to remove, edit, or reject
27
+ comments, commits, code, wiki edits, issues, and other contributions
28
+ that are not aligned to this Code of Conduct.
29
+ By adopting this Code of Conduct,
30
+ project maintainers commit themselves to fairly and consistently
31
+ applying these principles to every aspect of managing this project.
32
+ Project maintainers who do not follow or enforce the Code of Conduct
33
+ may be permanently removed from the project team.
34
+
35
+ This code of conduct applies both within project spaces and in public spaces
36
+ when an individual is representing the project or its community.
37
+
38
+ Instances of abusive, harassing, or otherwise unacceptable behavior
39
+ may be reported by opening an issue
40
+ or contacting one or more of the project maintainers.
41
+
42
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0,
43
+ available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
@@ -0,0 +1,28 @@
1
+ # How to Contribute
2
+
3
+ We'd love to accept your patches and contributions to this project. There are
4
+ just a few small guidelines you need to follow.
5
+
6
+ ## Contributor License Agreement
7
+
8
+ Contributions to this project must be accompanied by a Contributor License
9
+ Agreement. You (or your employer) retain the copyright to your contribution;
10
+ this simply gives us permission to use and redistribute your contributions as
11
+ part of the project. Head over to <https://cla.developers.google.com/> to see
12
+ your current agreements on file or to sign a new one.
13
+
14
+ You generally only need to submit a CLA once, so if you've already submitted one
15
+ (even if it was for a different project), you probably don't need to do it
16
+ again.
17
+
18
+ ## Code reviews
19
+
20
+ All submissions, including submissions by project members, require review. We
21
+ use GitHub pull requests for this purpose. Consult
22
+ [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23
+ information on using pull requests.
24
+
25
+ ## Community Guidelines
26
+
27
+ This project follows [Google's Open Source Community
28
+ Guidelines](https://opensource.google.com/conduct/).
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,72 @@
1
+ # API Client Generator for Ruby
2
+
3
+ Create Ruby clients from a protocol buffer description of an API.
4
+
5
+ **Note** This project is a preview. Please try it out and let us know what you think,
6
+ but there are currently no guarantees of stability or support.
7
+
8
+ ## Usage
9
+
10
+ ### Install the Generator
11
+
12
+ This tool is in pre-alpha so it is not yet released to RubyGems.
13
+
14
+ ```sh
15
+ $ git clone https://github.com/googleapis/gapic-generator-ruby.git
16
+ $ cd gapic-generator-ruby
17
+ $ git submodule update --init
18
+ $ cd gapic-generator
19
+ $ bundle install
20
+ $ bundle exec rake install
21
+ $ which protoc-gen-ruby_gapic
22
+ > {Non-empty path}
23
+ ```
24
+
25
+ ### Generate an API
26
+
27
+ Installing this generator exposes `protoc-gen-ruby_gapic` on the PATH. By doing
28
+ so, it gives the protobuf compiler the CLI option `--ruby_gapic_out` on which
29
+ you can specify an output path for this generator.
30
+
31
+ If you want to experiment with an already-existing API, one example is available.
32
+ First you should get the protos and dependencies:
33
+
34
+ ```sh
35
+ $ git clone git@github.com:googleapis/api-common-protos.git
36
+ $ git clone git@github.com:googleapis/googleapis.git
37
+ ```
38
+
39
+ Now you're ready to compile the API:
40
+
41
+ ```sh
42
+ $ protoc google/cloud/vision/v1/*.proto \
43
+ --proto_path=api-common-protos/ \
44
+ --proto_path=googleapis/ \
45
+ --ruby_gapic_out=/dest/
46
+ ```
47
+
48
+ Or, if you don't have `protoc` installed, you can use `grpc_tools_ruby_protoc`
49
+ from the `grpc-tools` gem:
50
+
51
+ ```sh
52
+ $ gem install grpc-tools
53
+ $ grpc_tools_ruby_protoc google/cloud/vision/v1/*.proto \
54
+ --proto_path=api-common-protos/ \
55
+ --proto_path=googleapis/ \
56
+ --ruby_gapic_out=/dest/
57
+ ```
58
+
59
+ ## Contributing
60
+
61
+ Contributions to this library are always welcome and highly encouraged.
62
+
63
+ See the [CONTRIBUTING](CONTRIBUTING.md) documentation for more information on how to get started.
64
+
65
+ ## Versioning
66
+
67
+ This library is currently a **preview** with no guarantees of stability or support. Please get
68
+ involved and let us know if you find it useful and we'll work towards a stable version.
69
+
70
+ ## Disclaimer
71
+
72
+ This is not an official Google product.
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Copyright 2018 Google LLC
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # https://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ $stderr.sync = true
19
+ require "optparse"
20
+ require "fileutils"
21
+
22
+ def export_templates_to export_path
23
+ if File.exist? export_path
24
+ puts "Cannot export to an existing file path"
25
+ exit 1
26
+ end
27
+ FileUtils.mkdir_p export_path
28
+ source_dir = File.join File.dirname(__dir__), "templates", "default", "."
29
+ FileUtils.cp_r source_dir, export_path
30
+ end
31
+
32
+ def build_gem_to generator_name, output_path
33
+ if File.exist? output_path
34
+ puts "Cannot generate gem to an existing file path"
35
+ exit 1
36
+ end
37
+ FileUtils.mkdir_p output_path
38
+
39
+ require "gapic/gem_builder"
40
+
41
+ builder = Gapic::GemBuilder.new generator_name, output_path
42
+ builder.bootstrap
43
+ examples_path = File.join output_path, "example_templates", generator_name
44
+ export_templates_to examples_path
45
+ templates_path = File.join output_path, "templates", generator_name
46
+ FileUtils.mkdir_p templates_path
47
+ FileUtils.touch File.join(templates_path, ".gitkeep")
48
+
49
+ Dir.chdir output_path do
50
+ system "git init && git add . && git commit -m " \
51
+ "'Created new client generator gem using gapic-generator'"
52
+ end
53
+ end
54
+
55
+ ARGV << "-h" if ARGV.empty?
56
+
57
+ options = {}
58
+ OptionParser.new do |opts|
59
+ opts.banner = "Usage: gapic-generator [options]"
60
+
61
+ opts.on "-e", "--export export_path", String,
62
+ "Export templates to the given path" do |export_path|
63
+ options[:export] = export_path
64
+ end
65
+
66
+ opts.on "-g", "--gem name", String, "Generate a new rubygem" do |name|
67
+ options[:generator_name] = name
68
+ end
69
+
70
+ opts.on "--output path", String, "Set the gem output directory" do |path|
71
+ options[:output_path] = path
72
+ end
73
+
74
+ opts.on_tail "-h", "--help", "Show this message" do
75
+ puts opts
76
+ exit
77
+ end
78
+ end.parse!
79
+
80
+ if options[:export]
81
+ export_path = File.expand_path options[:export]
82
+
83
+ export_templates_to export_path
84
+
85
+ puts "Template files exported to #{export_path}"
86
+ puts "You can use these files when calling protoc with:"
87
+ puts ""
88
+ puts "$ GOOGLE_GAPIC_GENERATOR_RUBY_TEMPLATES=#{export_path} protoc ..."
89
+ end
90
+
91
+ if options[:generator_name]
92
+ generator_name = options[:generator_name]
93
+ unless generator_name =~ /^[a-z]([a-z_]*[a-z])?$/
94
+ puts "Generator name must be lower_snake_case"
95
+ exit 1
96
+ end
97
+ output_path = options[:output_path] || "gapic-generator-#{generator_name}"
98
+ output_path = File.expand_path output_path
99
+
100
+ build_gem_to generator_name, output_path
101
+
102
+ puts "Generator for #{generator_name} created at #{output_path}"
103
+ end