Skip to content

Commit f47268f

Browse files
authored
Check result type before using in operator (#1724)
* Check `result` type before using `in` operator * Create serious-days-live.md
1 parent 67e3ee4 commit f47268f

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

.changeset/serious-days-live.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"openapi-typescript": patch
3+
---
4+
5+
Make sure result is an object before using the in operator.

packages/openapi-typescript/src/transform/schema-object.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ function transformSchemaObjectCore(schemaObject: SchemaObject, options: Transfor
269269
if ("type" in schemaObject && schemaObject.type) {
270270
if (typeof options.ctx.transform === "function") {
271271
const result = options.ctx.transform(schemaObject, options);
272-
if (result) {
272+
if (result && typeof result === "object") {
273273
if ("schema" in result) {
274274
if (result.questionToken) {
275275
return ts.factory.createUnionTypeNode([result.schema, UNDEFINED]);
@@ -470,7 +470,7 @@ function transformSchemaObjectCore(schemaObject: SchemaObject, options: Transfor
470470

471471
if (typeof options.ctx.transform === "function") {
472472
const result = options.ctx.transform(v as SchemaObject, options);
473-
if (result) {
473+
if (result && typeof result === "object") {
474474
if ("schema" in result) {
475475
type = result.schema;
476476
optional = result.questionToken ? QUESTION_TOKEN : optional;

0 commit comments

Comments
 (0)