mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-06-29 20:20:53 +00:00
update ruby samples
This commit is contained in:
parent
4be11452ce
commit
7c8333e2f8
@ -8,7 +8,7 @@ This SDK is automatically generated by the [Swagger Codegen](https://github.com/
|
||||
|
||||
- API version: 1.0.0
|
||||
- Package version: 1.0.0
|
||||
- Build date: 2016-07-04T22:10:18.328+08:00
|
||||
- Build date: 2016-07-14T16:12:28.313+08:00
|
||||
- Build package: class io.swagger.codegen.languages.RubyClientCodegen
|
||||
|
||||
## Installation
|
||||
@ -57,30 +57,15 @@ require 'petstore'
|
||||
|
||||
api_instance = Petstore::FakeApi.new
|
||||
|
||||
number = 3.4 # Float | None
|
||||
body = Petstore::Client.new # Client | client model
|
||||
|
||||
double = 1.2 # Float | None
|
||||
|
||||
string = "string_example" # String | None
|
||||
|
||||
byte = "B" # String | None
|
||||
|
||||
opts = {
|
||||
integer: 56, # Integer | None
|
||||
int32: 56, # Integer | None
|
||||
int64: 789, # Integer | None
|
||||
float: 3.4, # Float | None
|
||||
binary: "B", # String | None
|
||||
date: Date.parse("2013-10-20"), # Date | None
|
||||
date_time: DateTime.parse("2013-10-20T19:20:30+01:00"), # DateTime | None
|
||||
password: "password_example" # String | None
|
||||
}
|
||||
|
||||
begin
|
||||
#Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
||||
api_instance.test_endpoint_parameters(number, double, string, byte, opts)
|
||||
#To test \"client\" model
|
||||
result = api_instance.test_client_model(body)
|
||||
p result
|
||||
rescue Petstore::ApiError => e
|
||||
puts "Exception when calling FakeApi->test_endpoint_parameters: #{e}"
|
||||
puts "Exception when calling FakeApi->test_client_model: #{e}"
|
||||
end
|
||||
|
||||
```
|
||||
@ -91,6 +76,7 @@ All URIs are relative to *http://petstore.swagger.io/v2*
|
||||
|
||||
Class | Method | HTTP request | Description
|
||||
------------ | ------------- | ------------- | -------------
|
||||
*Petstore::FakeApi* | [**test_client_model**](docs/FakeApi.md#test_client_model) | **PATCH** /fake | To test \"client\" model
|
||||
*Petstore::FakeApi* | [**test_endpoint_parameters**](docs/FakeApi.md#test_endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
||||
*Petstore::FakeApi* | [**test_enum_query_parameters**](docs/FakeApi.md#test_enum_query_parameters) | **GET** /fake | To test enum query parameters
|
||||
*Petstore::PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **POST** /pet | Add a new pet to the store
|
||||
@ -126,6 +112,7 @@ Class | Method | HTTP request | Description
|
||||
- [Petstore::ArrayTest](docs/ArrayTest.md)
|
||||
- [Petstore::Cat](docs/Cat.md)
|
||||
- [Petstore::Category](docs/Category.md)
|
||||
- [Petstore::Client](docs/Client.md)
|
||||
- [Petstore::Dog](docs/Dog.md)
|
||||
- [Petstore::EnumClass](docs/EnumClass.md)
|
||||
- [Petstore::EnumTest](docs/EnumTest.md)
|
||||
|
8
samples/client/petstore/ruby/docs/Client.md
Normal file
8
samples/client/petstore/ruby/docs/Client.md
Normal file
@ -0,0 +1,8 @@
|
||||
# Petstore::Client
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**client** | **String** | | [optional]
|
||||
|
||||
|
@ -4,10 +4,56 @@ All URIs are relative to *http://petstore.swagger.io/v2*
|
||||
|
||||
Method | HTTP request | Description
|
||||
------------- | ------------- | -------------
|
||||
[**test_client_model**](FakeApi.md#test_client_model) | **PATCH** /fake | To test \"client\" model
|
||||
[**test_endpoint_parameters**](FakeApi.md#test_endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
||||
[**test_enum_query_parameters**](FakeApi.md#test_enum_query_parameters) | **GET** /fake | To test enum query parameters
|
||||
|
||||
|
||||
# **test_client_model**
|
||||
> Client test_client_model(body)
|
||||
|
||||
To test \"client\" model
|
||||
|
||||
### Example
|
||||
```ruby
|
||||
# load the gem
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::FakeApi.new
|
||||
|
||||
body = Petstore::Client.new # Client | client model
|
||||
|
||||
|
||||
begin
|
||||
#To test \"client\" model
|
||||
result = api_instance.test_client_model(body)
|
||||
p result
|
||||
rescue Petstore::ApiError => e
|
||||
puts "Exception when calling FakeApi->test_client_model: #{e}"
|
||||
end
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**body** | [**Client**](Client.md)| client model |
|
||||
|
||||
### Return type
|
||||
|
||||
[**Client**](Client.md)
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: application/json
|
||||
- **Accept**: application/json
|
||||
|
||||
|
||||
|
||||
# **test_endpoint_parameters**
|
||||
> test_endpoint_parameters(number, double, string, byte, opts)
|
||||
|
||||
|
@ -37,6 +37,7 @@ require 'petstore/models/array_of_number_only'
|
||||
require 'petstore/models/array_test'
|
||||
require 'petstore/models/cat'
|
||||
require 'petstore/models/category'
|
||||
require 'petstore/models/client'
|
||||
require 'petstore/models/dog'
|
||||
require 'petstore/models/enum_class'
|
||||
require 'petstore/models/enum_test'
|
||||
|
@ -31,6 +31,63 @@ module Petstore
|
||||
@api_client = api_client
|
||||
end
|
||||
|
||||
# To test \"client\" model
|
||||
#
|
||||
# @param body client model
|
||||
# @param [Hash] opts the optional parameters
|
||||
# @return [Client]
|
||||
def test_client_model(body, opts = {})
|
||||
data, _status_code, _headers = test_client_model_with_http_info(body, opts)
|
||||
return data
|
||||
end
|
||||
|
||||
# To test \"client\" model
|
||||
#
|
||||
# @param body client model
|
||||
# @param [Hash] opts the optional parameters
|
||||
# @return [Array<(Client, Fixnum, Hash)>] Client data, response status code and response headers
|
||||
def test_client_model_with_http_info(body, opts = {})
|
||||
if @api_client.config.debugging
|
||||
@api_client.config.logger.debug "Calling API: FakeApi.test_client_model ..."
|
||||
end
|
||||
# verify the required parameter 'body' is set
|
||||
fail ArgumentError, "Missing the required parameter 'body' when calling FakeApi.test_client_model" if body.nil?
|
||||
# resource path
|
||||
local_var_path = "/fake".sub('{format}','json')
|
||||
|
||||
# query parameters
|
||||
query_params = {}
|
||||
|
||||
# header parameters
|
||||
header_params = {}
|
||||
|
||||
# HTTP header 'Accept' (if needed)
|
||||
local_header_accept = ['application/json']
|
||||
local_header_accept_result = @api_client.select_header_accept(local_header_accept) and header_params['Accept'] = local_header_accept_result
|
||||
|
||||
# HTTP header 'Content-Type'
|
||||
local_header_content_type = ['application/json']
|
||||
header_params['Content-Type'] = @api_client.select_header_content_type(local_header_content_type)
|
||||
|
||||
# form parameters
|
||||
form_params = {}
|
||||
|
||||
# http body (model)
|
||||
post_body = @api_client.object_to_http_body(body)
|
||||
auth_names = []
|
||||
data, status_code, headers = @api_client.call_api(:PATCH, local_var_path,
|
||||
:header_params => header_params,
|
||||
:query_params => query_params,
|
||||
:form_params => form_params,
|
||||
:body => post_body,
|
||||
:auth_names => auth_names,
|
||||
:return_type => 'Client')
|
||||
if @api_client.config.debugging
|
||||
@api_client.config.logger.debug "API called: FakeApi#test_client_model\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
||||
end
|
||||
return data, status_code, headers
|
||||
end
|
||||
|
||||
# Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
||||
# Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
||||
# @param number None
|
||||
|
199
samples/client/petstore/ruby/lib/petstore/models/client.rb
Normal file
199
samples/client/petstore/ruby/lib/petstore/models/client.rb
Normal file
@ -0,0 +1,199 @@
|
||||
=begin
|
||||
#Swagger Petstore
|
||||
|
||||
#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
|
||||
OpenAPI spec version: 1.0.0
|
||||
Contact: apiteam@swagger.io
|
||||
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
=end
|
||||
|
||||
require 'date'
|
||||
|
||||
module Petstore
|
||||
|
||||
class Client
|
||||
attr_accessor :client
|
||||
|
||||
|
||||
# Attribute mapping from ruby-style variable name to JSON key.
|
||||
def self.attribute_map
|
||||
{
|
||||
:'client' => :'client'
|
||||
}
|
||||
end
|
||||
|
||||
# Attribute type mapping.
|
||||
def self.swagger_types
|
||||
{
|
||||
:'client' => :'String'
|
||||
}
|
||||
end
|
||||
|
||||
# Initializes the object
|
||||
# @param [Hash] attributes Model attributes in the form of hash
|
||||
def initialize(attributes = {})
|
||||
return unless attributes.is_a?(Hash)
|
||||
|
||||
# convert string to symbol for hash key
|
||||
attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
|
||||
|
||||
if attributes.has_key?(:'client')
|
||||
self.client = attributes[:'client']
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Show invalid properties with the reasons. Usually used together with valid?
|
||||
# @return Array for valid properies with the reasons
|
||||
def list_invalid_properties
|
||||
invalid_properties = Array.new
|
||||
return invalid_properties
|
||||
end
|
||||
|
||||
# Check to see if the all the properties in the model are valid
|
||||
# @return true if the model is valid
|
||||
def valid?
|
||||
return true
|
||||
end
|
||||
|
||||
# Checks equality by comparing each attribute.
|
||||
# @param [Object] Object to be compared
|
||||
def ==(o)
|
||||
return true if self.equal?(o)
|
||||
self.class == o.class &&
|
||||
client == o.client
|
||||
end
|
||||
|
||||
# @see the `==` method
|
||||
# @param [Object] Object to be compared
|
||||
def eql?(o)
|
||||
self == o
|
||||
end
|
||||
|
||||
# Calculates hash code according to all attributes.
|
||||
# @return [Fixnum] Hash code
|
||||
def hash
|
||||
[client].hash
|
||||
end
|
||||
|
||||
# Builds the object from hash
|
||||
# @param [Hash] attributes Model attributes in the form of hash
|
||||
# @return [Object] Returns the model itself
|
||||
def build_from_hash(attributes)
|
||||
return nil unless attributes.is_a?(Hash)
|
||||
self.class.swagger_types.each_pair do |key, type|
|
||||
if type =~ /^Array<(.*)>/i
|
||||
# check to ensure the input is an array given that the the attribute
|
||||
# is documented as an array but the input is not
|
||||
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
||||
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
||||
end
|
||||
elsif !attributes[self.class.attribute_map[key]].nil?
|
||||
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
||||
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
||||
end
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
# Deserializes the data based on type
|
||||
# @param string type Data type
|
||||
# @param string value Value to be deserialized
|
||||
# @return [Object] Deserialized data
|
||||
def _deserialize(type, value)
|
||||
case type.to_sym
|
||||
when :DateTime
|
||||
DateTime.parse(value)
|
||||
when :Date
|
||||
Date.parse(value)
|
||||
when :String
|
||||
value.to_s
|
||||
when :Integer
|
||||
value.to_i
|
||||
when :Float
|
||||
value.to_f
|
||||
when :BOOLEAN
|
||||
if value.to_s =~ /^(true|t|yes|y|1)$/i
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
when :Object
|
||||
# generic object (usually a Hash), return directly
|
||||
value
|
||||
when /\AArray<(?<inner_type>.+)>\z/
|
||||
inner_type = Regexp.last_match[:inner_type]
|
||||
value.map { |v| _deserialize(inner_type, v) }
|
||||
when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
|
||||
k_type = Regexp.last_match[:k_type]
|
||||
v_type = Regexp.last_match[:v_type]
|
||||
{}.tap do |hash|
|
||||
value.each do |k, v|
|
||||
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
||||
end
|
||||
end
|
||||
else # model
|
||||
temp_model = Petstore.const_get(type).new
|
||||
temp_model.build_from_hash(value)
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the string representation of the object
|
||||
# @return [String] String presentation of the object
|
||||
def to_s
|
||||
to_hash.to_s
|
||||
end
|
||||
|
||||
# to_body is an alias to to_hash (backward compatibility)
|
||||
# @return [Hash] Returns the object in the form of hash
|
||||
def to_body
|
||||
to_hash
|
||||
end
|
||||
|
||||
# Returns the object in the form of hash
|
||||
# @return [Hash] Returns the object in the form of hash
|
||||
def to_hash
|
||||
hash = {}
|
||||
self.class.attribute_map.each_pair do |attr, param|
|
||||
value = self.send(attr)
|
||||
next if value.nil?
|
||||
hash[param] = _to_hash(value)
|
||||
end
|
||||
hash
|
||||
end
|
||||
|
||||
# Outputs non-array value in the form of hash
|
||||
# For object, use to_hash. Otherwise, just return the value
|
||||
# @param [Object] value Any valid value
|
||||
# @return [Hash] Returns the value in the form of hash
|
||||
def _to_hash(value)
|
||||
if value.is_a?(Array)
|
||||
value.compact.map{ |v| _to_hash(v) }
|
||||
elsif value.is_a?(Hash)
|
||||
{}.tap do |hash|
|
||||
value.each { |k, v| hash[k] = _to_hash(v) }
|
||||
end
|
||||
elsif value.respond_to? :to_hash
|
||||
value.to_hash
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
@ -100,21 +100,9 @@ module Petstore
|
||||
# Check to see if the all the properties in the model are valid
|
||||
# @return true if the model is valid
|
||||
def valid?
|
||||
map_of_enum_string_validator = EnumAttributeValidator.new('Hash<String, String>', [])
|
||||
return false unless map_of_enum_string_validator.valid?(@map_of_enum_string)
|
||||
return true
|
||||
end
|
||||
|
||||
# Custom attribute writer method checking allowed values (enum).
|
||||
# @param [Object] map_of_enum_string Object to be assigned
|
||||
def map_of_enum_string=(map_of_enum_string)
|
||||
validator = EnumAttributeValidator.new('Hash<String, String>', [])
|
||||
unless validator.valid?(map_of_enum_string)
|
||||
fail ArgumentError, "invalid value for 'map_of_enum_string', must be one of #{validator.allowable_values}."
|
||||
end
|
||||
@map_of_enum_string = map_of_enum_string
|
||||
end
|
||||
|
||||
# Checks equality by comparing each attribute.
|
||||
# @param [Object] Object to be compared
|
||||
def ==(o)
|
||||
|
53
samples/client/petstore/ruby/spec/models/client_spec.rb
Normal file
53
samples/client/petstore/ruby/spec/models/client_spec.rb
Normal file
@ -0,0 +1,53 @@
|
||||
=begin
|
||||
#Swagger Petstore
|
||||
|
||||
#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
|
||||
OpenAPI spec version: 1.0.0
|
||||
Contact: apiteam@swagger.io
|
||||
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
=end
|
||||
|
||||
require 'spec_helper'
|
||||
require 'json'
|
||||
require 'date'
|
||||
|
||||
# Unit tests for Petstore::Client
|
||||
# Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
|
||||
# Please update as you see appropriate
|
||||
describe 'Client' do
|
||||
before do
|
||||
# run before each test
|
||||
@instance = Petstore::Client.new
|
||||
end
|
||||
|
||||
after do
|
||||
# run after each test
|
||||
end
|
||||
|
||||
describe 'test an instance of Client' do
|
||||
it 'should create an instact of Client' do
|
||||
expect(@instance).to be_instance_of(Petstore::Client)
|
||||
end
|
||||
end
|
||||
describe 'test attribute "client"' do
|
||||
it 'should work' do
|
||||
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user