Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/speakeasy-sdks/test

A typescript SDK for accessing the test API.
https://github.com/speakeasy-sdks/test

Last synced: 2 days ago
JSON representation

A typescript SDK for accessing the test API.

Awesome Lists containing this project

README

        

# Test

## SDK Installation

### NPM

```bash
npm add https://github.com/speakeasy-sdks/test
```

### Yarn

```bash
yarn add https://github.com/speakeasy-sdks/test
```

## SDK Example Usage

### Example

```typescript
import { Test } from "Test";
import { PetStatus } from "Test/dist/sdk/models/shared";

async function run() {
const sdk = new Test({
security: {
petstoreAuth: "",
},
});

const res = await sdk.pet.addPetForm({
category: {
id: 1,
name: "Dogs",
},
id: 10,
name: "doggie",
photoUrls: [""],
tags: [{}],
});

if (res.statusCode == 200) {
// handle response
}
}

run();

```

## Available Resources and Operations

### [pet](docs/sdks/pet/README.md)

* [addPetForm](docs/sdks/pet/README.md#addpetform) - Add a new pet to the store
* [addPetJson](docs/sdks/pet/README.md#addpetjson) - Add a new pet to the store
* [addPetRaw](docs/sdks/pet/README.md#addpetraw) - Add a new pet to the store
* [deletePet](docs/sdks/pet/README.md#deletepet) - Deletes a pet
* [findPetsByStatus](docs/sdks/pet/README.md#findpetsbystatus) - Finds Pets by status
* [findPetsByTags](docs/sdks/pet/README.md#findpetsbytags) - Finds Pets by tags
* [getPetById](docs/sdks/pet/README.md#getpetbyid) - Find pet by ID
* [updatePetWithForm](docs/sdks/pet/README.md#updatepetwithform) - Updates a pet in the store with form data
* [updatePetForm](docs/sdks/pet/README.md#updatepetform) - Update an existing pet
* [updatePetJson](docs/sdks/pet/README.md#updatepetjson) - Update an existing pet
* [updatePetRaw](docs/sdks/pet/README.md#updatepetraw) - Update an existing pet
* [uploadFile](docs/sdks/pet/README.md#uploadfile) - uploads an image

### [store](docs/sdks/store/README.md)

* [deleteOrder](docs/sdks/store/README.md#deleteorder) - Delete purchase order by ID
* [getInventory](docs/sdks/store/README.md#getinventory) - Returns pet inventories by status
* [getOrderById](docs/sdks/store/README.md#getorderbyid) - Find purchase order by ID
* [placeOrderForm](docs/sdks/store/README.md#placeorderform) - Place an order for a pet
* [placeOrderJson](docs/sdks/store/README.md#placeorderjson) - Place an order for a pet
* [placeOrderRaw](docs/sdks/store/README.md#placeorderraw) - Place an order for a pet

### [user](docs/sdks/user/README.md)

* [createUserForm](docs/sdks/user/README.md#createuserform) - Create user
* [createUserJson](docs/sdks/user/README.md#createuserjson) - Create user
* [createUserRaw](docs/sdks/user/README.md#createuserraw) - Create user
* [createUsersWithListInput](docs/sdks/user/README.md#createuserswithlistinput) - Creates list of users with given input array
* [deleteUser](docs/sdks/user/README.md#deleteuser) - Delete user
* [getUserByName](docs/sdks/user/README.md#getuserbyname) - Get user by user name
* [loginUser](docs/sdks/user/README.md#loginuser) - Logs user into the system
* [logoutUser](docs/sdks/user/README.md#logoutuser) - Logs out current logged in user session
* [updateUserForm](docs/sdks/user/README.md#updateuserform) - Update user
* [updateUserJson](docs/sdks/user/README.md#updateuserjson) - Update user
* [updateUserRaw](docs/sdks/user/README.md#updateuserraw) - Update user

## Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an error. If Error objects are specified in your OpenAPI Spec, the SDK will throw the appropriate Error type.

| Error Object | Status Code | Content Type |
| --------------- | --------------- | --------------- |
| errors.SDKError | 4xx-5xx | */* |

Example

```typescript
import { Test } from "Test";
import { PetStatus } from "Test/dist/sdk/models/shared";

async function run() {
const sdk = new Test({
security: {
petstoreAuth: "",
},
});

let res;
try {
res = await sdk.pet.addPetForm({
category: {
id: 1,
name: "Dogs",
},
id: 10,
name: "doggie",
photoUrls: [""],
tags: [{}],
});
} catch (err) {
if (err instanceof errors.SDKError) {
console.error(err); // handle exception
throw err;
}
}

if (res.statusCode == 200) {
// handle response
}
}

run();

```

## Server Selection

### Select Server by Index

You can override the default server globally by passing a server index to the `serverIdx: number` optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:

| # | Server | Variables |
| - | ------ | --------- |
| 0 | `https:///api/v3` | None |

#### Example

```typescript
import { Test } from "Test";
import { PetStatus } from "Test/dist/sdk/models/shared";

async function run() {
const sdk = new Test({
serverIdx: 0,
security: {
petstoreAuth: "",
},
});

const res = await sdk.pet.addPetForm({
category: {
id: 1,
name: "Dogs",
},
id: 10,
name: "doggie",
photoUrls: [""],
tags: [{}],
});

if (res.statusCode == 200) {
// handle response
}
}

run();

```

### Override Server URL Per-Client

The default server can also be overridden globally by passing a URL to the `serverURL: str` optional parameter when initializing the SDK client instance. For example:
```typescript
import { Test } from "Test";
import { PetStatus } from "Test/dist/sdk/models/shared";

async function run() {
const sdk = new Test({
serverURL: "https:///api/v3",
security: {
petstoreAuth: "",
},
});

const res = await sdk.pet.addPetForm({
category: {
id: 1,
name: "Dogs",
},
id: 10,
name: "doggie",
photoUrls: [""],
tags: [{}],
});

if (res.statusCode == 200) {
// handle response
}
}

run();

```

## Custom HTTP Client

The Typescript SDK makes API calls using the [axios](https://axios-http.com/docs/intro) HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with a custom `AxiosInstance` object.

For example, you could specify a header for every request that your sdk makes as follows:

```typescript
import { Test } from "Test";
import axios from "axios";

const httpClient = axios.create({
headers: {'x-custom-header': 'someValue'}
})

const sdk = new Test({defaultClient: httpClient});
```

## Authentication

### Per-Client Security Schemes

This SDK supports the following security scheme globally:

| Name | Type | Scheme |
| -------------- | -------------- | -------------- |
| `petstoreAuth` | oauth2 | OAuth2 token |

You can set the security parameters through the `security` optional parameter when initializing the SDK client instance. For example:
```typescript
import { Test } from "Test";
import { PetStatus } from "Test/dist/sdk/models/shared";

async function run() {
const sdk = new Test({
security: {
petstoreAuth: "",
},
});

const res = await sdk.pet.addPetForm({
category: {
id: 1,
name: "Dogs",
},
id: 10,
name: "doggie",
photoUrls: [""],
tags: [{}],
});

if (res.statusCode == 200) {
// handle response
}
}

run();

```

### Per-Operation Security Schemes

Some operations in this SDK require the security scheme to be specified at the request level. For example:
```typescript
import { Test } from "Test";
import { GetPetByIdSecurity } from "Test/dist/sdk/models/operations";

async function run() {
const sdk = new Test();
const operationSecurity: GetPetByIdSecurity = {
apiKey: "",
};

const res = await sdk.pet.getPetById(
{
petId: 504151,
},
operationSecurity
);

if (res.statusCode == 200) {
// handle response
}
}

run();

```

### Maturity

This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage
to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally
looking for the latest version.

### Contributions

While we value open-source contributions to this SDK, this library is generated programmatically.
Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release!

### SDK Created by [Speakeasy](https://docs.speakeasyapi.dev/docs/using-speakeasy/client-sdks)