We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using the following schema:
paths: /api/sample: get: summary: sample responses: '200': description: Success content: application/json: schema: oneOf: - $ref: '#/components/schemas/TypeObj1' - $ref: '#/components/schemas/TypeObj2' components: schemas: Type: enum: - Type1 - Type2 type: string Base: type: object required: - type properties: type: allOf: - $ref: '#/components/schemas/Type' discriminator: propertyName: type mapping: Type1: '#/components/schemas/TypeObj1' Type2: '#/components/schemas/TypeObj2' TypeObj1: type: object allOf: - $ref: '#/components/schemas/Base' required: - type properties: moreProp: type: string TypeObj2: type: object allOf: - $ref: '#/components/schemas/Base' required: - type properties: prop: type: string
with mock: true in the configuration
mock: true
Generated mock is
export const getGetApiSampleResponseMock = ( overrideResponse: any = {}, ): GetApiSample200 => faker.helpers.arrayElement([ { ...overrideResponse, moreProp: faker.helpers.arrayElement([faker.word.sample(), undefined]), type: faker.helpers.arrayElement(['Type1'] as const), ...overrideResponse, }, { ...overrideResponse, prop: faker.helpers.arrayElement([faker.word.sample(), undefined]), type: faker.helpers.arrayElement(['Type2'] as const), ...overrideResponse, }, ]);
I'd like the mock to be split up so I can reference a specific type, something like this:
export const getTypeObj1Mock = (overrideResponse: any ={}): TypeObj1 => ({ moreProp: faker.helpers.arrayElement([faker.word.sample(), undefined]), type: faker.helpers.arrayElement(['Type1'] as const), ...overrideResponse, }); export const getTypeObj2Mock = (overrideResponse: any ={}): TypeObj2 => ({ prop: faker.helpers.arrayElement([faker.word.sample(), undefined]), type: faker.helpers.arrayElement(['Type2'] as const), ...overrideResponse, }); export const getGetApiSampleResponseMock = ( overrideResponse: any = {}, ): GetApiSample200 => faker.helpers.arrayElement([ getTypeObj1Mock(overrideResponse), getTypeObj2Mock(overrideResponse), ]);
This would help when testing, so I can test that when the api returns a specific type, the correct thing gets rendered.
Package Version: 6.27.1
The text was updated successfully, but these errors were encountered:
AffeJonsson
Successfully merging a pull request may close this issue.
What are the steps to reproduce this issue?
Using the following schema:
with
mock: true
in the configurationWhat happens?
Generated mock is
What were you expecting to happen?
I'd like the mock to be split up so I can reference a specific type, something like this:
Any other comments?
This would help when testing, so I can test that when the api returns a specific type, the correct thing gets rendered.
What versions are you using?
Package Version: 6.27.1
The text was updated successfully, but these errors were encountered: