|
| 1 | +## @openapitools/typescript-axios-with-aws-iam@1.0.0 |
| 2 | + |
| 3 | +This generator creates TypeScript/JavaScript client that utilizes [axios](https://github.com/axios/axios). The generated Node module can be used in the following environments: |
| 4 | + |
| 5 | +Environment |
| 6 | +* Node.js |
| 7 | +* Webpack |
| 8 | +* Browserify |
| 9 | + |
| 10 | +Language level |
| 11 | +* ES5 - you must have a Promises/A+ library installed |
| 12 | +* ES6 |
| 13 | + |
| 14 | +Module system |
| 15 | +* CommonJS |
| 16 | +* ES6 module system |
| 17 | + |
| 18 | +It can be used in both TypeScript and JavaScript. In TypeScript, the definition will be automatically resolved via `package.json`. ([Reference](https://www.typescriptlang.org/docs/handbook/declaration-files/consumption.html)) |
| 19 | + |
| 20 | +### Building |
| 21 | + |
| 22 | +To build and compile the typescript sources to javascript use: |
| 23 | +``` |
| 24 | +npm install |
| 25 | +npm run build |
| 26 | +``` |
| 27 | + |
| 28 | +### Publishing |
| 29 | + |
| 30 | +First build the package then run `npm publish` |
| 31 | + |
| 32 | +### Consuming |
| 33 | + |
| 34 | +navigate to the folder of your consuming project and run one of the following commands. |
| 35 | + |
| 36 | +_published:_ |
| 37 | + |
| 38 | +``` |
| 39 | +npm install @openapitools/typescript-axios-with-aws-iam@1.0.0 --save |
| 40 | +``` |
| 41 | + |
| 42 | +_unPublished (not recommended):_ |
| 43 | + |
| 44 | +``` |
| 45 | +npm install PATH_TO_GENERATED_PACKAGE --save |
| 46 | +``` |
| 47 | + |
| 48 | +### Documentation for API Endpoints |
| 49 | + |
| 50 | +All URIs are relative to *https://abc123.execute-api.us-east-1.amazonaws.com/prod* |
| 51 | + |
| 52 | +Class | Method | HTTP request | Description |
| 53 | +------------ | ------------- | ------------- | ------------- |
| 54 | +*DefaultApi* | [**createPet**](docs/DefaultApi.md#createpet) | **POST** /pet | Create a new pet |
| 55 | +*DefaultApi* | [**getInventory**](docs/DefaultApi.md#getinventory) | **GET** /store/inventory | Returns pet inventories by status |
| 56 | +*DefaultApi* | [**getPetById**](docs/DefaultApi.md#getpetbyid) | **GET** /pet | Find pet by ID |
| 57 | + |
| 58 | + |
| 59 | +### Documentation For Models |
| 60 | + |
| 61 | + - [Pet](docs/Pet.md) |
| 62 | + |
| 63 | + |
| 64 | +<a id="documentation-for-authorization"></a> |
| 65 | +## Documentation For Authorization |
| 66 | + |
| 67 | + |
| 68 | +Authentication schemes defined for the API: |
| 69 | +<a id="aws_iam"></a> |
| 70 | +### aws_iam |
| 71 | + |
| 72 | +- **Type**: API key |
| 73 | +- **API key parameter name**: Authorization |
| 74 | +- **Location**: HTTP header |
| 75 | + |
| 76 | +<a id="sigv4_auth"></a> |
| 77 | +### sigv4_auth |
| 78 | + |
| 79 | +- **Type**: API key |
| 80 | +- **API key parameter name**: Authorization |
| 81 | +- **Location**: HTTP header |
| 82 | + |
| 83 | + |
| 84 | +<a id="aws-v4-signature"></a> |
| 85 | +### AWS V4 Signature |
| 86 | + |
| 87 | +This client supports AWS Signature Version 4 for authenticating requests to AWS services. |
| 88 | + |
| 89 | +#### Configuration |
| 90 | + |
| 91 | +```typescript |
| 92 | +import { Configuration } from '@openapitools/typescript-axios-with-aws-iam'; |
| 93 | + |
| 94 | +const configuration = new Configuration({ |
| 95 | + awsv4: { |
| 96 | + credentials: { |
| 97 | + accessKeyId: 'your-access-key-id', |
| 98 | + secretAccessKey: 'your-secret-access-key', |
| 99 | + sessionToken: 'your-session-token' // Optional, for temporary credentials |
| 100 | + }, |
| 101 | + options: { |
| 102 | + region: 'us-east-1', // AWS region |
| 103 | + service: 'execute-api' // AWS service name, typically 'execute-api' for API Gateway |
| 104 | + } |
| 105 | + } |
| 106 | +}); |
| 107 | +``` |
| 108 | + |
| 109 | +#### Environment Variables |
| 110 | + |
| 111 | +You can also use environment variables for AWS credentials: |
| 112 | + |
| 113 | +```bash |
| 114 | +export AWS_ACCESS_KEY_ID=your-access-key-id |
| 115 | +export AWS_SECRET_ACCESS_KEY=your-secret-access-key |
| 116 | +export AWS_SESSION_TOKEN=your-session-token # Optional |
| 117 | +``` |
| 118 | + |
| 119 | +When environment variables are set, they will be used as fallbacks if not provided in the configuration. |
| 120 | + |
| 121 | +#### Usage Example |
| 122 | + |
| 123 | +```typescript |
| 124 | +import { DefaultApi, Configuration } from '@openapitools/typescript-axios-with-aws-iam'; |
| 125 | + |
| 126 | +const configuration = new Configuration({ |
| 127 | + basePath: 'https://your-api-gateway-id.execute-api.us-east-1.amazonaws.com/stage', |
| 128 | + awsv4: { |
| 129 | + credentials: { |
| 130 | + accessKeyId: process.env.AWS_ACCESS_KEY_ID, |
| 131 | + secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, |
| 132 | + sessionToken: process.env.AWS_SESSION_TOKEN |
| 133 | + }, |
| 134 | + options: { |
| 135 | + region: 'us-east-1', |
| 136 | + service: 'execute-api' |
| 137 | + } |
| 138 | + } |
| 139 | +}); |
| 140 | + |
| 141 | +const apiInstance = new DefaultApi(configuration); |
| 142 | + |
| 143 | +// All requests will now be signed with AWS V4 signature |
| 144 | +apiInstance.someMethod().then((response) => { |
| 145 | + console.log(response.data); |
| 146 | +}).catch((error) => { |
| 147 | + console.error(error); |
| 148 | +}); |
| 149 | +``` |
| 150 | + |
| 151 | +#### IAM Permissions |
| 152 | + |
| 153 | +Ensure your AWS credentials have the necessary IAM permissions to access the API endpoints. For API Gateway, this typically includes: |
| 154 | + |
| 155 | +```json |
| 156 | +{ |
| 157 | + "Version": "2012-10-17", |
| 158 | + "Statement": [ |
| 159 | + { |
| 160 | + "Effect": "Allow", |
| 161 | + "Action": [ |
| 162 | + "execute-api:Invoke" |
| 163 | + ], |
| 164 | + "Resource": "arn:aws:execute-api:region:account-id:api-id/*" |
| 165 | + } |
| 166 | + ] |
| 167 | +} |
| 168 | +``` |
| 169 | + |
0 commit comments