Skip to content

Commit 1cea5e5

Browse files
committed
fix(cli): execute all tests; fix broken tests
1 parent 448701f commit 1cea5e5

File tree

8 files changed

+71
-67
lines changed

8 files changed

+71
-67
lines changed

packages/cli/examples/widgets.oas.json

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
}
107107
}
108108
},
109-
"/mutations/createWidget": {
109+
"/v1/widgets": {
110110
"post": {
111111
"operationId": "createWidget",
112112
"description": "Create a widget",
@@ -115,27 +115,14 @@
115115
"content": {
116116
"application/json": {
117117
"schema": {
118-
"type": "object",
119-
"properties": {
120-
"name": {
121-
"type": "string",
122-
"description": "The name of the widget"
123-
},
124-
"status": {
125-
"$ref": "#/components/schemas/WidgetStatus"
126-
}
127-
},
128-
"required": [
129-
"name",
130-
"status"
131-
]
118+
"$ref": "#/components/schemas/CreateWidgetInput"
132119
}
133120
}
134121
}
135122
},
136123
"responses": {
137-
"200": {
138-
"description": "OK",
124+
"201": {
125+
"description": "Widget created successfully",
139126
"content": {
140127
"application/json": {
141128
"schema": {
@@ -165,22 +152,14 @@
165152
"content": {
166153
"application/json": {
167154
"schema": {
168-
"type": "object",
169-
"properties": {
170-
"id": {
171-
"$ref": "#/components/schemas/WidgetID"
172-
}
173-
},
174-
"required": [
175-
"id"
176-
]
155+
"$ref": "#/components/schemas/DeactivateWidgetInput"
177156
}
178157
}
179158
}
180159
},
181160
"responses": {
182161
"200": {
183-
"description": "OK",
162+
"description": "Widget successfully deactivated",
184163
"content": {
185164
"application/json": {
186165
"schema": {

packages/cli/examples/widgets.oas.yaml

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ paths:
6565
$ref: "#/components/responses/InvalidCredentials"
6666
"403":
6767
$ref: "#/components/responses/Forbidden"
68-
/mutations/createWidget:
68+
/v1/widgets:
6969
post:
7070
operationId: createWidget
7171
description: Create a widget
@@ -74,19 +74,10 @@ paths:
7474
content:
7575
application/json:
7676
schema:
77-
type: object
78-
properties:
79-
name:
80-
type: string
81-
description: The name of the widget
82-
status:
83-
$ref: "#/components/schemas/WidgetStatus"
84-
required:
85-
- name
86-
- status
77+
$ref: "#/components/schemas/CreateWidgetInput"
8778
responses:
88-
"200":
89-
description: OK
79+
"201":
80+
description: Widget created successfully
9081
content:
9182
application/json:
9283
schema:
@@ -106,15 +97,10 @@ paths:
10697
content:
10798
application/json:
10899
schema:
109-
type: object
110-
properties:
111-
id:
112-
$ref: "#/components/schemas/WidgetID"
113-
required:
114-
- id
100+
$ref: "#/components/schemas/DeactivateWidgetInput"
115101
responses:
116102
"200":
117-
description: OK
103+
description: Widget successfully deactivated
118104
content:
119105
application/json:
120106
schema:

packages/cli/examples/widgets.rpc.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ operations:
3030
mutations:
3131
createWidget:
3232
description: Create a widget
33+
path: /v1/widgets
3334
input:
3435
schema: { $ref: "#/components/schemas/CreateWidgetInput" }
3536
output:
37+
description: Widget created successfully
38+
statusCode: 201
3639
schema: { $ref: "#/components/schemas/Widget" }
3740
errors:
3841
400: { $ref: "#/components/responses/BadRequest" }
@@ -43,6 +46,7 @@ operations:
4346
input:
4447
schema: { $ref: "#/components/schemas/DeactivateWidgetInput" }
4548
output:
49+
description: Widget successfully deactivated
4650
schema: { $ref: "#/components/schemas/Widget" }
4751
errors:
4852
400: { $ref: "#/components/responses/BadRequest" }

packages/cli/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"scripts": {
3434
"build": "tsup-node src/index.ts",
3535
"build:check": "tsc --noEmit",
36-
"build:examples": "npm run build && npm run build:examples:yaml && npm run build:examples:json",
36+
"build:examples": "npm run build:examples:yaml && npm run build:examples:json",
3737
"build:examples:yaml": "bin/yarpc-cli.mjs -i examples/widgets.rpc.yaml -o examples/widgets.oas.yaml -f yaml",
3838
"build:examples:json": "bin/yarpc-cli.mjs -i examples/widgets.rpc.yaml -o examples/widgets.oas.json -f json",
3939
"ci": "npm run build:check && npm run lint:check && npm run test:node && npm run format:check",
@@ -45,7 +45,8 @@
4545
"lint:check": "eslint . --cache --ext .ts",
4646
"pretest": "npm run lint && tsc --noEmit",
4747
"test": "npm run build:check && npm run test:node",
48-
"test:node": "node --loader ts-node/esm --test src/*.test.ts",
48+
"test:node": "npm run test:only -- src/**/*.test.ts",
49+
"test:only": "node --loader ts-node/esm --test",
4950
"posttest": "npm run format && npm run build:examples"
5051
},
5152
"devDependencies": {

packages/cli/src/transformers/document-transformer.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ test("DocumentTransformer#transform", async (t) => {
172172
};
173173

174174
const actual = await DocumentTransformer.transform(doc, { logger });
175-
assert.deepStrictEqual(actual, expected);
175+
176+
assert.deepStrictEqual(
177+
actual.paths?.["/health/deep"],
178+
expected.paths["/health/deep"]
179+
);
176180
});
177181
});

packages/cli/src/transformers/operation-transformer.test.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ test("OperationTransformer#transformMutationOperation", async (t) => {
6666
},
6767
];
6868
const expectedRequestBody = {
69+
required: true,
6970
content: {
7071
"application/json": {
7172
schema: {
@@ -173,17 +174,33 @@ test("OperationTransformer#transformQueryOperation", async (t) => {
173174
}
174175
);
175176

176-
const expectedResponseLength =
177-
Object.keys(listUserWidgetsOAS.responses).length + 1;
178-
assert.equal(Object.keys(actual.responses), expectedResponseLength);
179-
assert.strictEqual(actual.responses["418"], {
177+
const expectedResponseLength = Object.keys(
178+
listUserWidgetsOAS.responses
179+
).length;
180+
assert.equal(
181+
Object.keys(actual.responses).length,
182+
expectedResponseLength
183+
);
184+
assert.deepStrictEqual(actual.responses["418"], {
180185
description: "I'm a teapot",
181186
content: {
182-
418: {
183-
"application/json": operations.listUserWidgets.output,
184-
},
187+
"application/json": operations.listUserWidgets.output,
185188
},
186189
});
187190
}
188191
);
192+
193+
await t.test("does not include the path if it was specified", async () => {
194+
const actual = await transformer.transformQueryOperation(
195+
"listUserWidgets",
196+
{
197+
...operations.listUserWidgets,
198+
path: "/widgets",
199+
}
200+
);
201+
202+
console.log({ actual });
203+
// @ts-expect-error path should not be included
204+
assert.strictEqual(actual.path, undefined);
205+
});
189206
});

packages/cli/src/transformers/operation-transformer.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
RPCInputObject,
99
RPCOperationObject,
1010
RPCOutputObject,
11-
ResponseObject,
1211
ResponsesObject,
1312
isReferenceObject,
1413
} from "../types/index.js";
@@ -18,10 +17,6 @@ import {
1817
transformRPCInputs,
1918
} from "./parameter-transformer.js";
2019

21-
const DEFAULT_RESPONSE: ResponseObject = {
22-
description: "OK",
23-
};
24-
2520
type TransformerDeps = {
2621
resolver: IRefResolver;
2722
logger?: Logger;
@@ -100,7 +95,18 @@ export class OperationTransformer {
10095
{ operationId, operation, parameterDefaults },
10196
`Transforming operation "${operationId}"`
10297
);
103-
const { description, input, output, errors, ...rest } = operation;
98+
const {
99+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
100+
path: _path,
101+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
102+
method: _method,
103+
104+
description,
105+
input,
106+
output,
107+
errors,
108+
...rest
109+
} = operation;
104110

105111
let transformedInputs: TransformOutput | undefined;
106112
let responses: ResponsesObject | undefined;
@@ -127,7 +133,7 @@ export class OperationTransformer {
127133

128134
return {
129135
operationId,
130-
description,
136+
...(description ? { description } : {}),
131137
...transformedInputs,
132138
responses,
133139
...rest,
@@ -150,7 +156,12 @@ export class OperationTransformer {
150156
? await this.resolver.resolve(schemaOrRef)
151157
: schemaOrRef;
152158

153-
return transformRPCInputs(inputSchema, defaults, parameterOverrides);
159+
return transformRPCInputs(
160+
schemaOrRef,
161+
inputSchema,
162+
defaults,
163+
parameterOverrides
164+
);
154165
}
155166

156167
private transformOperationResponses(
@@ -167,7 +178,7 @@ export class OperationTransformer {
167178
"application/json": mediaType,
168179
},
169180
}
170-
: DEFAULT_RESPONSE;
181+
: { description };
171182

172183
return {
173184
[statusCode]: successResponse,

packages/cli/src/transformers/parameter-transformer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
RPCParameterLocation,
55
RPCParameterObject,
66
RPCParametersObject,
7+
ReferenceObject,
78
SchemaObject,
89
assertObjectTypeSchema,
910
} from "../types/index.js";
@@ -59,6 +60,7 @@ export type ParameterDefaults = RPCParameterObject & {
5960
* @returns
6061
*/
6162
export function transformRPCInputs(
63+
schemaOrRef: SchemaObject | ReferenceObject,
6264
inputSchema: SchemaObject,
6365
defaults: ParameterDefaults,
6466
overrides: RPCParametersObject = {}
@@ -75,7 +77,7 @@ export function transformRPCInputs(
7577
required: true,
7678
content: {
7779
"application/json": {
78-
schema: inputSchema,
80+
schema: schemaOrRef,
7981
},
8082
},
8183
},

0 commit comments

Comments
 (0)