Skip to content

Commit 53aa7e9

Browse files
committed
feat: remove IBaseResourceWithSpec
- Replaces `IBaseResourceWithSpec` with `IResourceWithSpec` because the properties of `Resource` and `IResource` are the same. issue #5
1 parent e8515dd commit 53aa7e9

File tree

2 files changed

+13
-46
lines changed

2 files changed

+13
-46
lines changed

src/models.ts

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { JsonSchemaEx } from './json-schema-ex';
1313
*/
1414
export interface IRestApiWithSpec extends apigateway.IRestApi {
1515
/** Root resource ('/') with the features to build the OpenAPI definition. */
16-
root: IBaseResourceWithSpec;
16+
readonly root: IResourceWithSpec;
1717

1818
/** Adds a new model. */
1919
addModel(id: string, props: ModelOptionsWithSpec): apigateway.Model;
@@ -25,46 +25,10 @@ export interface IRestApiWithSpec extends apigateway.IRestApi {
2525
*
2626
* @remarks
2727
*
28-
* This interface duplicates {@link IResourceWithSpec} but is necessary because
29-
* {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.RestApi.html#root | aws_apigateway.RestApi.root}
30-
* might not satisfy
31-
* {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.Resource.html | aws_apigateway.Resource}.
32-
*
33-
* It might not be obvious but this interface is a super-interface of
34-
* {@link IResourceWithSpec}.
35-
*
36-
* @beta
37-
*/
38-
export interface IBaseResourceWithSpec extends apigateway.IResource {
39-
/** Default method options with the OpenAPI definition. */
40-
defaultMethodOptions?: MethodOptionsWithSpec;
41-
42-
/**
43-
* Parent resource.
44-
*
45-
* @remarks
46-
*
47-
* `undefined` if this resource represents the root.
48-
*/
49-
parentResource?: IBaseResourceWithSpec;
50-
51-
/** Adds a new child resource with the OpenAPI definition. */
52-
addResource(
53-
pathPart: string,
54-
options?: ResourceOptionsWithSpec,
55-
): IResourceWithSpec;
56-
57-
/** Adds a method with the OpenAPI definition. */
58-
addMethod(
59-
httpMethod: string,
60-
target?: apigateway.Integration,
61-
options?: MethodOptionsWithSpec,
62-
): apigateway.Method;
63-
}
64-
65-
/**
66-
* {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.Resource.html | aws_apigateway.Resource}
67-
* augmented with the features to build the OpenAPI definition.
28+
* Although this interface actually inherits
29+
* {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.Resource.html | aws_apigateway.Resource},
30+
* you should rely on only properties defined in
31+
* {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.IResource.html | aws_apigateway.IResource}.
6832
*
6933
* @beta
7034
*/
@@ -79,7 +43,7 @@ export interface IResourceWithSpec extends apigateway.Resource {
7943
*
8044
* `undefined` if this resource is the root.
8145
*/
82-
parentResource?: IBaseResourceWithSpec;
46+
parentResource?: IResourceWithSpec;
8347

8448
/** Adds a new child resource with the OpenAPI definition. */
8549
addResource(
@@ -196,6 +160,10 @@ export interface MethodOptionsWithSpec extends apigateway.MethodOptions {
196160
* {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.MethodOptions.html#requestparameters | requestParameters}
197161
* and `requestParameterSchemas` are specified, `requestParameterSchemas`
198162
* precedes.
163+
*
164+
* Please refer to
165+
* {@link https://github.com/metadevpro/openapi3-ts | OpenApi3-TS}
166+
* for more details about `BaseParameterObject`.
199167
*/
200168
requestParameterSchemas?: { [key: string]: BaseParameterObject };
201169
/**

src/rest-api-with-spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212

1313
import { translateJsonSchemaEx } from './json-schema-ex';
1414
import {
15-
IBaseResourceWithSpec,
1615
IResourceWithSpec,
1716
IRestApiWithSpec,
1817
MethodOptionsWithSpec,
@@ -184,7 +183,7 @@ class ResourceWithSpec {
184183
private builder: OpenApiBuilder,
185184
private restApi: IRestApiWithSpec,
186185
private resource: apigateway.IResource,
187-
private parent?: IBaseResourceWithSpec,
186+
private parent?: IResourceWithSpec,
188187
) {}
189188

190189
/**
@@ -213,7 +212,7 @@ class ResourceWithSpec {
213212
builder: OpenApiBuilder,
214213
restApi: IRestApiWithSpec,
215214
resource: apigateway.IResource,
216-
parent?: IBaseResourceWithSpec,
215+
parent?: IResourceWithSpec,
217216
): IResourceWithSpec {
218217
const wrapper = new ResourceWithSpec(builder, restApi, resource, parent);
219218
wrapper.facade = new Proxy(resource, {
@@ -335,7 +334,7 @@ class ResourceWithSpec {
335334
* @private
336335
*/
337336
function translatePathPart(
338-
resource: IBaseResourceWithSpec,
337+
resource: IResourceWithSpec,
339338
): ParameterObject[] | undefined {
340339
// locates /{name} at the end
341340
const match = resource.path.match(/\/\{(.+)\}$/);

0 commit comments

Comments
 (0)