genio 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9bb45aea9bf6c8657f94daa34c0dfd990502105c
4
+ data.tar.gz: a610a55af427c649baf47c4a50066bb477e40f55
5
+ SHA512:
6
+ metadata.gz: 631cf5acf014e5da47a3539e5d6c89eab628e13a6a177e5edd91ae373428b5be600bb65cb6c8e97b9bba6b51f92da8f4e41c15cf0c612d4b43bbc0fb997ca18f
7
+ data.tar.gz: e82403ec32a277715a79767a5f2c25f316562d0c0ae524c0314f6bc55922dc9d400aee02a001bf05715a68b3c026730615408d5e38923e0dbc67614622bb04ea
@@ -0,0 +1,54 @@
1
+ Apache License
2
+
3
+ Version 2.0, January 2004
4
+
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
16
+
17
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
18
+
19
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
20
+
21
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
22
+
23
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
24
+
25
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
26
+
27
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
28
+
29
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
30
+
31
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
32
+
33
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
34
+
35
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
36
+
37
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
38
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
39
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
40
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
41
+
42
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
43
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
44
+
45
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
46
+
47
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
48
+
49
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
50
+
51
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
52
+
53
+ END OF TERMS AND CONDITIONS
54
+
@@ -0,0 +1,55 @@
1
+ Genio is an easy to use code generation tool that can generate API client libraries in multiple programming languages. Genio comes with in-built support for multiple API specification formats - WSDLs, WADLs and the [Google discovery format](https://developers.google.com/discovery) but also allows you to plug in parsers for additional specification formats. It uses a simple templating system that allows easy customization of the generated code.
2
+
3
+
4
+ ## Requirements
5
+
6
+ * Ruby 1.9.3 or above
7
+
8
+ ## Installation
9
+
10
+ ```sh
11
+ gem install genio
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ With genio installed on your local machine, run
17
+
18
+ ```sh
19
+ genio <java|php|dotnet> --schema=path/to/specification [--output-path=output/directory]
20
+ ```
21
+
22
+ With the --schema argument option, Genio will attempt to guess the specification type based on the file extension of the argument. If you follow non-standard naming convention for your files, please use the --wsdl / --wadl / --json-schema arguments instead.
23
+
24
+ Once you have generated source files with genio, you can use them in your project in conjunction with PayPal's core SDK libraries. You can take a look at the sample [hello world projects](https://github.com/paypal/genio-sample/tree/master/hello-world) and read language specific instructions [here](https://github.com/paypal/genio/wiki/Using-genio).
25
+
26
+ ## Supported languages
27
+
28
+ Genio comes with templates for the following programming languages. Support for other languages to follow soon.
29
+
30
+ * java
31
+ * dotnet
32
+ * php
33
+
34
+ ## Supported formats
35
+
36
+ * WADL (`--wadl=path/to/schema.wadl`)
37
+ * Google discovery format (`--json-schema=path/to/schema.json`)
38
+ * WSDL (`--wsdl=path/to/schema.wsdl`)
39
+
40
+ ## Upcoming features
41
+
42
+ We have plans to add the following soon
43
+
44
+ * Automatic API reference generation from spec.
45
+ * Support for JSON schema Version 4 specification.
46
+
47
+ ## Documentation
48
+
49
+ * [Genio internals](https://github.com/paypal/genio/wiki/Genio-internals)
50
+
51
+ ## Contributions and issues
52
+
53
+ We will be happy to accept contributions by way of templates for additional languages and parsers for other API specification formats. Please submit a pull request if you would like to contribute.
54
+
55
+ If you have a feature ask or an issue to report, please file an [issue](https://github.com/paypal/genio/issues/new) on github.
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #
4
+ # Copyright 2013 PayPal Inc.
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
+ # http://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
+ #
19
+ require "genio"
20
+
21
+ Genio::Tasks.start(ARGV)
@@ -0,0 +1,35 @@
1
+ #
2
+ # Copyright 2013 PayPal Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ #
17
+ require "genio/version"
18
+
19
+ module Genio
20
+ autoload :Template, "genio/template"
21
+ autoload :Logging, "genio/logging"
22
+ autoload :Tasks, "genio/tasks"
23
+
24
+ module Helper
25
+ autoload :Base, "genio/helper/base"
26
+ autoload :PHP, "genio/helper/php"
27
+ autoload :DotNet, "genio/helper/dot_net"
28
+ autoload :Java, "genio/helper/java"
29
+ end
30
+
31
+ module Util
32
+ autoload :NamespaceHelper, "genio/util/namespace_helper"
33
+ autoload :SchemaHelper, "genio/util/schema_helper"
34
+ end
35
+ end
@@ -0,0 +1,101 @@
1
+ #
2
+ # Copyright 2013 PayPal Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ #
17
+ require 'active_support/all'
18
+
19
+ module Genio
20
+ module Helper
21
+ module Base
22
+
23
+ # Checks for static modifier, currently all Get methods
24
+ # are considered static
25
+ def is_static_method(property)
26
+ property.type == "GET"
27
+ end
28
+
29
+ # Returns true if this.getId() should be include in the
30
+ # API calls - Applies to non-static methods which have a
31
+ # path variable which is the host class
32
+ # e.g /v1/users/{user} or /v1/users/{user-id}
33
+ def check_host_id(classname, property)
34
+ !is_static_method(property) && property.path.gsub(/-/, "").gsub(/_/, "") =~ /\{(#{classname}[^\}]*)\}/i
35
+ end
36
+
37
+ # Returns true if data_type is a input type used in
38
+ # a service operation or header, false otherwise
39
+ def is_operation_input(data_type, schema)
40
+ schema.services.each do |service_name, servicedef|
41
+ servicedef.operations.each do |operation_name, oper_definition|
42
+ if (data_type.name == oper_definition.request || data_type.name == oper_definition.header)
43
+ return true
44
+ end
45
+ end
46
+ end
47
+ return false
48
+ end
49
+
50
+ # Determine if type_name is a complex type
51
+ # returns true if its complex, false otherwise
52
+ def is_complex_type(type_name, schema)
53
+ return true if schema.data_types[type_name]
54
+ return false
55
+ end
56
+
57
+ # Determine if type_name is a enum type
58
+ # returns true if its an enum, false otherwise
59
+ def is_enum_type(type_name, schema)
60
+ return true if schema.enum_types[type_name]
61
+ return false
62
+ end
63
+
64
+ # Retruns true if the data_type has a attribute member
65
+ def contains_attribute(data_type)
66
+ data_type.properties.each do |name, definition|
67
+ return true if definition.attribute
68
+ end
69
+ return false
70
+ end
71
+
72
+ # Determines if XML elements should be qualified
73
+ # using prefix; reading elementformdefault attributes
74
+ # from schemas
75
+ def should_qualify_name(package, schema)
76
+ return true if package.blank?
77
+ namespace = schema.namespaces.find{|ns, prefix| prefix == package}
78
+ namespace and schema.element_form_defaults[namespace.first] == "qualified"
79
+ end
80
+
81
+ # Word wraps comment
82
+ def comment_wrap(text, line_width, prefix='')
83
+ return prefix if ( (!text.kind_of? String) || (text.strip.length == 0) )
84
+ text.gsub(/(.{1,#{line_width}})(\s+|$)/, prefix + "\\1\n").gsub(/\n$/, "")
85
+ end
86
+
87
+ # Returns list of all top-level input types
88
+ # defined in this service
89
+ def request_types(schema)
90
+ @request_types || schema.services.values.map{|service| service.operations.values.map{|opt| opt.request } }.flatten
91
+ end
92
+
93
+ # Returns list of all header types
94
+ # defined in this service
95
+ def header_types(schema)
96
+ @request_types || schema.services.values.map{|service| service.operations.values.map{|opt| opt.header } }.flatten
97
+ end
98
+
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,410 @@
1
+ #
2
+ # Copyright 2013 PayPal Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ #
17
+ module Genio
18
+ module Helper
19
+ module DotNet
20
+
21
+ include Base
22
+
23
+ #Key/Reserved Words
24
+ KeyWords = [
25
+ "abstract",
26
+ "as",
27
+ "base",
28
+ "bool",
29
+ "break",
30
+ "byte",
31
+ "case",
32
+ "catch",
33
+ "char",
34
+ "checked",
35
+ "class",
36
+ "const",
37
+ "continue",
38
+ "decimal",
39
+ "default",
40
+ "delegate",
41
+ "do",
42
+ "double",
43
+ "else",
44
+ "enum",
45
+ "event",
46
+ "explicit",
47
+ "extern",
48
+ "false",
49
+ "finally",
50
+ "fixed",
51
+ "float",
52
+ "for",
53
+ "foreach",
54
+ "goto",
55
+ "if",
56
+ "implicit",
57
+ "in",
58
+ "int",
59
+ "interface",
60
+ "internal",
61
+ "is",
62
+ "lock",
63
+ "long",
64
+ "namespace",
65
+ "new",
66
+ "null",
67
+ "object",
68
+ "operator",
69
+ "out",
70
+ "override",
71
+ "params",
72
+ "private",
73
+ "protected",
74
+ "public",
75
+ "readonly",
76
+ "ref",
77
+ "return",
78
+ "sbyte",
79
+ "sealed",
80
+ "short",
81
+ "sizeof",
82
+ "stackalloc",
83
+ "static",
84
+ "string",
85
+ "struct",
86
+ "switch",
87
+ "this",
88
+ "throw",
89
+ "true",
90
+ "try",
91
+ "typeof",
92
+ "uint",
93
+ "ulong",
94
+ "unchecked",
95
+ "unsafe",
96
+ "ushort",
97
+ "using",
98
+ "virtual",
99
+ "void",
100
+ "volatile",
101
+ "while"
102
+ ]
103
+
104
+ # Keyword substitute hash
105
+ KeywordsSubstitute = {
106
+ "readonly" => "readOnly"
107
+ }
108
+
109
+ # Static resource imports
110
+ # Resource class which have REST operation enabled
111
+ # depend on these core classes
112
+ ServiceImportREST = [
113
+ "PayPal",
114
+ "PayPal.Util",
115
+ "System.Collections.Generic"
116
+ ]
117
+
118
+ # Static resource imports for WSDL
119
+ # service class; they depend on these core classes
120
+ ServiceImportWSDL = [
121
+ "PayPal",
122
+ "PayPal.Util",
123
+ "System.Collections",
124
+ "System.Collections.Generic",
125
+ "System.Xml"
126
+ ]
127
+
128
+ # Static resource imports for WSDL
129
+ # stub classes; they depend on these core classes
130
+ StubImportWSDL = [
131
+ "PayPal.Util",
132
+ "System.Globalization",
133
+ "System.Text",
134
+ "System.Xml",
135
+ ]
136
+
137
+ # Spec Types to Dotnet Types conversion map
138
+ BasicTypes = { "int" => "int", "integer" => "int", "positiveInteger" => "int", "nonNegativeInteger" => "int", "long" => "long", "double" => "double", "decimal" => "double", "float" => "float", "boolean" => "bool", "string" => "string", "dateTime" => "string", "date" => "string", "number" => "double", "object" => "object", "token" => "string", "duration" => "string", "anyURI" => "string", "date_time" => "string", "base64Binary" => "string", "time" => "string" }
139
+
140
+ # Returns the type of a member
141
+ # If the passed in parameter is one of Basic types
142
+ # return the corresponding BasicType, else
143
+ # the parameter is returned unmodified
144
+ def find_basic_type(key)
145
+ only_basic_type(key) || key
146
+ end
147
+
148
+ # Returns the corresponding basic
149
+ # data type in Dotnet
150
+ def only_basic_type(key)
151
+ BasicTypes[key.camelcase(:lower)]
152
+ end
153
+
154
+ # Determines if a type of a property is nullable
155
+ # Enum types are treated nullable
156
+ def is_nullable_type(property)
157
+ if ['int', 'long', 'double', 'float', 'bool'].include? find_basic_type(property.type)
158
+ return true
159
+ elsif schema.enum_types[property.type]
160
+ return true
161
+ else
162
+ false
163
+ end
164
+ end
165
+
166
+ # Returns the property type name to be used as the
167
+ # type name in enclosing Class
168
+ def get_property_class(property, classname = nil)
169
+ type = find_basic_type(property.type)
170
+
171
+ # If type is Self (as per Spec) treat is as HostType
172
+ # classname is always in camelcase
173
+ type = classname if type == "self"
174
+ type = "List<#{type}>" if property.array
175
+ type
176
+ end
177
+
178
+ # Returns the imports for the Class
179
+ def imports(data_type, schema, package, classname, schema_format, operation_input = false)
180
+ pkg = options[:namespace]
181
+ pkg = capitalize_package(remove_tld_in_package(convert_ns_to_package(pkg))) if pkg.present?
182
+
183
+ # mandatory references
184
+ list = ["System"]
185
+
186
+ if (schema_format == "rest")
187
+ list.push("Newtonsoft.Json")
188
+ list.push("Newtonsoft.Json.Serialization")
189
+ end
190
+
191
+ list.push("PayPal")
192
+ data_type.properties.each do |name, property|
193
+ type = schema.data_types[property.type] || schema.enum_types[property.type]
194
+ if (type)
195
+ if (pkg.present?)
196
+ list.push(pkg)
197
+ else
198
+ # TODO fix this when definition namespace fixes
199
+ defpkg = capitalize_package(remove_tld_in_package(convert_ns_to_package(type.package || package)))
200
+ list.push(defpkg)
201
+ end
202
+ end
203
+ list.push("System.Collections") if property.array
204
+ list.push("System.Collections.Generic") if property.array
205
+ end
206
+
207
+ # Add references for members of parent datatype
208
+ # flatten classes for wsdl
209
+ if schema.instance_of? Genio::Parser::Format::Wsdl
210
+ x_type = schema.data_types[data_type.extends]
211
+ while x_type
212
+ x_type.properties.each do |name, property|
213
+ type = schema.data_types[property.type] || schema.enum_types[property.type]
214
+ if (type)
215
+ if (pkg.present?)
216
+ list.push(pkg)
217
+ else
218
+ # TODO fix this when definition namespace fixes
219
+ defpkg = capitalize_package(remove_tld_in_package(convert_ns_to_package(type.package || package)))
220
+ list.push(defpkg)
221
+ end
222
+ end
223
+ list.push("System.Collections") if property.array
224
+ list.push("System.Collections.Generic") if property.array
225
+ end
226
+ x_type = schema.data_types[x_type.extends]
227
+ end
228
+ end
229
+
230
+ # Add reference for request and response type
231
+ # of operations: Applies to REST services
232
+ service = schema.services[classname]
233
+ if service
234
+ service.operations.each do |name, operation|
235
+ if operation.response
236
+ if (pkg.present?)
237
+ list.push(pkg)
238
+ else
239
+ list.push(capitalize_package(remove_tld_in_package(convert_ns_to_package(schema.data_types[operation.response].try(:package) || package))))
240
+ end
241
+ end
242
+ if operation.request
243
+ if (pkg.present?)
244
+ list.push(pkg)
245
+ else
246
+ list.push(capitalize_package(remove_tld_in_package(convert_ns_to_package(schema.data_types[operation.request].try(:package) || package))))
247
+ end
248
+ end
249
+ end
250
+ end
251
+
252
+ list += ServiceImportREST if schema.services[classname]
253
+ list += StubImportWSDL if (schema_format == "soap")
254
+ #TODO fix for XMLSerialization
255
+ list += [] if (operation_input && (schema_format == "soap"))
256
+ list.uniq.sort
257
+ end
258
+
259
+ # Generate imports for WSDL Service class
260
+ def service_imports(schema, service, package)
261
+ pkg = options[:namespace]
262
+ pkg = capitalize_package(remove_tld_in_package(convert_ns_to_package(pkg))) if pkg.present?
263
+
264
+ # mandatory references
265
+ list = ["System"]
266
+
267
+ # import request and response of operations
268
+ service.operations.each do |name, definition|
269
+ if (definition.request_property)
270
+ if (pkg.present?)
271
+ list.push(pkg)
272
+ else
273
+ list.push(capitalize_package(remove_tld_in_package(convert_ns_to_package(schema.data_types[validate_class_name(definition.request_property.type)].package || package))))
274
+ end
275
+ end
276
+ if (definition.response_property)
277
+ if (pkg.present?)
278
+ list.push(pkg)
279
+ else
280
+ list.push(capitalize_package(remove_tld_in_package(convert_ns_to_package(schema.data_types[validate_class_name(definition.response_property.type)].package || package))))
281
+ end
282
+ end
283
+ if (definition.fault_property)
284
+ if (pkg.present?)
285
+ list.push(pkg)
286
+ else
287
+ list.push(capitalize_package(remove_tld_in_package(convert_ns_to_package(schema.data_types[validate_class_name(definition.fault_property.type)].package || package))))
288
+ end
289
+ end
290
+ end
291
+
292
+ # mandatory imports
293
+ list += ServiceImportWSDL
294
+ list.uniq.sort
295
+ end
296
+
297
+ # Replaces any "-" present in the path URI to valid "_"
298
+ # used while replacing placeholders with exact values
299
+ def validate_path(path)
300
+ path.gsub(/\{([^}]*)\}/){|match| "\{#{validate_property_name($1)}\}" }
301
+ end
302
+
303
+ # Replaces '-' with '_' and CamelCase(s) them [DotNet]
304
+ def validate_class_name(name)
305
+ only_basic_type(name) || name.gsub(/-/, "_").camelcase
306
+ end
307
+
308
+ # Replaces '-' with '_',
309
+ # used for valid property names [DotNet]
310
+ # replaces keywords with substitutes form KeywordsSubstitute
311
+ def validate_property_name(name, camel = false)
312
+ if camel
313
+ valid_name = name.gsub(/-/, "_").camelcase
314
+ else
315
+ valid_name = name.gsub(/-/, "_")
316
+ end
317
+ if KeyWords.include? valid_name
318
+ valid_name = KeywordsSubstitute[valid_name]
319
+ end
320
+ valid_name
321
+ end
322
+
323
+ # Replaces '-' and spaces with '_'
324
+ # used for valid enum names [DotNet]
325
+ def validate_enum_name(name)
326
+ name.gsub(/[-\s]/, "_").sub(/^\d/, '_\0')
327
+ end
328
+
329
+ # Replaces '-' with '_' and camelCase(s) them
330
+ # used for valid property names as method/constructor
331
+ # arguments [DotNet]
332
+ def validate_property_as_argument(name)
333
+ name.gsub(/-/, "_").camelcase(:lower)
334
+ end
335
+
336
+ # Prepends do to method names that are keywords
337
+ def validate_method_name(name)
338
+ KeyWords.include?(name.camelcase(:lower)) ? "Do#{name.gsub(/-/, '_').camelcase}" : name.gsub(/-/, '_').camelcase
339
+ end
340
+
341
+ # Generate method formal parameters for REST API calls
342
+ def form_rest_api_args(classname, property, name)
343
+ arguments = {}
344
+ property.path.scan(/{([^}]*)}/).each do |name, etc|
345
+ if is_static_method(property) or validate_class_name(name) !~ /^#{classname}/i
346
+ arguments[validate_property_as_argument(name)] = "string"
347
+ end
348
+ end
349
+ if property.request and property.request != classname
350
+ arguments[validate_property_as_argument(property.request)] = property.request
351
+ end
352
+ if property.type == 'GET' or property.type == 'HEAD' or property.type == 'DELETE'
353
+ arguments["queryParameters"] = "Dictionary<string, string>"
354
+ end
355
+ arguments
356
+ end
357
+
358
+ # Generates a map of parameters for placeholders used
359
+ # to process path URI
360
+ def generate_format_hash(classname, property, resourcePath)
361
+ map = {}
362
+ resourcePath.scan(/\{([^}]*)\}/) { |name, etc|
363
+ if (name.gsub(/-/, "").gsub(/_/, "").match(/^#{classname}.*/i) and !is_static_method(property))
364
+ map[name] = 'this.id'
365
+ else
366
+ map[name] = validate_property_as_argument(name)
367
+ end
368
+ }
369
+ map
370
+ end
371
+
372
+ # Returns the expression to set for payLoad in the API call
373
+ def get_payload(classname, property)
374
+ payLoad = '""';
375
+ if !is_static_method(property)
376
+ if property.request == classname
377
+ payLoad = "this.ConvertToJson()"
378
+ elsif property.request
379
+ payLoad = validate_property_as_argument(property.request) + ".ConvertToJson()"
380
+ end
381
+ end
382
+ payLoad
383
+ end
384
+
385
+ # Returns the name used during serialization for types
386
+ # that extend Serializer interface
387
+ def get_rootname_serialization(data_type, schema)
388
+ schema.services.each do |service_name, servicedef|
389
+ servicedef.operations.each do |operation_name, oper_definition|
390
+ if (data_type.name == oper_definition.request)
391
+ return (oper_definition.request_property.package + ":" + oper_definition.request_property.name)
392
+ elsif (data_type.name == oper_definition.header)
393
+ return (oper_definition.header_property.package + ":" + oper_definition.header_property.name)
394
+ end
395
+ end
396
+ end
397
+ end
398
+
399
+ # Returns a hash of arguments for wsdl operations
400
+ # including the request type and name
401
+ # hash is in the format of [name] = [type]
402
+ def get_wsdl_operation_arguments(operation_definition)
403
+ argument_hash = {}
404
+ argument_hash[validate_property_as_argument(operation_definition.request_property.name)] = operation_definition.request
405
+ argument_hash
406
+ end
407
+
408
+ end
409
+ end
410
+ end