Getting Started with Swagger Petstore - OpenAPI 3.0
Introduction
This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about Swagger at https://swagger.io. In the third iteration of the pet store, we've switched to the design first approach! You can now help us improve the API whether it's by making changes to the definition itself or to the code. That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
If you're looking for the Swagger 2.0/OAS 2.0 version of Petstore, then click here. Alternatively, you can load via the Edit > Load Petstore OAS 2.0 menu option!
Some useful links:
Find out more about Swagger: http://swagger.io
Install the Package
Run the following command from your project directory to install the package from npm:
npm install petstore-test-sdk@1.0.2
For additional package details, see the Npm page for the petstore-test-sdk@1.0.2 npm.
Test the SDK
To validate the functionality of this SDK, you can execute all tests located in the test directory. This SDK utilizes Jest as both the testing framework and test runner.
To run the tests, navigate to the root directory of the SDK and execute the following command:
npm run test
Or you can also run tests with coverage report:
npm run test:coverage
Initialize the API Client
Note: Documentation for the client can be found here.
The following parameters are configurable for the API Client:
| Parameter | Type | Description |
|---|---|---|
| timeout | number |
Timeout for API calls. Default: 0 |
| httpClientOptions | Partial<HttpClientOptions> |
Stable configurable http client options. |
| unstableHttpClientOptions | any |
Unstable configurable http client options. |
| customHeaderAuthenticationCredentials | CustomHeaderAuthenticationCredentials |
The credential object for customHeaderAuthentication |
The API client can be initialized as follows:
Code-Based Client Initialization
import { Client } from 'petstore-test-sdk';
const client = new Client({
customHeaderAuthenticationCredentials: {
'api_key': 'api_key'
},
timeout: 0,
});
Configuration-Based Client Initialization
import * as path from 'path';
import * as fs from 'fs';
import { Client } from 'petstore-test-sdk';
// Provide absolute path for the configuration file
const absolutePath = path.resolve('./config.json');
// Read the configuration file content
const fileContent = fs.readFileSync(absolutePath, 'utf-8');
// Initialize client from JSON configuration content
const client = Client.fromJsonConfig(fileContent);
See the Configuration-Based Client Initialization section for details.
Environment-Based Client Initialization
import * as dotenv from 'dotenv';
import * as path from 'path';
import * as fs from 'fs';
import { Client } from 'petstore-test-sdk';
// Optional - Provide absolute path for the .env file
const absolutePath = path.resolve('./.env');
if (fs.existsSync(absolutePath)) {
// Load environment variables from .env file
dotenv.config({ path: absolutePath, override: true });
}
// Initialize client using environment variables
const client = Client.fromEnvironment(process.env);
See the Environment-Based Client Initialization section for details.
Authorization
This API uses the following authentication schemes.
List of APIs
SDK Infrastructure
Configuration
- HttpClientOptions
- RetryConfiguration
- ProxySettings
- Configuration-Based Client Initialization
- Environment-Based Client Initialization