Skip to content

Commit d8847c8

Browse files
committed
Copy existing ruby codegen from swagger-codegen 2.4.4
1 parent bb2337d commit d8847c8

29 files changed

+3122
-0
lines changed

src/main/java/io/swagger/codegen/v3/generators/ruby/RubyClientCodegen.java

Lines changed: 736 additions & 0 deletions
Large diffs are not rendered by default.

src/main/resources/META-INF/services/io.swagger.codegen.v3.CodegenConfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ io.swagger.codegen.v3.generators.kotlin.KotlinClientCodegen
2222
io.swagger.codegen.v3.generators.kotlin.KotlinServerCodegen
2323
io.swagger.codegen.v3.generators.php.PhpClientCodegen
2424
io.swagger.codegen.v3.generators.python.PythonClientCodegen
25+
io.swagger.codegen.v3.generators.ruby.RubyClientCodegen
2526
io.swagger.codegen.v3.generators.scala.ScalaClientCodegen
2627
io.swagger.codegen.v3.generators.scala.AkkaHttpServerCodegen
2728
io.swagger.codegen.v3.generators.swift.Swift3Codegen
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
source 'https://rubygems.org'
2+
3+
gemspec
4+
5+
group :development, :test do
6+
gem 'rake', '~> 12.0.0'
7+
end
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# {{gemName}}
2+
3+
{{moduleName}} - the Ruby gem for the {{appName}}
4+
5+
{{#appDescription}}
6+
{{{appDescription}}}
7+
{{/appDescription}}
8+
9+
This SDK is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:
10+
11+
- API version: {{appVersion}}
12+
- Package version: {{gemVersion}}
13+
{{^hideGenerationTimestamp}}
14+
- Build date: {{generatedDate}}
15+
{{/hideGenerationTimestamp}}
16+
- Build package: {{generatorClass}}
17+
{{#infoUrl}}
18+
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
19+
{{/infoUrl}}
20+
21+
## Installation
22+
23+
### Build a gem
24+
25+
To build the Ruby code into a gem:
26+
27+
```shell
28+
gem build {{{gemName}}}.gemspec
29+
```
30+
31+
Then either install the gem locally:
32+
33+
```shell
34+
gem install ./{{{gemName}}}-{{{gemVersion}}}.gem
35+
```
36+
(for development, run `gem install --dev ./{{{gemName}}}-{{{gemVersion}}}.gem` to install the development dependencies)
37+
38+
or publish the gem to a gem hosting service, e.g. [RubyGems](https://rubygems.org/).
39+
40+
Finally add this to the Gemfile:
41+
42+
gem '{{{gemName}}}', '~> {{{gemVersion}}}'
43+
44+
### Install from Git
45+
46+
If the Ruby gem is hosted at a git repository: https://github.com/{{#gitUserId}}{{.}}{{/gitUserId}}{{^gitUserId}}YOUR_GIT_USERNAME{{/gitUserId}}/{{#gitRepoId}}{{.}}{{/gitRepoId}}{{^gitRepoId}}YOUR_GIT_REPO{{/gitRepoId}}, then add the following in the Gemfile:
47+
48+
gem '{{{gemName}}}', :git => 'https://github.com/{{#gitUserId}}{{.}}{{/gitUserId}}{{^gitUserId}}YOUR_GIT_USERNAME{{/gitUserId}}/{{#gitRepoId}}{{.}}{{/gitRepoId}}{{^gitRepoId}}YOUR_GIT_REPO{{/gitRepoId}}.git'
49+
50+
### Include the Ruby code directly
51+
52+
Include the Ruby code directly using `-I` as follows:
53+
54+
```shell
55+
ruby -Ilib script.rb
56+
```
57+
58+
## Getting Started
59+
60+
Please follow the [installation](#installation) procedure and then run the following code:
61+
```ruby
62+
# Load the gem
63+
require '{{{gemName}}}'
64+
{{#apiInfo}}{{#apis}}{{@first}}{{#operations}}{{#operation}}{{@first}}{{#hasAuthMethods}}
65+
# Setup authorization
66+
{{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}}
67+
# Configure HTTP basic authorization: {{{name}}}
68+
config.username = 'YOUR USERNAME'
69+
config.password = 'YOUR PASSWORD'{{/isBasic}}{{#isApiKey}}
70+
# Configure API key authorization: {{{name}}}
71+
config.api_key['{{{keyParamName}}}'] = 'YOUR API KEY'
72+
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
73+
#config.api_key_prefix['{{{keyParamName}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}}
74+
# Configure OAuth2 access token for authorization: {{{name}}}
75+
config.access_token = 'YOUR ACCESS TOKEN'{{/isOAuth}}
76+
{{/authMethods}}end
77+
{{/hasAuthMethods}}
78+
79+
api_instance = {{{moduleName}}}::{{{classname}}}.new{{#hasParams}}
80+
{{#vendorExtensions.x-codegen-hasRequiredParams}}{{#allParams}}{{#required}}
81+
{{{paramName}}} = {{{example}}} # {{{dataType}}} | {{{description}}}
82+
{{/required}}{{/allParams}}{{/vendorExtensions.x-codegen-hasRequiredParams}}{{#hasOptionalParams}}
83+
opts = { {{#allParams}}{{^required}}
84+
{{{paramName}}}: {{{example}}}{{#vendorExtensions.x-codegen-hasMoreOptional}},{{/vendorExtensions.x-codegen-hasMoreOptional}} # {{{dataType}}} | {{{description}}}{{/required}}{{/allParams}}
85+
}{{/hasOptionalParams}}{{/hasParams}}
86+
87+
begin
88+
{{#summary}} #{{{.}}}
89+
{{/summary}} {{#returnType}}result = {{/returnType}}api_instance.{{{operationId}}}{{#hasParams}}({{#allParams}}{{#required}}{{{paramName}}}{{#vendorExtensions.x-codegen-hasMoreRequired}}, {{/vendorExtensions.x-codegen-hasMoreRequired}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{{#vendorExtensions.x-codegen-hasRequiredParams}}, {{/vendorExtensions.x-codegen-hasRequiredParams}}opts{{/hasOptionalParams}}){{/hasParams}}{{#returnType}}
90+
p result{{/returnType}}
91+
rescue {{{moduleName}}}::ApiError => e
92+
puts "Exception when calling {{classname}}->{{{operationId}}}: #{e}"
93+
end
94+
{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
95+
```
96+
97+
## Documentation for API Endpoints
98+
99+
All URIs are relative to *{{basePath}}*
100+
101+
Class | Method | HTTP request | Description
102+
------------ | ------------- | ------------- | -------------
103+
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{moduleName}}::{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{{summary}}}{{/summary}}
104+
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
105+
106+
## Documentation for Models
107+
108+
{{#models}}{{#model}} - [{{moduleName}}::{{classname}}]({{modelDocPath}}{{classname}}.md)
109+
{{/model}}{{/models}}
110+
111+
## Documentation for Authorization
112+
113+
{{^authMethods}} All endpoints do not require authorization.
114+
{{/authMethods}}{{#authMethods}}{{#last}} Authentication schemes defined for the API:{{/last}}{{/authMethods}}
115+
{{#authMethods}}### {{name}}
116+
117+
{{#isApiKey}}- **Type**: API key
118+
- **API key parameter name**: {{keyParamName}}
119+
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
120+
{{/isApiKey}}
121+
{{#isBasic}}- **Type**: HTTP basic authentication
122+
{{/isBasic}}
123+
{{#isOAuth}}- **Type**: OAuth
124+
- **Flow**: {{flow}}
125+
- **Authorization URL**: {{authorizationUrl}}
126+
- **Scopes**: {{^scopes}}N/A{{/scopes}}
127+
{{#scopes}} - {{scope}}: {{description}}
128+
{{/scopes}}
129+
{{/isOAuth}}
130+
131+
{{/authMethods}}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
begin
2+
require 'rspec/core/rake_task'
3+
4+
RSpec::Core::RakeTask.new(:spec)
5+
task default: :spec
6+
rescue LoadError
7+
# no rspec available
8+
end
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
=begin
2+
{{> api_info}}
3+
=end
4+
5+
require 'uri'
6+
7+
module {{moduleName}}
8+
{{#operations}}
9+
class {{classname}}
10+
attr_accessor :api_client
11+
12+
def initialize(api_client = ApiClient.default)
13+
@api_client = api_client
14+
end
15+
{{#operation}}
16+
{{#summary}}
17+
# {{{summary}}}
18+
{{/summary}}
19+
{{#notes}}
20+
# {{{notes}}}
21+
{{/notes}}
22+
{{#allParams}}{{#required}} # @param {{paramName}} {{description}}
23+
{{/required}}{{/allParams}} # @param [Hash] opts the optional parameters
24+
{{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
25+
{{/required}}{{/allParams}} # @return [{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}]
26+
def {{operationId}}({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {})
27+
{{#returnType}}data, _status_code, _headers = {{/returnType}}{{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts)
28+
{{#returnType}}data{{/returnType}}{{^returnType}}nil{{/returnType}}
29+
end
30+
31+
{{#summary}}
32+
# {{summary}}
33+
{{/summary}}
34+
{{#notes}}
35+
# {{notes}}
36+
{{/notes}}
37+
{{#allParams}}{{#required}} # @param {{paramName}} {{description}}
38+
{{/required}}{{/allParams}} # @param [Hash] opts the optional parameters
39+
{{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}}
40+
{{/required}}{{/allParams}} # @return [Array<({{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}, Fixnum, Hash)>] {{#returnType}}{{{returnType}}} data{{/returnType}}{{^returnType}}nil{{/returnType}}, response status code and response headers
41+
def {{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {})
42+
if @api_client.config.debugging
43+
@api_client.config.logger.debug 'Calling API: {{classname}}.{{operationId}} ...'
44+
end
45+
{{#allParams}}
46+
{{#required}}
47+
# verify the required parameter '{{paramName}}' is set
48+
if @api_client.config.client_side_validation && {{{paramName}}}.nil?
49+
fail ArgumentError, "Missing the required parameter '{{paramName}}' when calling {{classname}}.{{operationId}}"
50+
end
51+
{{#isEnum}}
52+
{{^isContainer}}
53+
# verify enum value
54+
if @api_client.config.client_side_validation && ![{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}].include?({{{paramName}}})
55+
fail ArgumentError, "invalid value for '{{{paramName}}}', must be one of {{#allowableValues}}{{#values}}{{{this}}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}"
56+
end
57+
{{/isContainer}}
58+
{{/isEnum}}
59+
{{/required}}
60+
{{^required}}
61+
{{#isEnum}}
62+
{{#collectionFormat}}
63+
if @api_client.config.client_side_validation && opts[:'{{{paramName}}}'] && !opts[:'{{{paramName}}}'].all? { |item| [{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}].include?(item) }
64+
fail ArgumentError, 'invalid value for "{{{paramName}}}", must include one of {{#allowableValues}}{{#values}}{{{this}}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}'
65+
end
66+
{{/collectionFormat}}
67+
{{^collectionFormat}}
68+
if @api_client.config.client_side_validation && opts[:'{{{paramName}}}'] && ![{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}].include?(opts[:'{{{paramName}}}'])
69+
fail ArgumentError, 'invalid value for "{{{paramName}}}", must be one of {{#allowableValues}}{{#values}}{{{this}}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}'
70+
end
71+
{{/collectionFormat}}
72+
{{/isEnum}}
73+
{{/required}}
74+
{{#hasValidation}}
75+
{{#maxLength}}
76+
if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}.to_s.length > {{{maxLength}}}
77+
fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, the character length must be smaller than or equal to {{{maxLength}}}.'
78+
end
79+
80+
{{/maxLength}}
81+
{{#minLength}}
82+
if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}.to_s.length < {{{minLength}}}
83+
fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, the character length must be great than or equal to {{{minLength}}}.'
84+
end
85+
86+
{{/minLength}}
87+
{{#maximum}}
88+
if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{{maximum}}}
89+
fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{{maximum}}}.'
90+
end
91+
92+
{{/maximum}}
93+
{{#minimum}}
94+
if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{{minimum}}}
95+
fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, must be greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{{minimum}}}.'
96+
end
97+
98+
{{/minimum}}
99+
{{#pattern}}
100+
if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}} !~ Regexp.new({{{pattern}}})
101+
fail ArgumentError, "invalid value for '{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:\"{{{paramName}}}\"]{{/required}}' when calling {{classname}}.{{operationId}}, must conform to the pattern {{{pattern}}}."
102+
end
103+
104+
{{/pattern}}
105+
{{#maxItems}}
106+
if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}.length > {{{maxItems}}}
107+
fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, number of items must be less than or equal to {{{maxItems}}}.'
108+
end
109+
110+
{{/maxItems}}
111+
{{#minItems}}
112+
if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}.length < {{{minItems}}}
113+
fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, number of items must be greater than or equal to {{{minItems}}}.'
114+
end
115+
116+
{{/minItems}}
117+
{{/hasValidation}}
118+
{{/allParams}}
119+
# resource path
120+
local_var_path = '{{{path}}}'{{#pathParams}}.sub('{' + '{{baseName}}' + '}', {{paramName}}.to_s){{/pathParams}}
121+
122+
# query parameters
123+
query_params = {}
124+
{{#queryParams}}
125+
{{#required}}
126+
query_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}}
127+
{{/required}}
128+
{{/queryParams}}
129+
{{#queryParams}}
130+
{{^required}}
131+
query_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param(opts[:'{{{paramName}}}'], :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}opts[:'{{{paramName}}}']{{/collectionFormat}} if !opts[:'{{{paramName}}}'].nil?
132+
{{/required}}
133+
{{/queryParams}}
134+
135+
# header parameters
136+
header_params = {}
137+
{{#hasProduces}}
138+
# HTTP header 'Accept' (if needed)
139+
header_params['Accept'] = @api_client.select_header_accept([{{#produces}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}}])
140+
{{/hasProduces}}
141+
{{#hasConsumes}}
142+
# HTTP header 'Content-Type'
143+
header_params['Content-Type'] = @api_client.select_header_content_type([{{#consumes}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}])
144+
{{/hasConsumes}}
145+
{{#headerParams}}
146+
{{#required}}
147+
header_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}}
148+
{{/required}}
149+
{{/headerParams}}
150+
{{#headerParams}}
151+
{{^required}}
152+
header_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param(opts[:'{{{paramName}}}'], :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}opts[:'{{{paramName}}}']{{/collectionFormat}} if !opts[:'{{{paramName}}}'].nil?
153+
{{/required}}
154+
{{/headerParams}}
155+
156+
# form parameters
157+
form_params = {}
158+
{{#formParams}}
159+
{{#required}}
160+
form_params['{{baseName}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}}
161+
{{/required}}
162+
{{/formParams}}
163+
{{#formParams}}
164+
{{^required}}
165+
form_params['{{baseName}}'] = {{#collectionFormat}}@api_client.build_collection_param(opts[:'{{{paramName}}}'], :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}opts[:'{{{paramName}}}']{{/collectionFormat}} if !opts[:'{{paramName}}'].nil?
166+
{{/required}}
167+
{{/formParams}}
168+
169+
# http body (model)
170+
{{^bodyParam}}
171+
post_body = nil
172+
{{/bodyParam}}
173+
{{#bodyParam}}
174+
post_body = @api_client.object_to_http_body({{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}})
175+
{{/bodyParam}}
176+
auth_names = [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}]
177+
data, status_code, headers = @api_client.call_api(:{{httpMethod}}, local_var_path,
178+
:header_params => header_params,
179+
:query_params => query_params,
180+
:form_params => form_params,
181+
:body => post_body,
182+
:auth_names => auth_names{{#returnType}},
183+
:return_type => '{{{returnType}}}'{{/returnType}})
184+
if @api_client.config.debugging
185+
@api_client.config.logger.debug "API called: {{classname}}#{{operationId}}\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
186+
end
187+
return data, status_code, headers
188+
end
189+
{{/operation}}
190+
end
191+
{{/operations}}
192+
end

0 commit comments

Comments
 (0)