forked from loafle/openapi-generator-original
[ruby] Improve ruby client examples (#8040)
* [ruby] Improve ruby client examples * samples * quote fixes * Keep enum value * better string type handling * fix failing tests * add space after comment * update samples * use Time Co-authored-by: William Cheng <wing328hk@gmail.com>
This commit is contained in:
@@ -18,6 +18,7 @@ To test special tags and operation ID starting with number
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::AnotherFakeApi.new
|
||||
|
||||
@@ -16,6 +16,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::DefaultApi.new
|
||||
|
||||
@@ -30,6 +30,7 @@ Health check endpoint
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::FakeApi.new
|
||||
@@ -88,13 +89,14 @@ test http signature authentication
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
# setup authorization
|
||||
Petstore.configure do |config|
|
||||
end
|
||||
|
||||
api_instance = Petstore::FakeApi.new
|
||||
pet = Petstore::Pet.new # Pet | Pet object that needs to be added to the store
|
||||
pet = Petstore::Pet.new({name: 'doggie', photo_urls: ['photo_urls_example']}) # Pet | Pet object that needs to be added to the store
|
||||
opts = {
|
||||
query_1: 'query_1_example', # String | query parameter
|
||||
header_1: 'header_1_example' # String | header parameter
|
||||
@@ -159,6 +161,7 @@ Test serialization of outer boolean types
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::FakeApi.new
|
||||
@@ -224,6 +227,7 @@ Test serialization of object with outer number type
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::FakeApi.new
|
||||
@@ -289,11 +293,12 @@ Test serialization of outer number types
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::FakeApi.new
|
||||
opts = {
|
||||
body: 3.4 # Float | Input number as post body
|
||||
body: 8.14 # Float | Input number as post body
|
||||
}
|
||||
|
||||
begin
|
||||
@@ -354,6 +359,7 @@ Test serialization of outer string types
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::FakeApi.new
|
||||
@@ -419,6 +425,7 @@ For this test, the body for this request much reference a schema named `File`.
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::FakeApi.new
|
||||
@@ -479,6 +486,7 @@ No authorization required
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::FakeApi.new
|
||||
@@ -543,6 +551,7 @@ To test \"client\" model
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::FakeApi.new
|
||||
@@ -606,6 +615,7 @@ Fake endpoint for testing various parameters 假端點 偽のエンドポイン
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
# setup authorization
|
||||
Petstore.configure do |config|
|
||||
@@ -615,17 +625,17 @@ Petstore.configure do |config|
|
||||
end
|
||||
|
||||
api_instance = Petstore::FakeApi.new
|
||||
number = 3.4 # Float | None
|
||||
double = 3.4 # Float | None
|
||||
number = 8.14 # Float | None
|
||||
double = 1.2 # Float | None
|
||||
pattern_without_delimiter = 'pattern_without_delimiter_example' # String | None
|
||||
byte = 'byte_example' # String | None
|
||||
byte = 'BYTE_ARRAY_DATA_HERE' # String | None
|
||||
opts = {
|
||||
integer: 56, # Integer | None
|
||||
int32: 56, # Integer | None
|
||||
int64: 56, # Integer | None
|
||||
int64: 789, # Integer | None
|
||||
float: 3.4, # Float | None
|
||||
string: 'string_example', # String | None
|
||||
binary: File.new('/path/to/file'), # File | None
|
||||
binary: File.new('/path/to/some/file'), # File | None
|
||||
date: Date.parse('2013-10-20'), # Date | None
|
||||
date_time: Time.parse('2013-10-20T19:20:30+01:00'), # Time | None
|
||||
password: 'password_example', # String | None
|
||||
@@ -702,18 +712,19 @@ To test enum parameters
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::FakeApi.new
|
||||
opts = {
|
||||
enum_header_string_array: ['enum_header_string_array_example'], # Array<String> | Header parameter enum test (string array)
|
||||
enum_header_string: '-efg', # String | Header parameter enum test (string)
|
||||
enum_query_string_array: ['enum_query_string_array_example'], # Array<String> | Query parameter enum test (string array)
|
||||
enum_query_string: '-efg', # String | Query parameter enum test (string)
|
||||
enum_query_integer: 56, # Integer | Query parameter enum test (double)
|
||||
enum_query_double: 3.4, # Float | Query parameter enum test (double)
|
||||
enum_form_string_array: '$', # Array<String> | Form parameter enum test (string array)
|
||||
enum_form_string: '-efg' # String | Form parameter enum test (string)
|
||||
enum_header_string_array: ['>'], # Array<String> | Header parameter enum test (string array)
|
||||
enum_header_string: '_abc', # String | Header parameter enum test (string)
|
||||
enum_query_string_array: ['>'], # Array<String> | Query parameter enum test (string array)
|
||||
enum_query_string: '_abc', # String | Query parameter enum test (string)
|
||||
enum_query_integer: 1, # Integer | Query parameter enum test (double)
|
||||
enum_query_double: 1.1, # Float | Query parameter enum test (double)
|
||||
enum_form_string_array: ['>'], # Array<String> | Form parameter enum test (string array)
|
||||
enum_form_string: '_abc' # String | Form parameter enum test (string)
|
||||
}
|
||||
|
||||
begin
|
||||
@@ -780,6 +791,7 @@ Fake endpoint to test group parameters (optional)
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
# setup authorization
|
||||
Petstore.configure do |config|
|
||||
@@ -790,11 +802,11 @@ end
|
||||
api_instance = Petstore::FakeApi.new
|
||||
required_string_group = 56 # Integer | Required String in group parameters
|
||||
required_boolean_group = true # Boolean | Required Boolean in group parameters
|
||||
required_int64_group = 56 # Integer | Required Integer in group parameters
|
||||
required_int64_group = 789 # Integer | Required Integer in group parameters
|
||||
opts = {
|
||||
string_group: 56, # Integer | String in group parameters
|
||||
boolean_group: true, # Boolean | Boolean in group parameters
|
||||
int64_group: 56 # Integer | Integer in group parameters
|
||||
int64_group: 789 # Integer | Integer in group parameters
|
||||
}
|
||||
|
||||
begin
|
||||
@@ -857,10 +869,11 @@ test inline additionalProperties
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::FakeApi.new
|
||||
request_body = {'key' => 'request_body_example'} # Hash<String, String> | request body
|
||||
request_body = { key: 'inner_example'} # Hash<String, String> | request body
|
||||
|
||||
begin
|
||||
# test inline additionalProperties
|
||||
@@ -917,6 +930,7 @@ test json serialization of form data
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::FakeApi.new
|
||||
@@ -981,14 +995,15 @@ To test the collection format in query parameters
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::FakeApi.new
|
||||
pipe = ['pipe_example'] # Array<String> |
|
||||
ioutil = ['ioutil_example'] # Array<String> |
|
||||
http = ['http_example'] # Array<String> |
|
||||
url = ['url_example'] # Array<String> |
|
||||
context = ['context_example'] # Array<String> |
|
||||
pipe = ['inner_example'] # Array<String> |
|
||||
ioutil = ['inner_example'] # Array<String> |
|
||||
http = ['inner_example'] # Array<String> |
|
||||
url = ['inner_example'] # Array<String> |
|
||||
context = ['inner_example'] # Array<String> |
|
||||
|
||||
begin
|
||||
|
||||
|
||||
@@ -18,13 +18,14 @@ To test class name in snake case
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
# setup authorization
|
||||
Petstore.configure do |config|
|
||||
# Configure API key authorization: api_key_query
|
||||
config.api_key['api_key_query'] = 'YOUR API KEY'
|
||||
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
|
||||
#config.api_key_prefix['api_key_query'] = 'Bearer'
|
||||
# config.api_key_prefix['api_key_query'] = 'Bearer'
|
||||
end
|
||||
|
||||
api_instance = Petstore::FakeClassnameTags123Api.new
|
||||
|
||||
@@ -24,6 +24,7 @@ Add a new pet to the store
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
# setup authorization
|
||||
Petstore.configure do |config|
|
||||
@@ -32,7 +33,7 @@ Petstore.configure do |config|
|
||||
end
|
||||
|
||||
api_instance = Petstore::PetApi.new
|
||||
pet = Petstore::Pet.new # Pet | Pet object that needs to be added to the store
|
||||
pet = Petstore::Pet.new({name: 'doggie', photo_urls: ['photo_urls_example']}) # Pet | Pet object that needs to be added to the store
|
||||
|
||||
begin
|
||||
# Add a new pet to the store
|
||||
@@ -89,6 +90,7 @@ Deletes a pet
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
# setup authorization
|
||||
Petstore.configure do |config|
|
||||
@@ -97,7 +99,7 @@ Petstore.configure do |config|
|
||||
end
|
||||
|
||||
api_instance = Petstore::PetApi.new
|
||||
pet_id = 56 # Integer | Pet id to delete
|
||||
pet_id = 789 # Integer | Pet id to delete
|
||||
opts = {
|
||||
api_key: 'api_key_example' # String |
|
||||
}
|
||||
@@ -160,6 +162,7 @@ Multiple status values can be provided with comma separated strings
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
# setup authorization
|
||||
Petstore.configure do |config|
|
||||
@@ -168,7 +171,7 @@ Petstore.configure do |config|
|
||||
end
|
||||
|
||||
api_instance = Petstore::PetApi.new
|
||||
status = ['status_example'] # Array<String> | Status values that need to be considered for filter
|
||||
status = ['available'] # Array<String> | Status values that need to be considered for filter
|
||||
|
||||
begin
|
||||
# Finds Pets by status
|
||||
@@ -228,6 +231,7 @@ Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
# setup authorization
|
||||
Petstore.configure do |config|
|
||||
@@ -236,7 +240,7 @@ Petstore.configure do |config|
|
||||
end
|
||||
|
||||
api_instance = Petstore::PetApi.new
|
||||
tags = ['tags_example'] # Array<String> | Tags to filter by
|
||||
tags = ['inner_example'] # Array<String> | Tags to filter by
|
||||
|
||||
begin
|
||||
# Finds Pets by tags
|
||||
@@ -296,17 +300,18 @@ Returns a single pet
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
# setup authorization
|
||||
Petstore.configure do |config|
|
||||
# Configure API key authorization: api_key
|
||||
config.api_key['api_key'] = 'YOUR API KEY'
|
||||
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
|
||||
#config.api_key_prefix['api_key'] = 'Bearer'
|
||||
# config.api_key_prefix['api_key'] = 'Bearer'
|
||||
end
|
||||
|
||||
api_instance = Petstore::PetApi.new
|
||||
pet_id = 56 # Integer | ID of pet to return
|
||||
pet_id = 789 # Integer | ID of pet to return
|
||||
|
||||
begin
|
||||
# Find pet by ID
|
||||
@@ -364,6 +369,7 @@ Update an existing pet
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
# setup authorization
|
||||
Petstore.configure do |config|
|
||||
@@ -372,7 +378,7 @@ Petstore.configure do |config|
|
||||
end
|
||||
|
||||
api_instance = Petstore::PetApi.new
|
||||
pet = Petstore::Pet.new # Pet | Pet object that needs to be added to the store
|
||||
pet = Petstore::Pet.new({name: 'doggie', photo_urls: ['photo_urls_example']}) # Pet | Pet object that needs to be added to the store
|
||||
|
||||
begin
|
||||
# Update an existing pet
|
||||
@@ -429,6 +435,7 @@ Updates a pet in the store with form data
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
# setup authorization
|
||||
Petstore.configure do |config|
|
||||
@@ -437,7 +444,7 @@ Petstore.configure do |config|
|
||||
end
|
||||
|
||||
api_instance = Petstore::PetApi.new
|
||||
pet_id = 56 # Integer | ID of pet that needs to be updated
|
||||
pet_id = 789 # Integer | ID of pet that needs to be updated
|
||||
opts = {
|
||||
name: 'name_example', # String | Updated name of the pet
|
||||
status: 'status_example' # String | Updated status of the pet
|
||||
@@ -500,6 +507,7 @@ uploads an image
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
# setup authorization
|
||||
Petstore.configure do |config|
|
||||
@@ -508,10 +516,10 @@ Petstore.configure do |config|
|
||||
end
|
||||
|
||||
api_instance = Petstore::PetApi.new
|
||||
pet_id = 56 # Integer | ID of pet to update
|
||||
pet_id = 789 # Integer | ID of pet to update
|
||||
opts = {
|
||||
additional_metadata: 'additional_metadata_example', # String | Additional data to pass to server
|
||||
file: File.new('/path/to/file') # File | file to upload
|
||||
file: File.new('/path/to/some/file') # File | file to upload
|
||||
}
|
||||
|
||||
begin
|
||||
@@ -572,6 +580,7 @@ uploads an image (required)
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
# setup authorization
|
||||
Petstore.configure do |config|
|
||||
@@ -580,8 +589,8 @@ Petstore.configure do |config|
|
||||
end
|
||||
|
||||
api_instance = Petstore::PetApi.new
|
||||
pet_id = 56 # Integer | ID of pet to update
|
||||
required_file = File.new('/path/to/file') # File | file to upload
|
||||
pet_id = 789 # Integer | ID of pet to update
|
||||
required_file = File.new('/path/to/some/file') # File | file to upload
|
||||
opts = {
|
||||
additional_metadata: 'additional_metadata_example' # String | Additional data to pass to server
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ For valid response try integer IDs with value < 1000. Anything above 1000 or non
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::StoreApi.new
|
||||
@@ -83,13 +84,14 @@ Returns a map of status codes to quantities
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
# setup authorization
|
||||
Petstore.configure do |config|
|
||||
# Configure API key authorization: api_key
|
||||
config.api_key['api_key'] = 'YOUR API KEY'
|
||||
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
|
||||
#config.api_key_prefix['api_key'] = 'Bearer'
|
||||
# config.api_key_prefix['api_key'] = 'Bearer'
|
||||
end
|
||||
|
||||
api_instance = Petstore::StoreApi.new
|
||||
@@ -150,10 +152,11 @@ For valid response try integer IDs with value <= 5 or > 10. Other values will ge
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::StoreApi.new
|
||||
order_id = 56 # Integer | ID of pet that needs to be fetched
|
||||
order_id = 789 # Integer | ID of pet that needs to be fetched
|
||||
|
||||
begin
|
||||
# Find purchase order by ID
|
||||
@@ -211,6 +214,7 @@ Place an order for a pet
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::StoreApi.new
|
||||
|
||||
@@ -25,6 +25,7 @@ This can only be done by the logged in user.
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::UserApi.new
|
||||
@@ -85,6 +86,7 @@ Creates list of users with given input array
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::UserApi.new
|
||||
@@ -145,6 +147,7 @@ Creates list of users with given input array
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::UserApi.new
|
||||
@@ -207,6 +210,7 @@ This can only be done by the logged in user.
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::UserApi.new
|
||||
@@ -267,6 +271,7 @@ Get user by user name
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::UserApi.new
|
||||
@@ -328,6 +333,7 @@ Logs user into the system
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::UserApi.new
|
||||
@@ -391,6 +397,7 @@ Logs out current logged in user session
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::UserApi.new
|
||||
@@ -450,6 +457,7 @@ This can only be done by the logged in user.
|
||||
### Examples
|
||||
|
||||
```ruby
|
||||
require 'time'
|
||||
require 'petstore'
|
||||
|
||||
api_instance = Petstore::UserApi.new
|
||||
|
||||
Reference in New Issue
Block a user