diff --git a/src/core/getters/combine.mock.ts b/src/core/getters/combine.mock.ts index a7e04a393..dd6b25d43 100644 --- a/src/core/getters/combine.mock.ts +++ b/src/core/getters/combine.mock.ts @@ -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},`; diff --git a/src/core/getters/object.mock.ts b/src/core/getters/object.mock.ts index dfbeb7126..712632ff3 100644 --- a/src/core/getters/object.mock.ts +++ b/src/core/getters/object.mock.ts @@ -52,6 +52,7 @@ export const getMockObject = async ({ tags, combine, context, + imports, }); } diff --git a/src/core/resolvers/value.mock.ts b/src/core/resolvers/value.mock.ts index a4de17e0c..95da1eaf8 100644 --- a/src/core/resolvers/value.mock.ts +++ b/src/core/resolvers/value.mock.ts @@ -59,7 +59,7 @@ export const resolveMockValue = async ({ combine?: { properties: string[] }; context: ContextSpecs; imports: GeneratorImport[]; -}): Promise => { +}): Promise => { if (isReference(schema)) { const { name, specKey } = await getRefInfo(schema.$ref, { ...context, @@ -74,7 +74,7 @@ export const resolveMockValue = async ({ specKey: specKey || schema.specKey, }; - return getMockScalar({ + const scalar = await getMockScalar({ item: newSchema, mockOptions, operationId, @@ -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, @@ -94,4 +99,9 @@ export const resolveMockValue = async ({ context, imports, }); + + return { + ...scalar, + type: schema.type, + }; };