Skip to content

Commit 7d610b2

Browse files
authored
Merge pull request #6 from kikuomax/simple-constructor
Replace factory method with constructor
2 parents a33cf57 + f7173a2 commit 7d610b2

30 files changed

+162
-457
lines changed

README.ja.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
このレポジトリを依存関係(`dependencies`)に追加してください。
2222

2323
```sh
24-
npm install https://github.com/codemonger-io/cdk-rest-api-with-spec.git#v0.1.1
24+
npm install https://github.com/codemonger-io/cdk-rest-api-with-spec.git#v0.2.0
2525
```
2626

2727
このライブラリはCDK v2プロジェクトで使用することを想定しており、以下のモジュールは`dependencies`ではなく`peerDependencies`に含んでいます。
@@ -32,11 +32,10 @@ CDK v2プロジェクトで使っている限り、これらを別途インス
3232

3333
## 始める
3434

35-
[`aws_apigateway.RestApi`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.RestApi.html)のコンストラクタの代わりに[`RestApiWithSpec.createRestApi`](./api-docs/markdown/cdk-rest-api-with-spec.restapiwithspec.createrestapi.md)を使ってください。
36-
この関数は[`aws_apigateway.RestApi`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.RestApi.html)をOpenAPI定義を記述する機能で拡張したオブジェクトを返します。
35+
[`aws_apigateway.RestApi`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.RestApi.html)の代わりに[`RestApiWithSpec`](./api-docs/markdown/cdk-rest-api-with-spec.restapiwithspec.md)をインスタンス化してください。
3736

