├── .gitignore
├── CONTRIBUTORS.md
├── Rakefile
├── lib
├── genio
│ ├── version.rb
│ ├── logging.rb
│ ├── util
│ │ ├── schema_helper.rb
│ │ └── namespace_helper.rb
│ ├── template.rb
│ ├── helper
│ │ ├── base.rb
│ │ ├── php.rb
│ │ ├── dot_net.rb
│ │ └── java.rb
│ └── tasks.rb
└── genio.rb
├── bin
└── genio
├── spec
├── spec_helper.rb
├── namespace_helper_spec.rb
├── php_spec.rb
├── java_spec.rb
└── dotnet_spec.rb
├── Gemfile
├── templates
├── sdk.wsdlenum_dotnet.erb
├── sdk.rest_version_dotnet.erb
├── sdk.rest_version_java.erb
├── sdk.wsdlenum_java.erb
├── sdk.wsdlsoapserialize_php.erb
├── sdk.wsdl_php.erb
├── sdk.wsdlservice_php.erb
├── sdk.wsdl_dotnet.erb
├── sdk.wsdl_java.erb
├── sdk.rest_php.erb
├── sdk.wsdlsoapdeserialize_java.erb
├── sdk.wsdlservice_dotnet.erb
├── sdk.wsdlsoapdeserialize_dotnet.erb
├── sdk.wsdlservice_java.erb
├── sdk.wsdlsoapserialize_java.erb
├── sdk.wsdlsoapserialize_dotnet.erb
├── sdk.rest_dotnet.erb
└── sdk.rest_java.erb
├── genio.gemspec
├── README.md
└── LICENSE.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | *.gem
2 | *.rbc
3 | .bundle
4 | .config
5 | .ruby-version
6 | .yardoc
7 | Gemfile.lock
8 | InstalledFiles
9 | _yardoc
10 | coverage
11 | doc/
12 | lib/bundler/man
13 | pkg
14 | rdoc
15 | spec/reports
16 | test/tmp
17 | test/version_tmp
18 | tmp
19 |
--------------------------------------------------------------------------------
/CONTRIBUTORS.md:
--------------------------------------------------------------------------------
1 | Contributors
2 | ============
3 |
4 | These people have contributed to genio
5 |
6 | * Siddick Ebramsha
7 | * Kumaravel Jayakumar
8 | * Vidya Chandrasekaran
9 | * Latha Vairamani
10 | * Praveen Alavilli
11 | * Prasanna Annamalai
12 | * Ganesh Hegde
13 | * Tarini Kanta
14 | * Rajani Somaskandan
15 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
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 "bundler/gem_tasks"
18 |
--------------------------------------------------------------------------------
/lib/genio/version.rb:
--------------------------------------------------------------------------------
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 | VERSION = "1.0.0"
19 | end
20 |
--------------------------------------------------------------------------------
/bin/genio:
--------------------------------------------------------------------------------
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)
22 |
--------------------------------------------------------------------------------
/spec/spec_helper.rb:
--------------------------------------------------------------------------------
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 'bundler/setup'
18 | Bundler.require :default
19 |
20 | RSpec.configure do |config|
21 | end
22 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
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 | source 'https://rubygems.org'
18 |
19 | # Specify your gem's dependencies in sdk_generator.gemspec
20 | gemspec
21 |
22 | gem 'genio-parser', :git => 'https://github.com/paypal/genio-parser.git'
23 |
--------------------------------------------------------------------------------
/lib/genio/logging.rb:
--------------------------------------------------------------------------------
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 'logger'
18 |
19 | module Genio
20 | class << self
21 | attr_accessor :logger
22 | end
23 | self.logger = Logger.new(STDERR)
24 |
25 | module Logging
26 | def logger
27 | Genio.logger
28 | end
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/templates/sdk.wsdlenum_dotnet.erb:
--------------------------------------------------------------------------------
1 | <%
2 | #
3 | # Copyright 2013 PayPal Inc.
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 | # http://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 | #
18 | %>
19 | using System;
20 | using System.ComponentModel;
21 | namespace <%= package %>
22 | {
23 | [Serializable]
24 | public enum <%= classname %>
25 | {
26 |
27 | <% definition["values"].each do |value| %>
28 | [Description("<%= value %>")]<%= validate_enum_name(value.upcase) %><% if value != definition["values"].last %>,<% end %>
29 |
30 | <% end %>
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/lib/genio.rb:
--------------------------------------------------------------------------------
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
36 |
--------------------------------------------------------------------------------
/spec/namespace_helper_spec.rb:
--------------------------------------------------------------------------------
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 'spec_helper'
18 |
19 | describe 'Genio::Util::NamespaceHelper' do
20 | before :all do
21 | @helper = Class.new do
22 | include Genio::Util::NamespaceHelper
23 | end.new
24 | end
25 |
26 | it "should validate namepsace is urn or uri" do
27 | @helper.is_urn_ns("https://api.paypal.com/payments").should be_false
28 | @helper.is_urn_ns("urn:ebay:apis:eBLBaseComponents").should be_true
29 | end
30 |
31 | it "should convert namespaces to packagename" do
32 | @helper.convert_ns_to_package("com.paypal.api").should eql "com.paypal.api"
33 | end
34 |
35 |
36 | end
--------------------------------------------------------------------------------
/templates/sdk.rest_version_dotnet.erb:
--------------------------------------------------------------------------------
1 | <%
2 | #
3 | # Copyright 2013 PayPal Inc.
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 | # http://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 | #
18 | %>
19 | using PayPal;
20 |
21 | namespace PayPal
22 | {
23 | public class SDKVersionImpl : SDKVersion
24 | {
25 |
26 | ///
27 | /// SDK ID used in User-Agent HTTP header
28 | ///
29 | private const string SdkId = "";
30 |
31 | ///
32 | /// SDK Version used in User-Agent HTTP header
33 | ///
34 | private const string SdkVersion = "";
35 |
36 | public string GetSDKId()
37 | {
38 | return SdkId;
39 | }
40 |
41 | public string GetSDKVersion()
42 | {
43 | return SdkVersion;
44 | }
45 | }
46 |
47 | }
48 |
49 |
50 |
--------------------------------------------------------------------------------
/templates/sdk.rest_version_java.erb:
--------------------------------------------------------------------------------
1 | <%
2 | #
3 | # Copyright 2013 PayPal Inc.
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 | # http://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 | #
18 | %>
19 | package com.paypal.sdk.info;
20 |
21 | import com.paypal.core.SDKVersion;
22 |
23 | /**
24 | * Implementation of SDKVersion
25 | */
26 | public class SDKVersionImpl implements SDKVersion {
27 |
28 | /**
29 | * SDK ID used in User-Agent HTTP header
30 | */
31 | private static final String SDK_ID = "";
32 |
33 | /**
34 | * SDK Version used in User-Agent HTTP header
35 | */
36 | private static final String SDK_VERSION = "";
37 |
38 | public String getSDKId() {
39 | return SDK_ID;
40 | }
41 |
42 | public String getSDKVersion() {
43 | return SDK_VERSION;
44 | }
45 |
46 | }
--------------------------------------------------------------------------------
/templates/sdk.wsdlenum_java.erb:
--------------------------------------------------------------------------------
1 | <%
2 | #
3 | # Copyright 2013 PayPal Inc.
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 | # http://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 | #
18 | %>
19 | package <%= package %>;
20 |
21 | public enum <%= classname %> {
22 |
23 | <% definition["values"].each do |value| %>
24 |
25 | <%= validate_enum_name(value.upcase) %>("<%= value %>")<% if value != definition["values"].last %>,<% else %>;<% end %>
26 | <% end %>
27 |
28 | private String value;
29 |
30 | private <%= classname %> (String value) {
31 | this.value = value;
32 | }
33 |
34 | public String getValue(){
35 | return value;
36 | }
37 |
38 | public static <%= classname %> fromValue(String v) {
39 | for (<%= classname %> c : values()) {
40 | if (c.value.equals(v)) {
41 | return c;
42 | }
43 | }
44 | throw new IllegalArgumentException(v);
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/lib/genio/util/schema_helper.rb:
--------------------------------------------------------------------------------
1 | require 'thor/error'
2 |
3 | module Genio
4 | module Util
5 | module SchemaHelper
6 |
7 | # Decide on a parser from the passed in URI and
8 | # return the parser after loading the definition
9 | # from the URI
10 | def get_parser(options)
11 | if options[:wsdl]
12 | load_wsdl(options[:wsdl])
13 | elsif options[:wadl]
14 | load_wadl(options[:wadl])
15 | elsif options[:json_schema]
16 | load_json_schema(options[:json_schema])
17 | elsif options[:schema]
18 | get_parser_with_uri(options[:schema])
19 | else
20 | raise Thor::RequiredArgumentMissingError, "No value provided for required options '--json-schema' or '--wsdl' or '--wadl'"
21 | end
22 | end
23 |
24 | def get_parser_with_uri(uri)
25 | if (uri.end_with?('wadl'))
26 | load_wadl(uri)
27 | elsif (uri.end_with?('wsdl'))
28 | load_wsdl(uri)
29 | else
30 | load_json_schema(uri)
31 | end
32 | end
33 |
34 | def load_wsdl(path)
35 | schema = Parser::Format::Wsdl.new
36 | load_schema_uri(schema, path)
37 | schema
38 | end
39 |
40 | def load_wadl(path)
41 | schema = Parser::Format::Wadl.new
42 | load_schema_uri(schema, path)
43 | schema
44 | end
45 |
46 | def load_json_schema(path)
47 | schema = Parser::Format::JsonSchema.new
48 | load_schema_uri(schema, path)
49 | schema.fix_unknown_service
50 | schema
51 | end
52 |
53 | def load_schema_uri(parser, uri)
54 | uri.split(/,/).each do |path|
55 | parser.load(path)
56 | end
57 | end
58 |
59 | # Replaces '-' with '_' and CamelCase(s)
60 | def validate_file_name(name)
61 | name.gsub(/-/, "_").camelcase
62 | end
63 | end
64 | end
65 | end
66 |
--------------------------------------------------------------------------------
/lib/genio/template.rb:
--------------------------------------------------------------------------------
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 'tilt'
18 | require "thor"
19 |
20 | module Genio
21 | module Template
22 | include Thor::Shell
23 | include Thor::Actions
24 |
25 | def render_values
26 | @render_values ||= [{}]
27 | end
28 |
29 | def render(template, values = {})
30 | values = { :create_file => nil }.merge(values)
31 | values = render_values.last.merge(values)
32 | values[:scope] ||= generate_scope(values)
33 | render_values.push(values)
34 | content = parse_erb(template, values)
35 | render_values.pop
36 | create_file(values[:create_file], content) if values[:create_file]
37 | content
38 | end
39 |
40 | def generate_scope(values)
41 | Class.new do
42 | include values[:helper] if values[:helper]
43 |
44 | def initialize(klass)
45 | @klass = klass
46 | end
47 |
48 | def method_missing(name, *args)
49 | @klass.send(name, *args)
50 | end
51 | end.new(self)
52 | end
53 |
54 | def parse_erb(template, values)
55 | filename = File.absolute_path(template, template_path)
56 | template = Tilt::ErubisTemplate.new(Dir["#{filename}*"].first || template)
57 | template.render(values[:scope] || self, values)
58 | end
59 |
60 | def template_path
61 | @template_path ||= File.expand_path("../../../", __FILE__)
62 | end
63 |
64 | end
65 | end
66 |
--------------------------------------------------------------------------------
/genio.gemspec:
--------------------------------------------------------------------------------
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 | # coding: utf-8
18 | lib = File.expand_path('../lib', __FILE__)
19 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
20 | require 'genio/version'
21 |
22 | Gem::Specification.new do |spec|
23 | spec.name = "genio"
24 | spec.version = Genio::VERSION
25 | spec.authors = ["PayPal"]
26 | spec.email = ["DL-PP-Platform-Ruby-SDK@ebay.com"]
27 |
28 | spec.summary = %q{Genio is an extensible tool that can generate code to consume APIs in multiple programming languages based on API specification formats: JSON-Schema/WSDL/WADL}
29 | spec.description = %q{Genio is an extensible tool that can generate code to consume APIs in multiple programming languages based on API specification formats: JSON-Schema/WSDL/WADL}
30 | spec.homepage = "https://github.com/paypal/genio"
31 | spec.license = "Apache License, Version 2.0"
32 |
33 | spec.files = Dir["{lib,templates,bin}/**/*"] + [ "README.md", "LICENSE.txt" ]
34 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
35 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
36 | spec.require_paths = ["lib"]
37 |
38 | spec.add_dependency "genio-parser", "~> 1.0"
39 | spec.add_dependency "activesupport"
40 | spec.add_dependency "tilt"
41 | spec.add_dependency "erubis"
42 | spec.add_dependency "thor"
43 | # spec.add_dependency "json"
44 |
45 | spec.add_development_dependency "bundler", "~> 1.3"
46 | spec.add_development_dependency "rake"
47 | spec.add_development_dependency "rspec"
48 | end
49 |
--------------------------------------------------------------------------------
/templates/sdk.wsdlsoapserialize_php.erb:
--------------------------------------------------------------------------------
1 | <%
2 | #
3 | # Copyright 2013 PayPal Inc.
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 | # http://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 | #
18 | %>
19 | <% if (request_types(schema).include?(classname) or header_types(schema).include?(classname)) %>
20 | public function toXMLString()
21 | {
22 | $str = '<<%= get_rootname_serialization(data_type, schema) %>>';
23 | <% if (should_qualify_name(schema.namespaces[data_type.package], schema)) %>
24 | <% prefix = schema.namespaces[data_type.package] + ':' %>
25 | <% else %>
26 | <% prefix = '' %>
27 | <% end %>
28 | <% type = data_type %>
29 | <% while type %>
30 | <% type.properties.each do |name, property| %>
31 | if($this-><%= property.name %> != NULL)
32 | {
33 | <% if is_complex_type(property.type, schema) %>
34 | <% if property.max == 'unbounded' %>
35 | foreach($this-><%= property.name %> as $item)
36 | {
37 | $str .= '<<%= prefix %><%= property.name %>>';
38 | $str .= $item->toXMLString();
39 | $str .= '<%= prefix %><%= property.name %>>';
40 | }
41 | <% else %>
42 | $str .= '<<%= prefix %><%= property.name %>>';
43 | $str .= $this-><%= property.name %>->toXMLString();
44 | $str .= '<%= prefix %><%= property.name %>>';
45 | <% end %>
46 | <% else %>
47 | <% if property.max == 'unbounded' %>
48 | foreach($this-><%= property.name %> as $item)
49 | {
50 | $str .= '<<%= prefix %><%= property.name %>>';
51 | $str .= $item;
52 | $str .= '<%= prefix %><%= property.name %>>';
53 | }
54 | <% else %>
55 | $str .= '<<%= prefix %><%= property.name %>>';
56 | $str .= $this-><%= property.name %>;
57 | $str .= '<%= prefix %><%= property.name %>>';
58 | <% end %>
59 | <% end %>
60 | }
61 | <% end %>
62 | <% type = schema.data_types[type.extends] %>
63 | <% end %>
64 | $str .= '<%= get_rootname_serialization(data_type, schema) %>>';
65 | return $str;
66 | }
67 | <% end %>
68 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
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 --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.
56 |
--------------------------------------------------------------------------------
/templates/sdk.wsdl_php.erb:
--------------------------------------------------------------------------------
1 | <%
2 | #
3 | # Copyright 2013 PayPal Inc.
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 | # http://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 | #
18 | %>
19 | ;
21 | <% imports(data_type, schema, package, classname, "soap").each do |import| %>
22 | use <%= import %>;
23 | <% end %>
24 | /**
25 | <%= comment_wrap(data_type.description, 60, ' * ') %>
26 | */
27 | class <%= valid_class_name(classname) %> extends <% if data_type.fault %>PPXmlFaultMessage<% else %>PPXmlMessage<% end %> {
28 | <% const_args = {} %>
29 | <% type = data_type %>
30 | <% while type %>
31 | <% type.properties.each do |name, property| %>
32 | <% vname = to_underscore(name) %>
33 | <% vtype = get_php_type(property, schema, classname) %>
34 | <% const_args[vname] = property.type if property.required %>
35 | /**
36 | <%= comment_wrap(property.description, 60, "\t * ") %>
37 | <% if property.array %>
38 | * @array
39 | <% end %>
40 | * @access public
41 | <% if (property.value != '1' and !property.attribute) and !should_qualify_name(property.package, schema) %>
42 | * @namespace
43 | <% elsif property.package.present? %>
44 | * @namespace <%= property.package %>
45 | <% end %>
46 | <% if property.attribute %>
47 | * @attribute
48 | <% end %>
49 | <% if property.value == '1' %>
50 | * @value
51 | <% end %>
52 | * @var <%= "#{validated_package(schema.data_types[vtype].package)}\\" if schema.data_types[vtype] %><%= vtype %>
53 | <% if vname != property.name %>
54 | * @name <%= property.name %>
55 | <% end %>
56 | */
57 | public $<%= vname %>;
58 | <% end %>
59 | <% type = schema.data_types[type.extends] %>
60 | <% end %>
61 |
62 | <% if const_args.size > 0 %>
63 |
64 | /**
65 | * Constructor with mandatory properties
66 | *
67 | <% const_args.map.each do |name, type| %>
68 | * @param <%= type %> $<%= name %>
69 | <% end %>
70 | */
71 | public function __construct(<%= const_args.map{|name, type| "$#{name} = NULL"}.join(", ") %>) {
72 | <% const_args.each do |name, type| %>
73 | $this-><%= name %> = $<%= name %>;
74 | <% end %>
75 | }
76 | <% end %>
77 |
78 | <%= render "templates/sdk.wsdlsoapserialize_php.erb", :classname => classname, :schema => schema, :data_type => data_type %>
79 | }
80 |
--------------------------------------------------------------------------------
/templates/sdk.wsdlservice_php.erb:
--------------------------------------------------------------------------------
1 | <%
2 | #
3 | # Copyright 2013 PayPal Inc.
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 | # http://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 | #
18 | %>
19 | ;
21 |
22 | <% service_imports(schema, service, package).each do |import| %>
23 | use <%= import %>;
24 | <% end %>
25 | /**
26 | * AUTO GENERATED service wrapper class
27 | */
28 | class <%= classname %> extends PPBaseService {
29 |
30 | private static $SERVICE_NAME = "<%= classname %>";
31 | private static $SERVICE_VERSION = "";
32 | private static $SDK_NAME = "";
33 | private static $SDK_VERSION = "";
34 |
35 | public function __construct() {
36 | parent::__construct('<%= classname %>', 'SOAP');
37 | }
38 | <% service.operations.each do |name, definition| %>
39 | <% methodname = validate_method_name(name) %>
40 |
41 | /**
42 | * <%= definition.description %>
43 | * @param <%= get_namespace(schema.data_types[definition.request].package) %>\<%= definition.request %> $<%= valid_property_name(definition.request) %>
44 | * @param PayPal\Common\PPApiContext $apiContext
45 | * @return <%= get_namespace(schema.data_types[definition.response].package) %>\<%= definition.response %>
46 | <% if definition.fault %>
47 | * @throws <%= get_namespace(schema.data_types[definition.fault].package) %>\<%= definition.fault %>
48 | <% end %>
49 | */
50 | <% argument_array = get_wsdl_operation_arguments(definition) %>
51 | public function <%= methodname %>(<% if argument_array.size > 0 %> <%= argument_array.join(', ') %><% end %>, $apiContext) {
52 |
53 | $apiContext->addHttpHeader("SOAPAction", '"<%= definition.soapAction || '""' %>"');
54 |
55 | $handlers = array(
56 | new \PayPal\Handler\GenericSoapHandler($this->xmlNamespacePrefixProvider()),
57 | );
58 | $resp = $this->call('<%= classname %>', '<%= methodname %>', <% if argument_array.size > 0 %> <%= argument_array.join(', ') %><% end %>, $apiContext, $handlers);
59 |
60 | $ret = new <%= definition.response %>();
61 | <% if definition.fault %>
62 | try {
63 | $ret->init(PPUtils::xmlToArray($resp));
64 | } catch (PPTransformerException $ex) {
65 | $fault = new <%= definition.fault%>();
66 | $fault->init(PPUtils::xmlToArray($resp));
67 | throw $fault;
68 | }
69 | <% else %>
70 | $ret->init(PPUtils::xmlToArray($resp));
71 | <% end %>
72 | return $ret;
73 | }
74 |
75 | <% end %>
76 |
77 |
78 | /**
79 | * fucntion with namespaces and corresponding prefixes used in SOAP request serialization
80 | */
81 | public function xmlNamespacePrefixProvider(){
82 |
83 | $namespace = "";
84 | <% schema.namespaces.each do |namespace, prefix| %>
85 | <% if prefix != '' %>
86 | $namespace .= 'xmlns:<%= prefix %>="<%= namespace %>" ';
87 | <% end %>
88 | <% end %>
89 |
90 | return $namespace;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/templates/sdk.wsdl_dotnet.erb:
--------------------------------------------------------------------------------
1 | <%
2 | #
3 | # Copyright 2013 PayPal Inc.
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 | # http://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 | #
18 | %>
19 | <% operation_input = is_operation_input(data_type, schema) %>
20 | <% imports(data_type, schema, package, classname, "soap", operation_input).each do |import| %>
21 | using <%= import %>;
22 | <% end %>
23 | namespace <%= package %>
24 | {
25 | public class <%= validate_class_name(classname) %><% if data_type.fault %> : System.Exception <% end %><% if operation_input %> : XMLMessageSerializer<% end %>
26 | {
27 |
28 | ///
29 | /// Namespace of <%= classname %>
30 | ///
31 | public const string Namespace = "<%= data_type.package %>";
32 |
33 | ///
34 | /// Default US culture info used for decimal conversion
35 | ///
36 | private static CultureInfo DefaultCulture = new CultureInfo("en-US");
37 |
38 | <% const_args = {} %>
39 |
40 | <% type = data_type %>
41 | <% while type %>
42 | <% type.properties.each do |name, property| %>
43 | <% vname = validate_property_name(name, true) %>
44 | <% const_args[vname] = get_property_class(property, classname) if property.required %>
45 | private <%= get_property_class(property, classname) %><%= '?' if (is_nullable_type(property) and !property.array) %> <%= vname %>Property<% if property.array %> = new <%= get_property_class(property, classname) %>()<% end %>;
46 |
47 | ///
48 | /// <%= property.description %>
49 | ///
50 | public <%= get_property_class(property, classname) %><%= '?' if (is_nullable_type(property) and !property.array) %> <%= vname %>
51 | {
52 | get
53 | {
54 | return this.<%= vname %>Property;
55 | }
56 | set
57 | {
58 | this.<%= vname %>Property = value;
59 | }
60 | }
61 |
62 | <% end %>
63 | <% type = schema.data_types[type.extends] %>
64 | <% end %>
65 | ///
66 | /// Default Constructor
67 | ///
68 | public <%= classname %>()
69 | {
70 | }
71 |
72 | <% if const_args.size > 0 %>
73 | ///
74 | /// Parameterized Constructor
75 | ///
76 | public <%= classname %>(<%= const_args.map{|name, type| "#{type} #{validate_property_as_argument(name)}"}.join(", ") %>)
77 | {
78 | <% const_args.each do |name, type| %>
79 | this.<%= name %> = <%= validate_property_as_argument(name) %>;
80 | <% end %>
81 | }
82 | <% end %>
83 |
84 | <% serialization_name = get_rootname_serialization(data_type, schema) if operation_input %>
85 | <%= render "templates/sdk.wsdlsoapserialize_dotnet.erb", :classname => classname, :operation_input => operation_input, :serialization_name => serialization_name, :schema => schema, :data_type => data_type %>
86 |
87 | <%= render "templates/sdk.wsdlsoapdeserialize_dotnet.erb", :classname => classname, :data_type => data_type %>
88 |
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/lib/genio/util/namespace_helper.rb:
--------------------------------------------------------------------------------
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 Util
19 | module NamespaceHelper
20 |
21 | # Checks the format of the namespace as uri or urn,
22 | # and converts the namespace to package name ('.' seperated)
23 | # eg: http://github.paypal.com/payments/sale is changed to
24 | # com.paypal.github.payments.sale
25 | # eg: urn:ebay:apis:eBLBaseComponents is changed to
26 | # urn.ebay.apis.eBLBaseComponents
27 | # any numbers occuring as a part of path in the uri
28 | # based namespaces is removed
29 | def convert_ns_to_package(ns)
30 | if is_urn_ns(ns)
31 | packagename = ns.gsub(/:/, "\.")
32 | else
33 | hostname = URI.parse(ns)
34 | packagename = hostname.host.sub(/^www./, "").split(".").reverse.join(".")
35 | packagename << hostname.path.to_s.gsub(/[\d-]+/, "").sub(/\/+$/,'').gsub(/-/, '_').gsub(/\/+/, ".")
36 | end
37 | packagename
38 | end
39 |
40 | # Strips a package name off any
41 | # Top Level Domains (TLD)s; com, co, org, gov, de, us, in
42 | # eg: com.paypal.github.payments.sale is converted to
43 | # paypal.github.payments.sale
44 | def remove_tld_in_package(packagename)
45 | packagename.sub(/^(com|co|org|gov|de|us|in)\./, "")
46 | end
47 |
48 | # Lowercases parts of a package name
49 | # eg: Paypal.Github.Payments.Sale is converted to
50 | # paypal.github.payments.sale
51 | def lowercase_package(packagename)
52 | packagename.gsub(/([^\.]+[\.]?)/){ |match| $1.camelcase(:lower) }
53 | end
54 |
55 | # Capitalizes parts of a package name
56 | # eg: paypal.github.payments.sale is converted to
57 | # Paypal.Github.Payments.Sale
58 | def capitalize_package(packagename)
59 | packagename.gsub(/([^\.]+[\.]?)/){ |match| $1.camelcase }
60 | end
61 |
62 | # Returns a folder path corresponding to the
63 | # packagename; setting capitalize_folder true returns
64 | # folder names that are captialized
65 | def get_package_folder(packagename, capitalize_folder = false)
66 | if (capitalize_folder)
67 | capitalize_package(packagename).gsub(/\.|\\/, '/')
68 | else
69 | packagename.gsub(/\.|\\/, '/')
70 | end
71 | end
72 |
73 | # Returns a namespace path with '\' corresponding to the
74 | # packagename; setting capitalizefolder true returns
75 | # names that are captialized
76 | def get_slashed_package_name(packagename, capitalizefolder = false)
77 | if (capitalizefolder)
78 | capitalize_package(packagename).gsub(/\./, '\\')
79 | else
80 | packagename.gsub(/\./, '\\')
81 | end
82 | end
83 |
84 | # Checks if the uri starts with protocol
85 | # schemes and returns true, else treats
86 | # the namespace as a Uniform Resource Name
87 | def is_urn_ns(ns)
88 | !ns.start_with?('http:','https:')
89 | end
90 |
91 | end
92 | end
93 | end
94 |
--------------------------------------------------------------------------------
/templates/sdk.wsdl_java.erb:
--------------------------------------------------------------------------------
1 | <%
2 | #
3 | # Copyright 2013 PayPal Inc.
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 | # http://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 | #
18 | %>
19 | package <%= package %>;
20 | <% operation_input = is_operation_input(data_type, schema) %>
21 | <% imports(data_type, schema, package, classname, "soap", operation_input).each do |import| %>
22 | import <%= import %>;
23 | <% end %>
24 |
25 | public class <%= validate_class_name(classname) %><% if data_type.fault %> extends RuntimeException <% end %><% if operation_input %> implements XMLMessageSerializer<% end %> {
26 |
27 | /**
28 | * Namespace of <%= classname %>
29 | */
30 | public static final String nameSpace = "<%= data_type.package %>";
31 |
32 | <% const_args = {} %>
33 | <% type = data_type %>
34 | <% while type %>
35 | <% type.properties.each do |name, property| %>
36 | <% vname = validate_property_name(name) %>
37 | <% const_args[vname] = get_property_class(property, classname) if property.required %>
38 | /**
39 | * <%= property.description %>
40 | */
41 | private <%= get_property_class(property, classname) %> <%= vname %><% if property.array %> = new ArrayList<<%= validate_class_name(find_basic_type(property.type)) %>>()<% end %>;
42 |
43 | <% end %>
44 | <% type = schema.data_types[type.extends] %>
45 | <% end %>
46 | /**
47 | * Default Constructor
48 | */
49 | public <%= classname %>() {
50 | }
51 |
52 | <% if const_args.size > 0 %>
53 | /**
54 | * Parameterized Constructor
55 | */
56 | public <%= classname %>(<%= const_args.map{|name, type| "#{type} #{name}"}.join(", ") %>) {
57 | <% const_args.each do |name, type| %>
58 | this.<%= name %> = <%= name %>;
59 | <% end %>
60 | }
61 | <% end %>
62 |
63 | <% data_type.properties.each do |name, property| %>
64 | <%
65 | vname = validate_property_name(name)
66 | methodname = validate_class_name(name)
67 | %>
68 |
69 | /**
70 | * Setter for <%= vname %>
71 | */
72 | public <%= classname %> set<%= methodname %>(<%= get_property_class(property, classname) %> <%= vname %>) {
73 | this.<%= vname%> = <%= vname %>;
74 | return this;
75 | }
76 |
77 | /**
78 | * Getter for <%= vname %>
79 | */
80 | public <%= get_property_class(property, classname) %> get<%= methodname %>() {
81 | return this.<%= vname%>;
82 | }
83 |
84 | <% end %>
85 | <% if data_type.extends %>
86 | <% extended_data_type = schema.data_types[data_type.extends] %>
87 | <% extended_data_type.properties.each do |name, property| %>
88 | <%
89 | vname = validate_property_name(name)
90 | methodname = validate_class_name(name)
91 | %>
92 |
93 | /**
94 | * Setter for <%= vname %>
95 | */
96 | public <%= classname %> set<%= methodname %>(<%= get_property_class(property, classname) %> <%= vname %>) {
97 | this.<%= vname%> = <%= vname %>;
98 | return this;
99 | }
100 |
101 | /**
102 | * Getter for <%= vname %>
103 | */
104 | public <%= get_property_class(property, classname) %> get<%= methodname %>() {
105 | return this.<%= vname%>;
106 | }
107 |
108 | <% end %>
109 | <% end %>
110 | <% serialization_name = get_rootname_serialization(data_type, schema) if operation_input %>
111 | <%= render "templates/sdk.wsdlsoapserialize_java.erb", :classname => classname, :operation_input => operation_input, :serialization_name => serialization_name, :schema => schema, :data_type => data_type %>
112 |
113 | <%= render "templates/sdk.wsdlsoapdeserialize_java.erb", :classname => classname, :data_type => data_type %>
114 |
115 | }
116 |
--------------------------------------------------------------------------------
/lib/genio/helper/base.rb:
--------------------------------------------------------------------------------
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
102 |
--------------------------------------------------------------------------------
/templates/sdk.rest_php.erb:
--------------------------------------------------------------------------------
1 | <%
2 | #
3 | # Copyright 2013 PayPal Inc.
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 | # http://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 | #
18 | %>
19 |
21 | namespace <%= package %>;
22 |
23 | <% imports(data_type, schema, package, classname, "rest").each do |import| %>
24 | use <%= import %>;
25 | <% end %>
26 |
27 | class <%= classname %> <%= data_type.extends ? "extends #{valid_class_name(data_type.extends)} " : "extends PPModel " %><%= "implements IResource " if service %>{
28 | <% if service %>
29 |
30 | <% end %>
31 | <% data_type.properties.each do |name, property| %>
32 | <% vname = to_underscore(name) %>
33 | <% vtype = get_php_type(property, schema, classname) %>
34 | /**
35 | * <%= property.description %>
36 | *
37 | <% if property.array %>
38 | * @array
39 | <% end %>
40 | * @param <%= "#{get_namespace(schema.data_types[vtype].package || schema.endpoint )}\\" if schema.data_types[vtype] %><%= vtype %> $<%= name %>
41 | */
42 | public function set<%= valid_class_name(name) %>(<%if property.array %>array <%end%>$<%= vname %>) {
43 | <% if vname != name%>
44 | $this->{"<%= name %>"} = $<%= vname %>;
45 | <% else %>
46 | $this-><%= vname %> = $<%= vname %>;
47 | <% end %>
48 | return $this;
49 | }
50 |
51 | /**
52 | * <%= property.description %>
53 | *
54 | * @return <%= "#{get_namespace(schema.data_types[vtype].package || schema.endpoint )}\\" if schema.data_types[vtype] %><%= vtype %>
55 | */
56 | public function get<%= valid_class_name(name) %>() {
57 | <% if vname != name%>
58 | return $this->{"<%= name %>"};
59 | <% else %>
60 | return $this-><%= vname %>;
61 | <% end %>
62 | }
63 |
64 | <% end %>
65 | <% if service %>
66 | <% service.operations.each do |name, property| %>
67 | <% static = is_static_method(property) %>
68 | <% hostId_check = check_host_id(classname, property) %>
69 | <% argument_hash = form_arguments(classname, property, name) %>
70 | <% object_array = get_object_array(classname, name, property, argument_hash) %>
71 | <% payload = get_payload(classname, property) %>
72 | /*
73 | * <%= property.description %>
74 | *
75 | <% argument_hash.each do |name, type| %>
76 | * @param <%= type %> $<%= name %>
77 | <% end %>
78 | <% if( property.parameters && allowed_params(property.parameters).size > 0 )%>
79 | * allowed queryparameters <%= allowed_params(property.parameters).map{|k,v| "'#{k}'" }.join(", ") %>
80 | <% end %>
81 | * @param PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration, credentials, and additional headers.
82 | * @return <%= "#{get_namespace(schema.data_types[property.response].package || schema.endpoint )}\\" if schema.data_types[property.response] %><%= property.response || 'string' %>
83 | */
84 | public<%= " static" if static %> function <%= validate_function_name(name) %>(<% if argument_hash.size > 0 %><%= argument_hash.map{|name, type| type == "array" ? "array $#{name}" : "$#{name}"}.join(", ") %>, <% end %>$apiContext) {
85 | <% if hostId_check %>
86 | if ($this->getId() == null) {
87 | throw new \InvalidArgumentException("Id cannot be null");
88 | }
89 | <% end %>
90 | <% if argument_hash.size > 0 %>
91 | <% argument_hash.each do |name, type| %>
92 | <% if name != 'queryParameters'%>
93 |
94 | if ($<%= name %> == null<%= " || strlen($#{name}) == 0" if type == "string" %>) {
95 | throw new \InvalidArgumentException("<%= name%> cannot be null or empty");
96 | }
97 | <% end %>
98 | <% end %>
99 | <% end %>
100 | $payload = <%= payload %>;
101 | $call = new PPRestCall($apiContext);
102 | $json = $call->execute(array('PayPal\Rest\RestHandler'), <%= process_path_with_placeholders(classname, name, property.path, hostId_check, argument_hash, property.parameters) %>, "<%= property.type %>", $payload);
103 | <% if property.request == classname %>
104 | $this->fromJson($json);
105 | return $this;
106 | <% elsif property.response %>
107 | <% if property.response == "string" %>
108 | return $json;
109 | <% else %>
110 | $ret = new <%= property.response %>();
111 | $ret->fromJson($json);
112 | return $ret;
113 | <% end %>
114 | <% else %>
115 | return $json;
116 | <% end %>
117 | }
118 | <% end %>
119 | <% end %>
120 | }
121 |
--------------------------------------------------------------------------------
/templates/sdk.wsdlsoapdeserialize_java.erb:
--------------------------------------------------------------------------------
1 | <%
2 | #
3 | # Copyright 2013 PayPal Inc.
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 | # http://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 | #
18 | %>
19 | /**
20 | * Checks whether the node is empty space
21 | */
22 | private boolean isWhitespaceNode(Node n) {
23 | if (n.getNodeType() == Node.TEXT_NODE) {
24 | String val = n.getNodeValue();
25 | return val.trim().length() == 0;
26 | } else if (n.getNodeType() == Node.ELEMENT_NODE ) {
27 | return (n.getChildNodes().getLength() == 0);
28 | } else {
29 | return false;
30 | }
31 | }
32 |
33 | /**
34 | * Constructor using a Node parameter
35 | */
36 | public <%= classname %> (Node node) throws XPathExpressionException {
37 | XPathFactory factory = XPathFactory.newInstance();
38 | XPath xpath = factory.newXPath();
39 | Node childNode = null;
40 | NodeList nodeList = null;
41 | <% type = data_type %>
42 | <% while type %>
43 | <% type.properties.each do |name , definition| %>
44 | <% vname = validate_property_name(name) %>
45 | <% if definition.array %>
46 | nodeList = (NodeList) xpath.evaluate("<%= name %>", node, XPathConstants.NODESET);
47 | if (nodeList != null && nodeList.getLength() > 0) {
48 | for (int i = 0; i < nodeList.getLength(); i++) {
49 | Node subNode = nodeList.item(i);
50 | <% if is_complex_type(definition.type, schema) || is_enum_type(definition.type, schema) %>
51 | <% if definition.enum %>
52 | String value = subNode.getTextContent();
53 | this.<%= vname %>.add(<%= validate_class_name(definition.type) %>.fromValue(value));
54 | <% else %>
55 | this.<%= vname %>.add(new <%= validate_class_name(definition.type) %>(subNode));
56 | <% end %>
57 | <% else %>
58 | String value = subNode.getTextContent();
59 | <% if find_basic_type(definition.type) == 'String' %>
60 | this.<%= vname %>.add(value);
61 | <% elsif find_basic_type(definition.type) == 'Integer' %>
62 | this.<%= vname %>.add(Integer.valueOf(value));
63 | <% elsif find_basic_type(definition.type) == 'Boolean' %>
64 | this.<%= vname %>.add(Boolean.valueOf(value));
65 | <% elsif find_basic_type(definition.type) == 'Double' %>
66 | this.<%= vname %>.add(Double.valueOf(value));
67 | <% elsif find_basic_type(definition.type) == 'Float' %>
68 | this.<%= vname %>.add(Float.valueOf(value));
69 | <% end %>
70 | <% end %>
71 | }
72 | }
73 | <% else %>
74 | <% if is_complex_type(definition.type, schema) || is_enum_type(definition.type, schema) %>
75 | <% if definition.enum %>
76 | <% if definition.attribute %>
77 | childNode = (Node) xpath.evaluate("@<%= name %>", node, XPathConstants.NODE);
78 | if (childNode != null) {
79 | this.<%= vname %> = <%= validate_class_name(definition.type) %>.fromValue(childNode.getNodeValue());
80 | }
81 | <% else %>
82 | childNode = (Node) xpath.evaluate("<%= name %>", node, XPathConstants.NODE);
83 | if (childNode != null && !isWhitespaceNode(childNode)) {
84 | this.<%= vname %> = <%= validate_class_name(definition.type) %>.fromValue(childNode.getTextContent());
85 | }
86 | <% end %>
87 | <% else %>
88 | childNode = (Node) xpath.evaluate("<%= name %>", node, XPathConstants.NODE);
89 | if (childNode != null && !isWhitespaceNode(childNode)) {
90 | this.<%= vname %> = new <%= validate_class_name(definition.type) %>(childNode);
91 | }
92 | <% end %>
93 | <% else %>
94 | <% if definition.value == '1' %>
95 | String value = node.getTextContent();
96 | <% if find_basic_type(definition.type) == 'String' %>
97 | this.<%= vname %> = value;
98 | <% elsif find_basic_type(definition.type) == 'Integer' %>
99 | this.<%= vname %> = Integer.valueOf(value);
100 | <% elsif find_basic_type(definition.type) == 'Boolean' %>
101 | this.<%= vname %> = Boolean.valueOf(value);
102 | <% elsif find_basic_type(definition.type) == 'Double' %>
103 | this.<%= vname %> = Double.valueOf(value);
104 | <% elsif find_basic_type(definition.type) == 'Float' %>
105 | this.<%= vname %> = Float.valueOf(value);
106 | <% end %>
107 | <% else %>
108 | childNode = (Node) xpath.evaluate("<%= name %>", node, XPathConstants.NODE);
109 | if (childNode != null && !isWhitespaceNode(childNode)) {
110 | <% if find_basic_type(definition.type) == 'String' %>
111 | this.<%= vname %> = childNode.getTextContent();
112 | <% elsif find_basic_type(definition.type) == 'Integer' %>
113 | this.<%= vname %> = Integer.valueOf(childNode.getTextContent());
114 | <% elsif find_basic_type(definition.type) == 'Boolean' %>
115 | this.<%= vname %> = Boolean.valueOf(childNode.getTextContent());
116 | <% elsif find_basic_type(definition.type) == 'Double' %>
117 | this.<%= vname %> = Double.valueOf(childNode.getTextContent());
118 | <% elsif find_basic_type(definition.type) == 'Float' %>
119 | this.<%= vname %> = Float.valueOf(childNode.getTextContent());
120 | <% end %>
121 | }
122 | <% end %>
123 | <% end %>
124 | <% end %>
125 | <% end %>
126 | <% type = schema.data_types[type.extends] %>
127 | <% end %>
128 | }
129 |
--------------------------------------------------------------------------------
/templates/sdk.wsdlservice_dotnet.erb:
--------------------------------------------------------------------------------
1 | <%
2 | #
3 | # Copyright 2013 PayPal Inc.
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 | # http://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 | #
18 | %>
19 | <% service_imports(schema, service, package).each do |import| %>
20 | using <%= import %>;
21 | <% end %>
22 | namespace <%= package %>
23 | {
24 | public class <%= validate_class_name(classname) %> : BasePayPalService
25 | {
26 |
27 | static <%= validate_class_name(classname) %>()
28 | {
29 | DefaultSOAPAPICallHandler.XMLNamespaceProvider = new XmlNamespacePrefixProvider();
30 | }
31 |
32 | ///
33 | /// Service Version
34 | ///
35 | private const string ServiceVersion = "";
36 |
37 | ///
38 | /// Service Name
39 | ///
40 | private const string ServiceName = "<%= classname %>";
41 |
42 | ///
43 | /// SDK Name
44 | ///
45 | private const string SDKName = "";
46 |
47 | ///
48 | /// SDK Version
49 | ///
50 | private const string SDKVersion = "";
51 |
52 | ///
53 | /// Default constructor for loading configuration from *.Config file
54 | ///
55 | public <%= validate_class_name(classname) %>() : base()
56 | {
57 |
58 | }
59 |
60 | ///
61 | /// constructor for passing in a dynamic configuration object
62 | ///
63 | public <%= validate_class_name(classname) %>(Dictionary config) : base(config)
64 | {
65 |
66 | }
67 |
68 | <% service.operations.each do |name, definition| %>
69 | <% methodname = validate_method_name(name) %>
70 | <% argumentHash = get_wsdl_operation_arguments(definition) %>
71 | ///
72 | ///
73 | ///
74 | <% if argumentHash.size > 0 %>
75 | <% argumentHash.each do |name, type| %>
76 | /// <%= type %> request argument
77 | <% end %>
78 | <% end %>
79 | /// APIContext argument
80 | public <%= definition.response %> <%= methodname %>(<% if argumentHash.size > 0 %><%= argumentHash.map{|name, type| "#{type.camelcase} #{name}"}.join(", ") %><% end %>, APIContext apiContext)
81 | {
82 | if (apiContext == null)
83 | {
84 | throw new ArgumentNullException("APIContext is null");
85 | }
86 | if (apiContext.HTTPHeaders == null)
87 | {
88 | apiContext.HTTPHeaders = new Dictionary();
89 | }
90 | <%
91 | if definition.soapAction.blank?
92 | soapAction = "\"\""
93 | else
94 | soapAction = definition.soapAction
95 | end
96 | %>
97 | apiContext.HTTPHeaders.Add("SOAPAction", <%= soapAction.inspect %>);
98 | DefaultSOAPAPICallHandler apiCallPreHandler = new DefaultSOAPAPICallHandler(<% if argumentHash.size > 0 %><%= argumentHash.map{|name, type| "#{name}"}.join(", ") %><% end %>, apiContext, this.config, "<%= name %>");
99 | XmlDocument xmlDocument = new XmlDocument();
100 | string response = Call(apiCallPreHandler);
101 | xmlDocument.LoadXml(response);
102 | <%= definition.response %> <%= validate_property_as_argument(definition.response) %> = null;
103 | XmlNode xmlNode = xmlDocument.SelectSingleNode("*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='<%= definition.response_property.name %>']");
104 | if (xmlNode != null)
105 | {
106 | <%= validate_property_as_argument(definition.response) %> = new <%= definition.response %>(xmlNode);
107 | }
108 | <% if definition.fault %>
109 | else
110 | {
111 | xmlNode = xmlDocument.SelectSingleNode("*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='Fault']/*[local-name()='detail']/*[local-name()='<%= definition.fault %>']");
112 | if (xmlNode != null)
113 | {
114 | <%= definition.fault_property.name %> faultMessage = new <%= definition.fault_property.name %>(xmlNode);
115 | throw faultMessage;
116 | }
117 | else
118 | {
119 | throw new Exception("Unable to parse response, response = " + response);
120 | }
121 |
122 | }
123 | <% end %>
124 | return <%= validate_property_as_argument(definition.response) %>;
125 | }
126 |
127 |
128 | <% end %>
129 |
130 | private class XmlNamespacePrefixProvider : DefaultSOAPAPICallHandler.XmlNamespaceProvider
131 | {
132 |
133 | ///
134 | /// Namespace Dictionary instance
135 | ///
136 | private Dictionary namespaceDictionary;
137 |
138 | public XmlNamespacePrefixProvider()
139 | {
140 | namespaceDictionary = new Dictionary();
141 | <% schema.namespaces.each do |namespace, prefix| %>
142 | <% if prefix != '' %>
143 | namespaceDictionary.Add("<%= prefix %>", "<%= namespace %>");
144 | <% end %>
145 | <% end %>
146 | }
147 |
148 | public Dictionary GetNamespaceDictionary()
149 | {
150 | return namespaceDictionary;
151 | }
152 | }
153 | }
154 | }
155 |
--------------------------------------------------------------------------------
/templates/sdk.wsdlsoapdeserialize_dotnet.erb:
--------------------------------------------------------------------------------
1 | <%
2 | #
3 | # Copyright 2013 PayPal Inc.
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 | # http://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 | #
18 | %>
19 | ///
20 | /// Checks whether the node is empty space
21 | ///
22 | public static bool IsWhiteSpaceNode(XmlNode n)
23 | {
24 | if (n.NodeType == XmlNodeType.Text)
25 | {
26 | string val = n.InnerText;
27 | return (val.Trim().Length == 0);
28 | }
29 | else if (n.NodeType == XmlNodeType.Element)
30 | {
31 | return (n.ChildNodes.Count == 0);
32 | }
33 | else
34 | {
35 | return false;
36 | }
37 | }
38 |
39 | ///
40 | /// Constructor using XmlNode parameter
41 | ///
42 | public <%= classname %> (XmlNode xmlNode)
43 | {
44 | XmlNode ChildNode = null;
45 | XmlNodeList ChildNodeList = null;
46 | <% type = data_type %>
47 | <% while type %>
48 | <% type.properties.each do |name , definition| %>
49 | <% vname = validate_property_name(name, true) %>
50 | <% if definition.array %>
51 | ChildNodeList = xmlNode.SelectNodes("*[local-name() = '<%= name %>']");
52 | if (ChildNodeList != null && ChildNodeList.Count > 0)
53 | {
54 | for(int i = 0; i < ChildNodeList.Count; i++)
55 | {
56 | <% if is_complex_type(definition.type, schema) || is_enum_type(definition.type, schema) %>
57 | <% if definition.enum %>
58 | string value = ChildNodeList[i].InnerText;
59 | this.<%= vname %>.Add((<%= validate_class_name(definition.type) %>)ReflectionEnumUtil.GetValue(value, typeof(<%= validate_class_name(definition.type) %>)));
60 | <% else %>
61 | XmlNode subNode = ChildNodeList.Item(i);
62 | this.<%= vname %>.Add(new <%= validate_class_name(definition.type) %>(subNode));
63 |
64 | <% end %>
65 | <% else %>
66 | string value = ChildNodeList[i].InnerText;
67 | <% if find_basic_type(definition.type) == 'string' %>
68 | this.<%= vname %>.Add(value);
69 | <% elsif find_basic_type(definition.type) == 'int' %>
70 | this.<%= vname %>.Add(System.Convert.ToInt32(value));
71 | <% elsif find_basic_type(definition.type) == 'bool' %>
72 | this.<%= vname %>.Add(System.Convert.ToBoolean(value));
73 | <% elsif find_basic_type(definition.type) == 'double' %>
74 | this.<%= vname %>.add(System.Convert.ToDouble(value));
75 | <% elsif find_basic_type(definition.type) == 'float' %>
76 | this.<%= vname %>.add(System.Convert.ToSingle(value));
77 | <% end %>
78 | <% end %>
79 | }
80 | }
81 | <% else %> // array
82 | <% if is_complex_type(definition.type, schema) || is_enum_type(definition.type, schema) %>
83 | <% if definition.enum %>
84 | <% if definition.attribute %>
85 | ChildNode = xmlNode.SelectSingleNode("@*[local-name() = '<%= name %>']");
86 | if (ChildNode != null)
87 | {
88 | this.<%= vname %> = (<%= validate_class_name(definition.type) %>)ReflectionEnumUtil.GetValue(ChildNode.Value, typeof(<%= validate_class_name(definition.type) %>));
89 | }
90 | <% else %> // attribute
91 | ChildNode = xmlNode.SelectSingleNode("*[local-name() = '<%= name %>']");
92 | if(ChildNode != null && !IsWhiteSpaceNode(ChildNode))
93 | {
94 | this.<%= vname %> = (<%= validate_class_name(definition.type) %>)ReflectionEnumUtil.GetValue(ChildNode.InnerText,typeof(<%= validate_class_name(definition.type) %>));
95 | }
96 | <% end %> // attribute
97 | <% else %> // non-enum
98 | ChildNode = xmlNode.SelectSingleNode("*[local-name() = '<%= name %>']");
99 | if(ChildNode != null && !IsWhiteSpaceNode(ChildNode))
100 | {
101 | this.<%= vname %> = new <%= validate_class_name(definition.type) %>(ChildNode);
102 | }
103 | <% end %> // enum
104 | <% else %> // complex
105 | <% if definition.value == '1' %>
106 | <% if find_basic_type(definition.type) == 'string' %>
107 | this.<%= vname %> = xmlNode.InnerText;
108 | <% elsif find_basic_type(definition.type) == 'int' %>
109 | this.<%= vname %> = System.Convert.ToInt32(xmlNode.InnerText);
110 | <% elsif find_basic_type(definition.type) == 'bool' %>
111 | this.<%= vname %> = System.Convert.ToBoolean(xmlNode.InnerText);
112 | <% elsif find_basic_type(definition.type) == 'double' %>
113 | this.<%= vname %> = System.Convert.ToDouble(xmlNode.InnerText);
114 | <% elsif find_basic_type(definition.type) == 'float' %>
115 | this.<%= vname %> = System.Convert.ToSingle(xmlNode.InnerText);
116 | <% end %>
117 | <% else %> // value
118 | ChildNode = xmlNode.SelectSingleNode("*[local-name() = '<%= name %>']");
119 | if(ChildNode != null && !IsWhiteSpaceNode(ChildNode))
120 | {
121 | <% if find_basic_type(definition.type) == 'string' %>
122 | this.<%= vname %> = ChildNode.InnerText;
123 | <% elsif find_basic_type(definition.type) == 'int' %>
124 | this.<%= vname %> = System.Convert.ToInt32(ChildNode.InnerText);
125 | <% elsif find_basic_type(definition.type) == 'bool' %>
126 | this.<%= vname %> = System.Convert.ToBoolean(ChildNode.InnerText);
127 | <% elsif find_basic_type(definition.type) == 'double' %>
128 | this.<%= vname %> = System.Convert.ToDouble(ChildNode.InnerText);
129 | <% elsif find_basic_type(definition.type) == 'float' %>
130 | this.<%= vname %> = System.Convert.ToSingle(ChildNode.InnerText);
131 | <% end %>
132 | }
133 | <% end %> // value
134 | <% end %> // complex
135 | <% end %> // array
136 | <% end %>
137 | <% type = schema.data_types[type.extends] %>
138 | <% end %>
139 | }
140 |
--------------------------------------------------------------------------------
/templates/sdk.wsdlservice_java.erb:
--------------------------------------------------------------------------------
1 | <%
2 | #
3 | # Copyright 2013 PayPal Inc.
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 | # http://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 | #
18 | %>
19 | package <%= package %>;
20 |
21 | <% service_imports(schema, service, package).each do |import| %>
22 | import <%= import %>;
23 | <% end %>
24 |
25 | public class <%= validate_class_name(classname) %> extends BaseService {
26 |
27 | static {
28 | DefaultSOAPAPICallHandler.setXmlNamespaceProvider(new XmlNamespacePrefixProvider());
29 | }
30 |
31 | // Service Version
32 | public static final String SERVICE_VERSION = "";
33 |
34 | // Service Name
35 | public static final String SERVICE_NAME = "<%= classname %>";
36 |
37 | //SDK Name
38 | private static final String SDK_NAME = "";
39 |
40 | //SDK Version
41 | private static final String SDK_VERSION = "";
42 |
43 | /**
44 | * Default <%= validate_class_name(classname) %> Constructor.
45 | * Initializes the SDK system with the default configuration file named
46 | * 'sdk_config.properties' found in the class-path
47 | */
48 | public <%= validate_class_name(classname) %>() {
49 | super.initializeToDefault();
50 | }
51 |
52 | /**
53 | * <%= validate_class_name(classname) %> that uses the supplied
54 | * {@link Properties} to initialize the SDK system. For values that the
55 | * properties should holdconsult the documentation.
56 | * The initialization context is maintained only for
57 | * this instance of the class. Service level configuration.
58 | *
59 | * @param properties
60 | * {@link Properties} object
61 | */
62 | public <%= validate_class_name(classname) %>(Properties properties) {
63 | super(properties);
64 | }
65 |
66 | /**
67 | * <%= validate_class_name(classname) %> that uses the supplied
68 | * {@link Map} to initialize the SDK system. For values that the
69 | * configurationMap should hold consult the documentation.
70 | * The initialization context is maintained only for
71 | * this instance of the class. Service level configuration.
72 | *
73 | * @param configurationMap
74 | * {@link Map} object
75 | */
76 | public <%= validate_class_name(classname) %>(Map configurationMap) {
77 | super(configurationMap);
78 | }
79 |
80 | <% service.operations.each do |name, definition| %>
81 | <% methodname = validate_method_name(name) %>
82 | <% argumentHash = get_wsdl_operation_arguments(definition) %>
83 | public <%= definition.response %> <%= methodname %>(<% if argumentHash.size > 0 %><%= argumentHash.map{|name, type| "#{type.camelcase} #{name}"}.join(", ") %><% end %>, BaseAPIContext baseAPIContext) throws SAXException, IOException, ParserConfigurationException, InvalidResponseDataException, HttpErrorException, ClientActionRequiredException, InvalidCredentialException, MissingCredentialException, OAuthException, SSLConfigurationException, InterruptedException {
84 | if (baseAPIContext == null) {
85 | throw new IllegalArgumentException("BaseAPIContext is null");
86 | }
87 | if (baseAPIContext.getHTTPHeaders() == null) {
88 | baseAPIContext.setHTTPHeaders(new HashMap());
89 | }
90 | <%
91 | if definition.soapAction.blank?
92 | soapAction = "\"\""
93 | else
94 | soapAction = definition.soapAction
95 | end
96 | %>
97 | baseAPIContext.getHTTPHeaders().put("SOAPAction", <%= soapAction.inspect %>);
98 | APICallPreHandler apiCallPreHandler = new DefaultSOAPAPICallHandler(<% if argumentHash.size > 0 %><%= argumentHash.map{|name, type| "#{name}"}.join(", ") %><% end %>, baseAPIContext, this.configurationMap, "<%= name %>");
99 | String response = call(apiCallPreHandler);
100 | InputSource inStream = new InputSource();
101 | inStream.setCharacterStream(new StringReader((String) response));
102 | try {
103 | Node node = (Node) XPathFactory.newInstance().newXPath().evaluate("Envelope/Body/<%= definition.response_property.name %>", DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inStream), XPathConstants.NODE);
104 | return new <%= definition.response %>(node);
105 | } catch (XPathExpressionException exe) {
106 | <% if definition.fault %>
107 | try {
108 | inStream = new InputSource();
109 | inStream.setCharacterStream(new StringReader((String) response));
110 | Node node = (Node) XPathFactory.newInstance().newXPath().evaluate("Envelope/Body/Fault/detail/<%= definition.fault %>", DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inStream), XPathConstants.NODE);
111 | <%= definition.fault_property.name %> faultException = new <%= definition.fault_property.name %>(node);
112 | throw faultException;
113 | } catch (XPathExpressionException e) {
114 | throw new RuntimeException("Unable to parse response", e);
115 | }
116 | <% else %>
117 | throw new RuntimeException("Unable to parse response", exe);
118 | <% end %>
119 | }
120 | }
121 |
122 | <% end %>
123 |
124 | /**
125 | * Implementation of DefaultSOAPAPICallHandler.XmlNamespaceProvider
126 | */
127 | private static class XmlNamespacePrefixProvider implements XmlNamespaceProvider {
128 |
129 | private Map namespaceMap;
130 |
131 | public XmlNamespacePrefixProvider() {
132 | namespaceMap = new HashMap();
133 | <% schema.namespaces.each do |namespace, prefix| %>
134 | <% if prefix != '' %>
135 | namespaceMap.put("<%= prefix %>", "<%= namespace %>");
136 | <% end %>
137 | <% end %>
138 | }
139 |
140 | public Map getNamespaceMap() {
141 | return namespaceMap;
142 | }
143 | }
144 |
145 | }
146 |
--------------------------------------------------------------------------------
/templates/sdk.wsdlsoapserialize_java.erb:
--------------------------------------------------------------------------------
1 | <%
2 | #
3 | # Copyright 2013 PayPal Inc.
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 | # http://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 | #
18 | %>
19 | <% if operation_input %>
20 | public String toXMLString() {
21 | return toXMLString("<%= serialization_name.split(':').first %>", "<%= serialization_name.split(':').last %>");
22 | }
23 | <% end %>
24 |
25 | /**
26 | * Serialize the object to XML String form
27 | * @param prefix
28 | * Namespace prefix to use during serialization
29 | * @param name
30 | * Name used for serialization
31 | */
32 | public String toXMLString(String prefix, String name) {
33 | StringBuilder sb = new StringBuilder();
34 | if (name != null) {
35 | <% if contains_attribute(data_type) %>
36 | if (prefix != null) {
37 | sb.append("<").append(prefix + ":").append(name);
38 | } else {
39 | sb.append("<").append(name);
40 | }
41 | sb.append(getAttributeAsXml());
42 | sb.append(">");
43 | <% else %>
44 | if (prefix != null) {
45 | sb.append("<").append(prefix + ":").append(name).append(">");
46 | } else {
47 | sb.append("<").append(name).append(">");
48 | }
49 | <% end %>
50 | }
51 | <% type = data_type %>
52 | <% while type %>
53 | <% type.properties.each do |name , definition| %>
54 | <% if !definition.attribute %>
55 | <% vname = validate_property_name(name) %>
56 | if (this.<%= vname %> != null) {
57 | <% if definition.array %>
58 | for (int i=0; i < this.<%= vname %>.size(); i++) {
59 | <% if is_complex_type(definition.type, schema) || is_enum_type(definition.type, schema) %>
60 | <% if definition.enum %>
61 | sb.append("<");
62 | <% if should_qualify_name(definition.package, schema) %>
63 | sb.append("<%= definition.package %>:");
64 | <% end %>
65 | sb.append("<%= name %>>").append(SDKUtil.escapeInvalidXmlCharsRegex(this.<%= vname %>.get(i).getValue())).append("");
66 | <% if should_qualify_name(definition.package, schema) %>
67 | sb.append("<%= definition.package %>:");
68 | <% end %>
69 | sb.append("<%= name %>>");
70 | <% else %>
71 | <% if should_qualify_name(definition.package, schema) %>
72 | sb.append(this.<%= vname %>.get(i).toXMLString("<%= definition.package %>","<%= name %>"));
73 | <% else %>
74 | sb.append(this.<%= vname %>.get(i).toXMLString(null,"<%= name %>"));
75 | <% end %>
76 | <% end %>
77 | <% else %>
78 | <% if definition.value == '1' %>
79 | sb.append(SDKUtil.escapeInvalidXmlCharsRegex(value.get(i)));
80 | <% else %>
81 | sb.append("<");
82 | <% if should_qualify_name(definition.package, schema) %>
83 | sb.append("<%= definition.package %>:");
84 | <% end %>
85 | sb.append("<%= name %>>").append(SDKUtil.escapeInvalidXmlCharsRegex(this.<%= vname %>.get(i)));
86 | sb.append("");
87 | <% if should_qualify_name(definition.package, schema) %>
88 | sb.append("<%= definition.package %>:");
89 | <% end %>
90 | sb.append("<%= name %>>");
91 | <% end %>
92 | <% end %>
93 | }
94 | <% else %>
95 | <% if is_complex_type(definition.type, schema) || is_enum_type(definition.type, schema) %>
96 | <% if definition.enum %>
97 | sb.append("<");
98 | <% if should_qualify_name(definition.package, schema) %>
99 | sb.append("<%= definition.package %>:");
100 | <% end %>
101 | sb.append("<%= name %>>").append(SDKUtil.escapeInvalidXmlCharsRegex(this.<%= vname %>.getValue())).append("");
102 | <% if should_qualify_name(definition.package, schema) %>
103 | sb.append("<%= definition.package %>:");
104 | <% end %>
105 | sb.append("<%= name %>>");
106 | <% else %>
107 | <% if should_qualify_name(definition.package, schema) %>
108 | sb.append(this.<%= vname %>.toXMLString("<%= definition.package %>","<%= name %>"));
109 | <% else %>
110 | sb.append(this.<%= vname %>.toXMLString(null, "<%= name %>"));
111 | <% end %>
112 | <% end %>
113 | <% else %>
114 | <% if definition.value == '1' %>
115 | sb.append(SDKUtil.escapeInvalidXmlCharsRegex(value));
116 | <% else %>
117 | sb.append("<");
118 | <% if should_qualify_name(definition.package, schema) %>
119 | sb.append("<%= definition.package %>:");
120 | <% end %>
121 | sb.append("<%= name %>>");
122 | sb.append(SDKUtil.escapeInvalidXmlCharsRegex(this.<%= vname %>));
123 | sb.append("");
124 | <% if should_qualify_name(definition.package, schema) %>
125 | sb.append("<%= definition.package %>:");
126 | <% end %>
127 | sb.append("<%= name %>>");
128 | <% end %>
129 | <% end %>
130 | <% end %>
131 | }
132 | <% end %>
133 | <% end %>
134 | <% type = schema.data_types[type.extends] %>
135 | <% end %>
136 | if (name != null) {
137 | if (prefix != null) {
138 | sb.append("").append(prefix + ":").append(name).append(">");
139 | } else {
140 | sb.append("").append(name).append(">");
141 | }
142 | }
143 | return sb.toString();
144 | }
145 |
146 | <% if contains_attribute(data_type) %>
147 | /**
148 | * Serializes attributes if any
149 | */
150 | private String getAttributeAsXml() {
151 | StringBuilder sb = new StringBuilder();
152 | <% type = data_type %>
153 | <% while type %>
154 | <% type.properties.each do |name , definition| %>
155 | <% if definition.attribute %>
156 | <% vname = validate_property_name(name) %>
157 | if (this.<%= vname %> != null) {
158 | <% if definition.enum %>
159 | sb.append(" <%= name %>=\"").append(SDKUtil.escapeInvalidXmlCharsRegex(this.<%= vname %>.getValue())).append("\"");
160 | <% else %>
161 | sb.append(" <%= name %>=\"").append(SDKUtil.escapeInvalidXmlCharsRegex(this.<%= vname %>)).append("\"");
162 | <% end %>
163 | }
164 | <% end %>
165 | <% end %>
166 | <% type = schema.data_types[type.extends] %>
167 | <% end %>
168 | return sb.toString();
169 | }
170 | <% end %>
171 |
--------------------------------------------------------------------------------
/spec/php_spec.rb:
--------------------------------------------------------------------------------
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 'spec_helper'
18 |
19 | describe 'PHPHelper' do
20 |
21 | before :all do
22 | @php_helper = Class.new do
23 | include Genio::Util::NamespaceHelper
24 | include Genio::Helper::PHP
25 | end.new
26 | end
27 |
28 | it "get basic types" do
29 | @php_helper.find_basic_type("int").should eq "integer"
30 | @php_helper.find_basic_type("integer").should eq "integer"
31 | @php_helper.find_basic_type("positiveInteger").should eq "integer"
32 | @php_helper.find_basic_type("nonNegativeInteger").should eq "integer"
33 | @php_helper.find_basic_type("long").should eq "long"
34 | @php_helper.find_basic_type("double").should eq "double"
35 | @php_helper.find_basic_type("decimal").should eq "double"
36 | @php_helper.find_basic_type("float").should eq "float"
37 | @php_helper.find_basic_type("boolean").should eq "boolean"
38 | @php_helper.find_basic_type("string").should eq "string"
39 | @php_helper.find_basic_type("dateTime").should eq "string"
40 | @php_helper.find_basic_type("date").should eq "string"
41 | @php_helper.find_basic_type("number").should eq "number"
42 | @php_helper.find_basic_type("object").should eq "object"
43 | @php_helper.find_basic_type("token").should eq "string"
44 | @php_helper.find_basic_type("duration").should eq "string"
45 | @php_helper.find_basic_type("anyURI").should eq "string"
46 | @php_helper.find_basic_type("date_time").should eq "string"
47 | @php_helper.find_basic_type("base64Binary").should eq "string"
48 | @php_helper.find_basic_type("time").should eq "string"
49 | @php_helper.find_basic_type("customType").should eq "CustomType"
50 | @php_helper.find_basic_type("CustomType").should eq "CustomType"
51 | end
52 |
53 | it "get property type" do
54 | property = Genio::Parser::Types::Property.new( :type => 'self' )
55 | schema = Genio::Parser::Format::JsonSchema.new()
56 | schema.enum_types["Test"] = { }
57 | @php_helper.get_php_type(property, schema, 'HostClass').should eq "HostClass"
58 | property = Genio::Parser::Types::Property.new( :type => 'Test' )
59 | @php_helper.get_php_type(property, schema, 'HostClass').should eq "string"
60 | property = Genio::Parser::Types::Property.new( :type => 'integer' )
61 | @php_helper.get_php_type(property, schema, 'HostClass').should eq "integer"
62 | property = Genio::Parser::Types::Property.new( :type => 'date_time' )
63 | @php_helper.get_php_type(property, schema, 'HostClass').should eq "string"
64 | end
65 |
66 | it "test process path with placeholders" do
67 | @php_helper.process_path_with_placeholders('Payment', 'Payment', '/v1/payments/{payment-id}', true, nil, nil).should eq '"/v1/payments/{$this->getId()}"'
68 | argument_hash = {}
69 | argument_hash['payment_id'] = 'string'
70 | query_params = {}
71 | @php_helper.process_path_with_placeholders('Payment', 'Payment', '/v1/payments/{payment-id}', false, argument_hash, nil).should eq '"/v1/payments/$payment_id"'
72 | @php_helper.process_path_with_placeholders('Payment', 'Payment', '/v1/payments/{payment-id}', false, argument_hash, query_params).should eq '"/v1/payments/$payment_id?" . http_build_query($queryParameters)'
73 | @php_helper.process_path_with_placeholders('Payment', 'Payment', '/v1/payments/{payment-id}', true, argument_hash, query_params).should eq '"/v1/payments/{$this->getId()}?" . http_build_query($queryParameters)'
74 | end
75 |
76 | it "validate class name" do
77 | @php_helper.valid_class_name('class-name').should eq "ClassName"
78 | @php_helper.valid_class_name('Class-Name').should eq "ClassName"
79 | @php_helper.valid_class_name('class-Name').should eq "ClassName"
80 | @php_helper.valid_class_name('Class-name').should eq "ClassName"
81 | @php_helper.valid_class_name('class_name').should eq "ClassName"
82 | @php_helper.valid_class_name('Class_Name').should eq "ClassName"
83 | @php_helper.valid_class_name('class_Name').should eq "ClassName"
84 | @php_helper.valid_class_name('Class_name').should eq "ClassName"
85 | @php_helper.valid_class_name('classname').should eq "Classname"
86 | end
87 |
88 | it "validate property name" do
89 | @php_helper.valid_property_name('property-name').should eq 'propertyName'
90 | @php_helper.valid_property_name('Property-name').should eq 'propertyName'
91 | @php_helper.valid_property_name('Property-Name').should eq 'propertyName'
92 | @php_helper.valid_property_name('property-Name').should eq 'propertyName'
93 | @php_helper.valid_property_name('propertyname').should eq 'propertyname'
94 | end
95 |
96 | it "get deprecated function name" do
97 | @php_helper.deprecated_function_name('function-name').should eq 'Function_name'
98 | @php_helper.deprecated_function_name('function_name').should eq 'Function_name'
99 | @php_helper.deprecated_function_name('functionname').should eq 'Functionname'
100 | end
101 |
102 | it "validate method name" do
103 | @php_helper.validate_method_name('function-name').should eq 'functionName'
104 | @php_helper.validate_method_name('function_name').should eq 'functionName'
105 | @php_helper.validate_method_name('functionname').should eq 'functionname'
106 | @php_helper.validate_method_name('abstract').should eq 'doAbstract'
107 | end
108 |
109 | it "validate package name" do
110 | @php_helper.validated_package('com.paypal.api').should eq 'Paypal\\Api'
111 | end
112 |
113 | it "test to underscore" do
114 | @php_helper.to_underscore('underscore-me').should eq 'underscore_me'
115 | @php_helper.to_underscore('Underscore-Me').should eq 'Underscore_Me'
116 | @php_helper.to_underscore('UnderscoreMe').should eq 'UnderscoreMe'
117 | end
118 |
119 | end
120 |
--------------------------------------------------------------------------------
/templates/sdk.wsdlsoapserialize_dotnet.erb:
--------------------------------------------------------------------------------
1 | <%
2 | #
3 | # Copyright 2013 PayPal Inc.
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 | # http://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 | #
18 | %>
19 | <% if operation_input %>
20 | public String ToXMLString()
21 | {
22 | return ToXMLString("<%= serialization_name.split(':').first %>", "<%= serialization_name.split(':').last %>");
23 | }
24 | <% end %>
25 |
26 | ///
27 | /// Serialize the object to XML String form
28 | ///
29 | public String ToXMLString(string prefix, string name)
30 | {
31 | StringBuilder sb = new StringBuilder();
32 | if (name != null)
33 | {
34 | <% if contains_attribute(data_type) %>
35 | if (prefix != null)
36 | {
37 | sb.Append("<").Append(prefix + ":").Append(name);
38 | }
39 | else
40 | {
41 | sb.Append("<").Append(name);
42 | }
43 | sb.Append(GetAttributeAsXml());
44 | sb.Append(">");
45 | <% else %>
46 | if (prefix != null)
47 | {
48 | sb.Append("<").Append(prefix + ":").Append(name).Append(">");
49 | }
50 | else
51 | {
52 | sb.Append("<").Append(name).Append(">");
53 | }
54 | <% end %>
55 | }
56 | <% type = data_type %>
57 | <% while type %>
58 | <% type.properties.each do |name , definition| %>
59 | <% if !definition.attribute %>
60 | <% vname = validate_property_name(name, true) %>
61 | if (this.<%= vname %> != null)
62 | {
63 | <% if definition.array %>
64 | for (int i = 0; i < this.<%= vname %>.Count; i++)
65 | {
66 | <% if is_complex_type(definition.type, schema) || is_enum_type(definition.type, schema) %>
67 | <% if definition.enum %>
68 | sb.Append("<");
69 | <% if should_qualify_name(definition.package, schema) %>
70 | sb.Append("<%= definition.package %>:");
71 | <% end %>
72 | sb.Append("<%= name %>>").Append(SDKUtil.EscapeInvalidXmlCharsRegex(ReflectionEnumUtil.GetDescription(this.<%= vname %>[i]))).Append("");
73 | <% if should_qualify_name(definition.package, schema) %>
74 | sb.Append("<%= definition.package %>:");
75 | <% end %>
76 | sb.Append("<%= name %>>");
77 | <% else %>
78 | <% if should_qualify_name(definition.package, schema) %>
79 | sb.Append(this.<%= vname %>[i].ToXMLString("<%= definition.package %>","<%= name %>"));
80 | <% else %>
81 | sb.Append(this.<%= vname %>[i].ToXMLString(null,"<%= name %>"));
82 | <% end %>
83 | <% end %>
84 | <% else %>
85 | <% if definition.value == '1' %>
86 | sb.Append(SDKUtil.EscapeInvalidXmlCharsRegex(<% if find_basic_type(definition.type) == 'double' %>Convert.ToString(Value[i], DefaultCulture)<% else %>Value[i]<% end %>));
87 | <% else %>
88 | sb.Append("<");
89 | <% if should_qualify_name(definition.package, schema) %>
90 | sb.Append("<%= definition.package %>:");
91 | <% end %>
92 | sb.Append("<%= name %>>").Append(SDKUtil.EscapeInvalidXmlCharsRegex(<% if find_basic_type(definition.type) == 'double' %>Convert.ToString(this.<%= vname %>[i], DefaultCulture)<% else %>this.<%= vname %>[i]<% end %>));
93 | sb.Append("");
94 | <% if should_qualify_name(definition.package, schema) %>
95 | sb.Append("<%= definition.package %>:");
96 | <% end %>
97 | sb.Append("<%= name %>>");
98 | <% end %>
99 | <% end %>
100 | }
101 | <% else %>
102 | <% if is_complex_type(definition.type, schema) || is_enum_type(definition.type, schema) %>
103 | <% if definition.enum %>
104 | sb.Append("<");
105 | <% if should_qualify_name(definition.package, schema) %>
106 | sb.Append("<%= definition.package %>:");
107 | <% end %>
108 | sb.Append("<%= name %>>").Append(SDKUtil.EscapeInvalidXmlCharsRegex(ReflectionEnumUtil.GetDescription(this.<%= vname %>))).Append("");
109 | <% if should_qualify_name(definition.package, schema) %>
110 | sb.Append("<%= definition.package %>:");
111 | <% end %>
112 | sb.Append("<%= name %>>");
113 | <% else %>
114 | <% if should_qualify_name(definition.package, schema) %>
115 | sb.Append(this.<%= vname %>.ToXMLString("<%= definition.package %>","<%= name %>"));
116 | <% else %>
117 | sb.Append(this.<%= vname %>.ToXMLString(null, "<%= name %>"));
118 | <% end %>
119 | <% end %>
120 | <% else %>
121 | <% if definition.value == '1' %>
122 | sb.Append(SDKUtil.EscapeInvalidXmlCharsRegex(<% if find_basic_type(definition.type) == 'double' %>Convert.ToString(Value, DefaultCulture)<% else %>Value<% end %>));
123 | <% else %>
124 | sb.Append("<");
125 | <% if should_qualify_name(definition.package, schema) %>
126 | sb.Append("<%= definition.package %>:");
127 | <% end %>
128 | sb.Append("<%= name %>>");
129 | sb.Append(SDKUtil.EscapeInvalidXmlCharsRegex(<% if find_basic_type(definition.type) == 'double' %>Convert.ToString(this.<%= vname %>, DefaultCulture)<% else %>this.<%= vname %><% end %>));
130 | sb.Append("");
131 | <% if should_qualify_name(definition.package, schema) %>
132 | sb.Append("<%= definition.package %>:");
133 | <% end %>
134 | sb.Append("<%= name %>>");
135 | <% end %>
136 | <% end %>
137 | <% end %>
138 | }
139 | <% end %>
140 | <% end %>
141 | <% type = schema.data_types[type.extends] %>
142 | <% end %>
143 | if (name != null)
144 | {
145 | if (prefix != null)
146 | {
147 | sb.Append("").Append(prefix + ":").Append(name).Append(">");
148 | }
149 | else
150 | {
151 | sb.Append("").Append(name).Append(">");
152 | }
153 | }
154 | return sb.ToString();
155 | }
156 |
157 | <% if contains_attribute(data_type) %>
158 |
159 | ///
160 | /// Serializes attributes if any
161 | ///
162 | private String GetAttributeAsXml()
163 | {
164 | StringBuilder sb = new StringBuilder();
165 | <% type = data_type %>
166 | <% while type %>
167 | <% type.properties.each do |name , definition| %>
168 | <% if definition.attribute %>
169 | <% vname = validate_property_name(name, true) %>
170 | if (this.<%= vname %> != null)
171 | {
172 | <% if definition.enum %>
173 | sb.Append(" <%= name %>=\"").Append(SDKUtil.EscapeInvalidXmlCharsRegex(ReflectionEnumUtil.GetDescription(this.<%= vname %>))).Append("\"");
174 | <% else %>
175 | sb.Append(" <%= name %>=\"").Append(SDKUtil.EscapeInvalidXmlCharsRegex(this.<%= vname %>)).Append("\"");
176 | <% end %>
177 | }
178 | <% end %>
179 | <% end %>
180 | <% type = schema.data_types[type.extends] %>
181 | <% end %>
182 | return sb.ToString();
183 | }
184 | <% end %>
185 |
--------------------------------------------------------------------------------
/templates/sdk.rest_dotnet.erb:
--------------------------------------------------------------------------------
1 | <%
2 | #
3 | # Copyright 2013 PayPal Inc.
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 | # http://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 | #
18 | %>
19 | <% imports(data_type, schema, package, classname, "rest").each do |import| %>
20 | using <%= import %>;
21 | <% end %>
22 |
23 | namespace <%= package %>
24 | {
25 | public class <%= validate_class_name(classname) %><%= " : #{validate_class_name(data_type.extends)}" if data_type.extends %>
26 | {
27 | <% const_args = {} %>
28 | <% data_type.properties.each do |name, property| %>
29 | <% vname = validate_property_name(name) %>
30 | <% const_args[vname] = get_property_class(property, classname) if property.required %>
31 | private <%= get_property_class(property, classname) %><%= '?' if (is_nullable_type(property) and !property.array) %> <%= vname %>Property;
32 |
33 | ///
34 | /// <%= property.description %>
35 | ///
36 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
37 | public <%= get_property_class(property, classname) %><%= '?' if (is_nullable_type(property) and !property.array) %> <%= vname %>
38 | {
39 | get
40 | {
41 | return this.<%= vname %>Property;
42 | }
43 | set
44 | {
45 | this.<%= vname %>Property = value;
46 | }
47 | }
48 |
49 | <% end %>
50 | ///
51 | /// Default Constructor
52 | ///
53 | public <%= validate_class_name(classname) %>()
54 | {
55 | }
56 |
57 | <% if const_args.size > 0 %>
58 | ///
59 | /// Parameterized Constructor
60 | ///
61 | public <%= validate_class_name(classname) %>(<%= const_args.map{|name, type| "#{type} #{name}"}.join(", ") %>)
62 | {
63 | <% const_args.each do |name, type| %>
64 | this.<%= name %> = <%= name %>;
65 | <% end %>
66 | }
67 | <% end %>
68 |
69 | <% service = schema.services[classname] %>
70 | <% if service %>
71 | <% service.operations.each do |name, property| %>
72 | <% static = is_static_method(property) %>
73 | <% hostIdCheck = check_host_id(classname, property) %>
74 | <% methodName = validate_method_name(name) %>
75 | <% argumentHash = form_rest_api_args(classname, property, name) %>
76 | <% resourcePath = validate_path(property.path) %>
77 | <% pathParameters = generate_format_hash(classname, property, resourcePath) %>
78 | <% payLoad = get_payload(classname, property) %>
79 | <% if options[:gen_deprecated_methods] %>
80 |
81 | ///
82 | /// <%= property.description %>
83 | ///
84 | /// Access Token used for the API call.<% if argumentHash.size > 0 %><% argumentHash.each do |name, type| %>
85 | /// <%= type %><% end %><% end %>
86 | /// <% if property.response %><%= property.response %><% end %>
87 | public<%= " static" if static %><% if property.response %> <%= validate_class_name(property.response) %><% else %> void<% end %> <%= methodName %>(string accessToken<% if argumentHash.size > 0 %>, <%= argumentHash.map{|name, type| "#{type} #{name}"}.join(", ") %><% end %>)
88 | {
89 | APIContext apiContext = new APIContext(accessToken);
90 | <% if property.response %>
91 | return <%= methodName %>(apiContext<% if argumentHash.size > 0 %>, <%= argumentHash.map{|name, type| "#{name}"}.join(", ") %><% end %>);
92 | <% else %>
93 | <%= name.camelcase %>(apiContext<% if argumentHash.size > 0 %>, <%= argumentHash.map{|name, type| "#{name}"}.join(", ") %><% end %>);
94 | return;
95 | <% end %>
96 | }
97 | <% end %>
98 |
99 | ///
100 | /// <%= property.description %>
101 | ///
102 | /// APIContext used for the API call.<% if argumentHash.size > 0 %><% argumentHash.each do |name, type| %>
103 | /// <%= type %><% end %><% end %>
104 | /// <% if property.response %><%= property.response %><% end %>
105 | public<%= " static" if static %><% if property.response %> <%= validate_class_name(property.response) %><% else %> void<% end %> <%= methodName %>(APIContext apiContext<% if argumentHash.size > 0 %>, <%= argumentHash.map{|name, type| "#{type} #{name}"}.join(", ") %><% end %>)
106 | {
107 | if (apiContext == null)
108 | {
109 | throw new ArgumentNullException("APIContext cannot be null");
110 | }
111 | <% if options[:mandate_oauth] %>
112 | if (string.IsNullOrEmpty(apiContext.AccessToken))
113 | {
114 | throw new ArgumentNullException("AccessToken cannot be null or empty");
115 | }
116 | <% end %>
117 | if (apiContext.HTTPHeaders == null)
118 | {
119 | apiContext.HTTPHeaders = new Dictionary();
120 | }
121 | apiContext.HTTPHeaders.Add(BaseConstants.CONTENT_TYPE_HEADER, BaseConstants.CONTENT_TYPE_JSON);
122 | apiContext.SdkVersion = new SDKVersionImpl();
123 | <% if hostIdCheck %>
124 | if (this.id == null)
125 | {
126 | throw new ArgumentNullException("Id cannot be null");
127 | }
128 | <% end %>
129 | <% if argumentHash.size > 0 %>
130 | <% argumentHash.each do |name, type| %>
131 | <% if name != 'queryParameters' %>
132 | if (<%= name %> == null)
133 | {
134 | throw new ArgumentNullException("<%= name%> cannot be null");
135 | }
136 | <% end %>
137 | <% end %>
138 | <% end %>
139 | Dictionary pathParameters = new Dictionary();
140 | <% pathParameters.each do |name, value| %>
141 | pathParameters.Add("<%= name %>", <%= value %>);
142 | <% end %>
143 | string pattern = "<%= resourcePath %>";
144 | <% if property.type != 'POST' and property.type != 'PATCH' and property.type != 'PUT' %>
145 | string resourcePath = SDKUtil.FormatURIPath(pattern, pathParameters, queryParameters);
146 | <% else %>
147 | string resourcePath = SDKUtil.FormatURIPath(pattern, pathParameters);
148 | <% end %>
149 | string payLoad = <%= payLoad %>;
150 | <% if property.response %>
151 | return PayPalResource.ConfigureAndExecute<<%= validate_class_name(property.response) %>>(apiContext, <%= "HttpMethod." + property.type %>, resourcePath, payLoad);
152 | <% else %>
153 | PayPalResource.ConfigureAndExecute