(api-gateway): Support SpecRestApi for UsagePlan
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the feature
Currently, when you use a `UsagePlan` L2 construct, you must specify a `Method` L2 construct to assign to the throttling-per-method configuration. Unfortunately, if you use a `SpecRestApi` with a Swagger/OpenAPI definition, there is no L2 Method construct to link to. It would be very helpful if you could initialize a skeleton `Method` instance for this purpose, or even better, have better processing of the Swagger template so that you could add the usage plan on a method after initialization.
### Use Case
Working with Swagger/OpenAPI and needing to initialize a `UsagePlan` for the API.
### Proposed Solution
Something like:
```ts
const api = new SpecRestApi(this, 'API', {
apiDefinition: ApiDefinition.fromInline('...'),
});
const usagePlan = this.api.addUsagePlan('UsagePlan', {...});
usagePlan.addApiStage({
api,
throttle: [Method.fromSwagger('my-method')],
});
```
or
```ts
const api = new SpecRestApi(this, 'API', {
apiDefinition: ApiDefinition.fromInline('...'),
});
// Precondition: we know this API returns special "Swagger" UsagePlan instance
const usagePlan = this.api.addUsagePlan('UsagePlan', {...});
usagePlan.addRule({
api,
method: 'my-method', // this then searches and validates the existing config
});
```
### Other Information
_No response_
### Acknowledgements
- [X] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
### CDK version used
2.42.0
### Environment details (OS name and version, etc.)
macOS 12.6
Contributor guide
Research direction
Start by tracing the SpecRestApi, UsagePlan, and ApiStage APIs involved in linking throttling rules to methods, then inspect how Swagger/OpenAPI definitions are represented. Decide whether the supported behavior should provide a method reference or validate a method name from the definition; done means a SpecRestApi can configure per-method usage-plan throttling with validation and coverage for the chosen API.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, openapi, typescript
- Domain
- api, cloud
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100