1 stable release
1.0.0 | May 14, 2021 |
---|
#50 in #sample
Used in hvcg-commons-lambda-clien…
305KB
5.5K
SLoC
Rust API for hvcg_example_openapi_entity
This is a sample server Petstore server. For this sample, you can use the api key special-key
to test the authorization filters.
Overview
This client/server was generated by the [openapi-generator] (https://openapi-generator.tech) project. By using the OpenAPI-Spec from a remote server, you can easily generate a server stub.
To see how to make this your own, look here:
- API version: 1.0.0
- Build date: 2021-05-14T20:40:15.040864+07:00[Asia/Bangkok]
This autogenerated project defines an API crate hvcg_example_openapi_entity
which contains:
- An
Api
trait defining the API in Rust. - Data types representing the underlying data model.
- A
Client
type which implementsApi
and issues HTTP requests for each operation. - A router which accepts HTTP requests and invokes the appropriate
Api
method for each operation.
It also contains an example server and client which make use of hvcg_example_openapi_entity
:
- The example server starts up a web server using the
hvcg_example_openapi_entity
router, and supplies a trivial implementation ofApi
which returns failure for every operation. - The example client provides a CLI which lets you invoke
any single operation on the
hvcg_example_openapi_entity
client by passing appropriate arguments on the command line.
You can use the example server and client as a basis for your own code. See below for more detail on implementing a server.
Examples
Run examples with:
cargo run --example <example-name>
To pass in arguments to the examples, put them after --
, for example:
cargo run --example client -- --help
Running the example server
To run the server, follow these simple steps:
cargo run --example server
Running the example client
To run a client, follow one of the following simple steps:
cargo run --example client DeletePet
cargo run --example client FindPetsByStatus
cargo run --example client FindPetsByTags
cargo run --example client GetPetById
cargo run --example client UpdatePetWithForm
cargo run --example client UploadFile
cargo run --example client DeleteOrder
cargo run --example client GetInventory
cargo run --example client GetOrderById
cargo run --example client CreateUsersWithArrayInput
cargo run --example client CreateUsersWithListInput
cargo run --example client DeleteUser
cargo run --example client GetUserByName
cargo run --example client LoginUser
cargo run --example client LogoutUser
HTTPS
The examples can be run in HTTPS mode by passing in the flag --https
, for example:
cargo run --example server -- --https
This will use the keys/certificates from the examples directory. Note that the
server chain is signed with CN=localhost
.
Using the generated library
The generated library has a few optional features that can be activated through Cargo.
server
- This defaults to enabled and creates the basic skeleton of a server implementation based on hyper
- To create the server stack you'll need to provide an implementation of the API trait to provide the server function.
client
- This defaults to enabled and creates the basic skeleton of a client implementation based on hyper
- The constructed client implements the API trait by making remote API call.
conversions
- This defaults to disabled and creates extra derives on models to allow "transmogrification" between objects of structurally similar types.
See https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section for how to use features in your Cargo.toml
.
Documentation for API Endpoints
All URIs are relative to http://petstore.swagger.io/v2
Method | HTTP request | Description |
---|---|---|
addPet | POST /pet | Add a new pet to the store |
deletePet | DELETE /pet/{petId} | Deletes a pet |
findPetsByStatus | GET /pet/findByStatus | Finds Pets by status |
findPetsByTags | GET /pet/findByTags | Finds Pets by tags |
getPetById | GET /pet/{petId} | Find pet by ID |
updatePet | PUT /pet | Update an existing pet |
updatePetWithForm | POST /pet/{petId} | Updates a pet in the store with form data |
uploadFile | POST /pet/{petId}/uploadImage | uploads an image |
deleteOrder | DELETE /store/order/{orderId} | Delete purchase order by ID |
getInventory | GET /store/inventory | Returns pet inventories by status |
getOrderById | GET /store/order/{orderId} | Find purchase order by ID |
placeOrder | POST /store/order | Place an order for a pet |
createUser | POST /user | Create user |
createUsersWithArrayInput | POST /user/createWithArray | Creates list of users with given input array |
createUsersWithListInput | POST /user/createWithList | Creates list of users with given input array |
deleteUser | DELETE /user/{username} | Delete user |
getUserByName | GET /user/{username} | Get user by user name |
loginUser | GET /user/login | Logs user into the system |
logoutUser | GET /user/logout | Logs out current logged in user session |
updateUser | PUT /user/{username} | Updated user |
Documentation For Models
Documentation For Authorization
api_key
- Type: API key
Example
petstore_auth
- Type: OAuth
- Flow: implicit
- Authorization URL: http://petstore.swagger.io/api/oauth/dialog
- Scopes:
- write:pets: modify pets in your account
- read:pets: read your pets
Example
Or via OAuth2 module to automatically refresh tokens and perform user authentication.
Author
Dependencies
~12–24MB
~354K SLoC