3837
```ts
39-
const api = RestApiWithSpec.createRestApi(this, 'example-api', {
38+
const api = new RestApiWithSpec(this, 'example-api', {
4039
description: 'Example of RestApiWithSpec',
4140
openApiInfo: {
4241
version: '0.0.1',

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ This library is implemented for the CDK **version 2** (CDK v2) and does not work
2121
Please add this repository to your dependencies.
2222

2323
```sh
24-
npm install https://github.com/codemonger-io/cdk-rest-api-with-spec.git#v0.1.1
24+
npm install https://github.com/codemonger-io/cdk-rest-api-with-spec.git#v0.2.0
2525
```
2626

2727
This library is supposed to be used in a CDK v2 project, so it does not include the following modules in the `dependencies` but does in the `peerDependencies`.
@@ -32,11 +32,10 @@ As long as you are working on a CDK v2 project, you should not have to separatel
3232

3333
## Getting started
3434

35-
Please use [`RestApiWithSpec.createRestApi`](./api-docs/markdown/cdk-rest-api-with-spec.restapiwithspec.createrestapi.md) instead of the constructor of [`aws_apigateway.RestApi`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.RestApi.html).
36-
This function will return an object which augments [`aws_apigateway.RestApi`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.RestApi.html) with the features to describe the OpenAPI definition.
35+
Please instantiate [`RestApiWithSpec`](./api-docs/markdown/cdk-rest-api-with-spec.restapiwithspec.md) instead of [`aws_apigateway.RestApi`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.RestApi.html).
3736

3837
```ts
39-
const api = RestApiWithSpec.createRestApi(this, 'example-api', {
38+
const api = new RestApiWithSpec(this, 'example-api', {
4039
description: 'Example of RestApiWithSpec',
4140
openApiInfo: {
4241
version: '0.0.1',

api-docs/cdk-rest-api-with-spec.api.md

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,18 @@ export interface IAuthorizerWithSpec extends aws_apigateway.IAuthorizer {
1818
securitySchemeObject?: SecuritySchemeObject;
1919
}
2020

21-
// @beta
22-
export interface IBaseResourceWithSpec extends aws_apigateway.IResource {
23-
addMethod(httpMethod: string, target?: aws_apigateway.Integration, options?: MethodOptionsWithSpec): aws_apigateway.Method;
24-
addResource(pathPart: string, options?: ResourceOptionsWithSpec): IResourceWithSpec;
25-
defaultMethodOptions?: MethodOptionsWithSpec;
26-
parentResource?: IBaseResourceWithSpec;
27-
}
28-
2921
// @beta
3022
export interface IResourceWithSpec extends aws_apigateway.Resource {
3123
addMethod(httpMethod: string, target?: aws_apigateway.Integration, options?: MethodOptionsWithSpec): aws_apigateway.Method;
3224
addResource(pathPart: string, options?: ResourceOptionsWithSpec): IResourceWithSpec;
3325
defaultMethodOptions?: MethodOptionsWithSpec;
34-
parentResource?: IBaseResourceWithSpec;
26+
parentResource?: IResourceWithSpec;
3527
}
3628

3729
// @beta
38-
export interface IRestApiWithSpec extends aws_apigateway.RestApi {
30+
export interface IRestApiWithSpec extends aws_apigateway.IRestApi {
3931
addModel(id: string, props: ModelOptionsWithSpec): aws_apigateway.Model;
40-
root: IBaseResourceWithSpec;
41-
underlying: aws_apigateway.RestApi;
32+
readonly root: IResourceWithSpec;
4233
}
4334

4435
// @beta
@@ -109,18 +100,16 @@ export interface ResourceOptionsWithSpec extends aws_apigateway.ResourceOptions
109100
}
110101

111102
// @beta
112-
export type RestApiFactory = (scope: Construct, id: string, props?: aws_apigateway.RestApiProps) => aws_apigateway.RestApi;
113-
114-
// @beta
115-
export class RestApiWithSpec {
116-
static createRestApi(scope: Construct, id: string, props: RestApiWithSpecProps): IRestApiWithSpec;
103+
export class RestApiWithSpec extends aws_apigateway.RestApi implements IRestApiWithSpec {
104+
constructor(scope: Construct, id: string, props: RestApiWithSpecProps);
105+
addModel(id: string, props: ModelOptionsWithSpec): aws_apigateway.Model;
117106
// (undocumented)
118107
readonly props: RestApiWithSpecProps;
108+
readonly root: IResourceWithSpec;
119109
}
120110

121111
// @beta
122112
export interface RestApiWithSpecProps extends aws_apigateway.RestApiProps {
123-
newRestApi?: RestApiFactory;
124113
openApiInfo: Partial<InfoObject> & Pick<InfoObject, 'version'>;
125114
openApiOutputPath: string;
126115
}

api-docs/markdown/cdk-rest-api-with-spec.ibaseresourcewithspec.addmethod.md

Lines changed: 0 additions & 29 deletions
This file was deleted.

api-docs/markdown/cdk-rest-api-with-spec.ibaseresourcewithspec.addresource.md

Lines changed: 0 additions & 28 deletions
This file was deleted.

api-docs/markdown/cdk-rest-api-with-spec.ibaseresourcewithspec.defaultmethodoptions.md

Lines changed: 0 additions & 16 deletions
This file was deleted.

api-docs/markdown/cdk-rest-api-with-spec.ibaseresourcewithspec.md

Lines changed: 0 additions & 38 deletions
This file was deleted.

api-docs/markdown/cdk-rest-api-with-spec.ibaseresourcewithspec.parentresource.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

api-docs/markdown/cdk-rest-api-with-spec.iresourcewithspec.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
88
>
99
10-
[aws\_apigateway.Resource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.Resource.html) augmented with the features to build the OpenAPI definition.
10+
[aws\_apigateway.IResource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.IResource.html) augmented with the features to build the OpenAPI definition.
1111

1212
<b>Signature:</b>
1313

@@ -16,12 +16,16 @@ export interface IResourceWithSpec extends apigateway.Resource
1616
```
1717
<b>Extends:</b> apigateway.Resource
1818
19+
## Remarks
20+
21+
Although this interface actually inherits [aws\_apigateway.Resource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.Resource.html)<!-- -->, you should rely on only properties defined in [aws\_apigateway.IResource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.IResource.html)<!-- -->.
22+
1923
## Properties
2024
2125
| Property | Modifiers | Type | Description |
2226
| --- | --- | --- | --- |
2327
| [defaultMethodOptions?](./cdk-rest-api-with-spec.iresourcewithspec.defaultmethodoptions.md) | | [MethodOptionsWithSpec](./cdk-rest-api-with-spec.methodoptionswithspec.md) | <b><i>(BETA)</i></b> <i>(Optional)</i> Default method options with the OpenAPI definition. |
24-
| [parentResource?](./cdk-rest-api-with-spec.iresourcewithspec.parentresource.md) | | [IBaseResourceWithSpec](./cdk-rest-api-with-spec.ibaseresourcewithspec.md) | <b><i>(BETA)</i></b> <i>(Optional)</i> Parent resource. |
28+
| [parentResource?](./cdk-rest-api-with-spec.iresourcewithspec.parentresource.md) | | [IResourceWithSpec](./cdk-rest-api-with-spec.iresourcewithspec.md) | <b><i>(BETA)</i></b> <i>(Optional)</i> Parent resource. |
2529
2630
## Methods
2731

api-docs/markdown/cdk-rest-api-with-spec.iresourcewithspec.parentresource.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Parent resource.
1212
<b>Signature:</b>
1313

1414
```typescript
15-
parentResource?: IBaseResourceWithSpec;
15+
parentResource?: IResourceWithSpec;
1616
```
1717

1818
## Remarks

0 commit comments

Comments
 (0)