Skip to content

Commit

Permalink
fix(mock): combine only one element different then object type
Browse files Browse the repository at this point in the history
  • Loading branch information
anymaniax committed May 14, 2022
1 parent 4cc91cf commit 52a7da2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/core/getters/combine.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export const combineSchemasMock = async ({
return `faker.random.arrayElement([${resolvedValue.value},`;
}
if (arr.length === 1) {
if (resolvedValue.type !== 'object') {
return `${resolvedValue.value}`;
}
return `{${resolvedValue.value}}`;
}
return `{${resolvedValue.value},`;
Expand Down
1 change: 1 addition & 0 deletions src/core/getters/object.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const getMockObject = async ({
tags,
combine,
context,
imports,
});
}

Expand Down
16 changes: 13 additions & 3 deletions src/core/resolvers/value.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const resolveMockValue = async ({
combine?: { properties: string[] };
context: ContextSpecs;
imports: GeneratorImport[];
}): Promise<MockDefinition> => {
}): Promise<MockDefinition & { type?: string }> => {
if (isReference(schema)) {
const { name, specKey } = await getRefInfo(schema.$ref, {
...context,
Expand All @@ -74,7 +74,7 @@ export const resolveMockValue = async ({
specKey: specKey || schema.specKey,
};

return getMockScalar({
const scalar = await getMockScalar({
item: newSchema,
mockOptions,
operationId,
Expand All @@ -83,9 +83,14 @@ export const resolveMockValue = async ({
context,
imports,
});

return {
...scalar,
type: newSchema.type,
};
}

return getMockScalar({
const scalar = await getMockScalar({
item: schema,
mockOptions,
operationId,
Expand All @@ -94,4 +99,9 @@ export const resolveMockValue = async ({
context,
imports,
});

return {
...scalar,
type: schema.type,
};
};

1 comment on commit 52a7da2

@vercel
Copy link

@vercel vercel bot commented on 52a7da2 May 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.