Skip to content

Commit 4536f34

Browse files
AllieJonssonAlfred Jonsson
and
Alfred Jonsson
authoredMay 8, 2024
fix(msw): make sure to early out when detecting loop in additionalproperties (#1362)
Co-authored-by: Alfred Jonsson <alfred.jonsson@decerno.se>
1 parent b13dbb3 commit 4536f34

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed
 

‎packages/mock/src/faker/getters/object.ts

+8
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@ export const getMockObject = ({
149149
if (isBoolean(item.additionalProperties)) {
150150
return { value: `{}`, imports: [], name: item.name };
151151
}
152+
if (
153+
isReference(item.additionalProperties) &&
154+
existingReferencedProperties.includes(
155+
item.additionalProperties.$ref.split('/').pop()!,
156+
)
157+
) {
158+
return { value: `{}`, imports: [], name: item.name };
159+
}
152160

153161
const resolvedValue = resolveMockValue({
154162
schema: {

‎packages/mock/src/msw/mocks.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const getMockScalarJsTypes = (
100100
`min: ${mockOptionsWithoutFunc.arrayMin}, ` +
101101
`max: ${mockOptionsWithoutFunc.arrayMax}}` +
102102
`)}, () => faker.number.int())`
103-
: 'faker.number.int().toString()';
103+
: 'faker.number.int()';
104104
case 'string':
105105
return isArray
106106
? `Array.from({length: faker.number.int({` +

0 commit comments

Comments
 (0)
Please sign in to comment.