Skip to content

Commit 910a15d

Browse files
committed
Add sample demonstrating passed withAwsSignature variable works
1 parent cc2a444 commit 910a15d

File tree

30 files changed

+1775
-1
lines changed

30 files changed

+1775
-1
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
generatorName: typescript-axios
2+
outputDir: samples/client/petstore/typescript-axios/builds/with-aws-iam
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/typescript-axios/with-aws-iam.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/typescript-axios
5+
additionalProperties:
6+
npmVersion: 1.0.0
7+
npmName: '@openapitools/typescript-axios-with-aws-iam'
8+
npmRepository: https://skimdb.npmjs.com/registry
9+
supportsES6: true
10+
withNodeImports: true
11+
withSeparateModelsAndApi: true
12+
apiPackage: client
13+
modelPackage: models
14+
enumPropertyNaming: UPPERCASE

modules/openapi-generator/src/main/resources/typescript-axios/package.mustache

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
"prepare": "npm run build"
2727
},
2828
"dependencies": {
29-
"axios": "{{axiosVersion}}"
29+
"axios": "{{axiosVersion}}"{{#withAWSV4Signature}},
30+
"aws4": "^1.11.0",
31+
"@aws-sdk/credential-provider-node": "^3.400.0"{{/withAWSV4Signature}}
3032
},
3133
"devDependencies": {
3234
"@types/node": "12.11.5 - 12.20.42",
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
openapi: 3.0.1
2+
info:
3+
title: OpenAPI Petstore with AWS IAM
4+
version: 1.0.0
5+
description: Test API for AWS IAM authentication detection
6+
servers:
7+
- url: https://abc123.execute-api.us-east-1.amazonaws.com/prod
8+
security:
9+
- iam: []
10+
paths:
11+
/pet:
12+
get:
13+
summary: Find pet by ID
14+
operationId: getPetById
15+
security:
16+
- iam: []
17+
responses:
18+
'200':
19+
description: successful operation
20+
content:
21+
application/json:
22+
schema:
23+
$ref: '#/components/schemas/Pet'
24+
'404':
25+
description: Pet not found
26+
post:
27+
summary: Create a new pet
28+
operationId: createPet
29+
security:
30+
- iam: []
31+
requestBody:
32+
required: true
33+
content:
34+
application/json:
35+
schema:
36+
$ref: '#/components/schemas/Pet'
37+
responses:
38+
'201':
39+
description: Pet created
40+
content:
41+
application/json:
42+
schema:
43+
$ref: '#/components/schemas/Pet'
44+
'400':
45+
description: Invalid input
46+
/store/inventory:
47+
get:
48+
summary: Returns pet inventories by status
49+
operationId: getInventory
50+
security:
51+
- iam: []
52+
responses:
53+
'200':
54+
description: successful operation
55+
content:
56+
application/json:
57+
schema:
58+
type: object
59+
additionalProperties:
60+
type: integer
61+
format: int32
62+
components:
63+
securitySchemes:
64+
iam:
65+
type: apiKey
66+
name: Authorization
67+
in: header
68+
x-amazon-apigateway-authtype: awsSigv4
69+
schemas:
70+
Pet:
71+
type: object
72+
required:
73+
- name
74+
- photoUrls
75+
properties:
76+
id:
77+
type: integer
78+
format: int64
79+
name:
80+
type: string
81+
example: doggie
82+
photoUrls:
83+
type: array
84+
items:
85+
type: string
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
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

Comments
 (0)