Skip to content

Commit dc18a87

Browse files
authoredMay 14, 2024··
fix: allow to override only root mock (#1338)
* fix: allow to override only root mock * update MSW docs * update all samples * fixup! update all samples * fix imposible type in polymorphic.yaml * regenerate samples * reformat project * regenerate samples
1 parent 770295f commit dc18a87

File tree

95 files changed

+33464
-21742
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+33464
-21742
lines changed
 

‎docs/src/pages/guides/msw.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ A function that returns a mock object will be generated as shown below:
3636
```typescript
3737
import { faker } from '@faker-js/faker';
3838

39-
export const getShowPetByIdMock = (overrideResponse?: any) => ({
39+
export const getShowPetByIdMock = (overrideResponse?: Partial<Type>): Type => ({
4040
id: faker.number.int({ min: undefined, max: undefined }),
4141
name: faker.word.sample(),
4242
tag: faker.helpers.arrayElement([faker.word.sample(), undefined]),

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const getMockObject = ({
2323
context,
2424
imports,
2525
existingReferencedProperties,
26+
allowOverride = false,
2627
}: {
2728
item: MockSchemaObject;
2829
operationId: string;
@@ -37,6 +38,8 @@ export const getMockObject = ({
3738
// This is used to prevent recursion when combining schemas
3839
// When an element is added to the array, it means on this iteration, we've already seen this property
3940
existingReferencedProperties: string[];
41+
// This is used to add the overrideResponse to the object
42+
allowOverride?: boolean;
4043
}): MockDefinition => {
4144
if (isReference(item)) {
4245
return resolveMockValue({
@@ -127,7 +130,9 @@ export const getMockObject = ({
127130
})
128131
.filter(Boolean);
129132

130-
properyScalars.push(`...${overrideVarName}`);
133+
if (allowOverride) {
134+
properyScalars.push(`...${overrideVarName}`);
135+
}
131136

132137
value += properyScalars.join(', ');
133138
value +=

0 commit comments

Comments
 (0)
Please sign in to comment.