Getting started
This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key special-key
to test the authorization filters.
How to Build
This client library is a Ruby gem which can be compiled and used in your Ruby and Ruby on Rails project. This library requires a few gems from the RubyGems repository.
- Open the command line interface or the terminal and navigate to the folder containing the source code.
- Run
gem build test_asdasdasd.gemspec
to build the gem. - Once built, the gem can be installed on the current work environment using
gem install test_asdasdasd-2.gem
How to Use
The following section explains how to use the SwaggerPetstore Ruby Gem in a new Rails project using RubyMine™. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.
1. Starting a new project
Close any existing projects in RubyMine™ by selecting File -> Close Project
. Next, click on Create New Project
to create a new project from scratch.
Next, provide TestApp
as the project name, choose Rails Application
as the project type, and click OK
.
In the next dialog make sure that correct Ruby SDK is being used (minimum 2.0.0) and click OK
.
This will create a new Rails Application project with an existing set of files and folder.
2. Add reference of the gem
In order to use the SwaggerPetstore gem in the new project we must add a gem reference. Locate the Gemfile
in the Project Explorer window under the TestApp
project node. The file contains references to all gems being used in the project. Here, add the reference to the library gem by adding the following line: gem 'test_asdasdasd', '~> 2'
3. Adding a new Rails Controller
Once the TestApp
project is created, a folder named controllers
will be visible in the Project Explorer under the following path: TestApp > app > controllers
. Right click on this folder and select New -> Run Rails Generator...
.
Selecting the said option will popup a small window where the generator names are displayed. Here, select the controller
template.
Next, a popup window will ask you for a Controller name and included Actions. For controller name provide Hello
and include an action named Index
and click OK
.
A new controller class anmed HelloController
will be created in a file named hello_controller.rb
containing a method named Index
. In this method, add code for initialization and a sample for its usage.
How to Test
You can test the generated SDK and the server with automatically generated test cases as follows:
- From terminal/cmd navigate to the root directory of the SDK.
- Invoke:
bundle exec rake
Initialization
Authentication
In order to setup authentication and initialization of the API client, you need the following information.
Parameter | Description |
---|---|
o_auth_client_id | OAuth 2 Client ID |
o_auth_redirect_uri | OAuth 2 Redirection endpoint or Callback Uri |
API client can be initialized as following.
# Configuration parameters and credentials
o_auth_client_id = 'o_auth_client_id' # OAuth 2 Client ID
o_auth_redirect_uri = 'o_auth_redirect_uri' # OAuth 2 Redirection endpoint or Callback Uri
client = TestAsdasdasd::TestAsdasdasdClient.new(
o_auth_client_id: o_auth_client_id,
o_auth_redirect_uri: o_auth_redirect_uri
)
The added initlization code can be debugged by putting a breakpoint in the Index
method and running the project in debug mode by selecting Run -> Debug 'Development: TestApp'
.
Class Reference
List of Controllers
PetController
Get singleton instance
The singleton instance of the PetController
class can be accessed from the API Client.
pet_controller = client.pet
add_pet
Add a new pet to the store
def add_pet(body); end
Parameters
Parameter | Tags | Description |
---|---|---|
body | Required |
Pet object that needs to be added to the store |
Example Usage
body = Pet.new
pet_controller.add_pet(body)
Errors
Error Code | Error Description |
---|---|
405 | Invalid input |
update_pet
Update an existing pet
def update_pet(body); end
Parameters
Parameter | Tags | Description |
---|---|---|
body | Required |
Pet object that needs to be added to the store |
Example Usage
body = Pet.new
pet_controller.update_pet(body)
Errors
Error Code | Error Description |
---|---|
400 | Invalid ID supplied |
404 | Pet not found |
405 | Validation exception |
find_pets_by_status
Multiple status values can be provided with comma separated strings
def find_pets_by_status(status); end
Parameters
Parameter | Tags | Description |
---|---|---|
status | Required Collection |
Status values that need to be considered for filter |
Example Usage
status = [TestAsdasdasd::Status2Enum::AVAILABLE]
result = pet_controller.find_pets_by_status(status)
Errors
Error Code | Error Description |
---|---|
400 | Invalid status value |
find_pets_by_tags
Muliple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
def (); end
Parameters
Parameter | Tags | Description |
---|---|---|
tags | Required Collection |
Tags to filter by |
Example Usage
= ['tags']
result = pet_controller.()
Errors
Error Code | Error Description |
---|---|
400 | Invalid tag value |
get_pet_by_id
Returns a single pet
def get_pet_by_id(pet_id); end
Parameters
Parameter | Tags | Description |
---|---|---|
pet_id | Required |
ID of pet to return |
Example Usage
pet_id = 181
result = pet_controller.get_pet_by_id(pet_id)
Errors
Error Code | Error Description |
---|---|
400 | Invalid ID supplied |
404 | Pet not found |
update_pet_with_form
Updates a pet in the store with form data
def update_pet_with_form(pet_id,
name = nil,
status = nil); end
Parameters
Parameter | Tags | Description |
---|---|---|
pet_id | Required |
ID of pet that needs to be updated |
name | Optional |
Updated name of the pet |
status | Optional |
Updated status of the pet |
Example Usage
pet_id = 181
name = 'name'
status = 'status'
pet_controller.update_pet_with_form(pet_id, name, status)
Errors
Error Code | Error Description |
---|---|
405 | Invalid input |
delete_pet
Deletes a pet
def delete_pet(pet_id,
api_key = nil); end
Parameters
Parameter | Tags | Description |
---|---|---|
pet_id | Required |
Pet id to delete |
api_key | Optional |
TODO: Add a parameter description |
Example Usage
pet_id = 181
api_key = 'api_key'
pet_controller.delete_pet(pet_id, api_key)
Errors
Error Code | Error Description |
---|---|
400 | Invalid ID supplied |
404 | Pet not found |
upload_file
uploads an image
def upload_file(pet_id,
= nil,
file = nil); end
Parameters
Parameter | Tags | Description |
---|---|---|
pet_id | Required |
ID of pet to update |
additional_metadata | Optional |
Additional data to pass to server |
file | Optional |
file to upload |
Example Usage
pet_id = 181
= 'additionalMetadata'
file = Faraday::UploadIO.new('PathToFile', 'application/octet-stream')
result = pet_controller.upload_file(pet_id, , file)
StoreController
Get singleton instance
The singleton instance of the StoreController
class can be accessed from the API Client.
store_controller = client.store
get_inventory
Returns a map of status codes to quantities
def get_inventory; end
Example Usage
result = store_controller.get_inventory()
create_place_order
Place an order for a pet
def create_place_order(body); end
Parameters
Parameter | Tags | Description |
---|---|---|
body | Required |
order placed for purchasing the pet |
Example Usage
body = Order.new
result = store_controller.create_place_order(body)
Errors
Error Code | Error Description |
---|---|
400 | Invalid Order |
get_order_by_id
For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions
def get_order_by_id(order_id); end
Parameters
Parameter | Tags | Description |
---|---|---|
order_id | Required |
ID of pet that needs to be fetched |
Example Usage
order_id = 181
result = store_controller.get_order_by_id(order_id)
Errors
Error Code | Error Description |
---|---|
400 | Invalid ID supplied |
404 | Order not found |
delete_order
For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors
def delete_order(order_id); end
Parameters
Parameter | Tags | Description |
---|---|---|
order_id | Required |
ID of the order that needs to be deleted |
Example Usage
order_id = 181
store_controller.delete_order(order_id)
Errors
Error Code | Error Description |
---|---|
400 | Invalid ID supplied |
404 | Order not found |
UserController
Get singleton instance
The singleton instance of the UserController
class can be accessed from the API Client.
user_controller = client.user
create_user
This can only be done by the logged in user.
def create_user(body); end
Parameters
Parameter | Tags | Description |
---|---|---|
body | Required |
Created user object |
Example Usage
body = User.new
user_controller.create_user(body)
Errors
Error Code | Error Description |
---|---|
0 | successful operation |
create_users_with_array_input
Creates list of users with given input array
def create_users_with_array_input(body); end
Parameters
Parameter | Tags | Description |
---|---|---|
body | Required Collection |
List of user object |
Example Usage
body = [User.new]
user_controller.create_users_with_array_input(body)
Errors
Error Code | Error Description |
---|---|
0 | successful operation |
create_users_with_list_input
Creates list of users with given input array
def create_users_with_list_input(body); end
Parameters
Parameter | Tags | Description |
---|---|---|
body | Required Collection |
List of user object |
Example Usage
body = [User.new]
user_controller.create_users_with_list_input(body)
Errors
Error Code | Error Description |
---|---|
0 | successful operation |
get_login_user
Logs user into the system
def get_login_user(username,
password); end
Parameters
Parameter | Tags | Description |
---|---|---|
username | Required |
The user name for login |
password | Required |
The password for login in clear text |
Example Usage
username = 'username'
password = 'password'
result = user_controller.get_login_user(username, password)
Errors
Error Code | Error Description |
---|---|
400 | Invalid username/password supplied |
get_logout_user
Logs out current logged in user session
def get_logout_user; end
Example Usage
user_controller.get_logout_user()
Errors
Error Code | Error Description |
---|---|
0 | successful operation |
get_user_by_name
Get user by user name
def get_user_by_name(username); end
Parameters
Parameter | Tags | Description |
---|---|---|
username | Required |
The name that needs to be fetched. Use user1 for testing. |
Example Usage
username = 'username'
result = user_controller.get_user_by_name(username)
Errors
Error Code | Error Description |
---|---|
400 | Invalid username supplied |
404 | User not found |
update_user
This can only be done by the logged in user.
def update_user(username,
body); end
Parameters
Parameter | Tags | Description |
---|---|---|
username | Required |
name that need to be updated |
body | Required |
Updated user object |
Example Usage
username = 'username'
body = User.new
user_controller.update_user(username, body)
Errors
Error Code | Error Description |
---|---|
400 | Invalid user supplied |
404 | User not found |
delete_user
This can only be done by the logged in user.
def delete_user(username); end
Parameters
Parameter | Tags | Description |
---|---|---|
username | Required |
The name that needs to be deleted |
Example Usage
username = 'username'
user_controller.delete_user(username)
Errors
Error Code | Error Description |
---|---|
400 | Invalid username supplied |
404 | User not found |