Skip to content
New issue

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

fix(core/src/types.ts): operations option mock data now supports array #1283

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export type NormalizedOperationOptions = {
transformer?: OutputTransformer;
mutator?: NormalizedMutator;
mock?: {
data?: MockProperties;
data?: MockData;
properties?: MockProperties;
};
contentType?: OverrideOutputContentType;
Expand Down Expand Up @@ -250,9 +250,30 @@ export type MockOptions = Omit<OverrideMockOptions, 'properties'> & {
tags?: Record<string, { properties: Record<string, unknown> }>;
};

export type MockProperties =
| { [key: string]: unknown }
| ((specs: OpenAPIObject) => { [key: string]: unknown });
export type MockPropertiesObject = {
[key: string]: unknown;
};
export type MockPropertiesObjectFn = (
specs: OpenAPIObject,
) => MockPropertiesObject;

export type MockProperties = MockPropertiesObject | MockPropertiesObjectFn;

export type MockDataObject = {
[key: string]: unknown;
};

export type MockDataObjectFn = (specs: OpenAPIObject) => MockDataObject;

export type MockDataArray = unknown[];

export type MockDataArrayFn = (specs: OpenAPIObject) => MockDataArray;

export type MockData =
| MockDataObject
| MockDataObjectFn
| MockDataArray
| MockDataArrayFn;

type OutputTransformerFn = (verb: GeneratorVerbOptions) => GeneratorVerbOptions;

Expand Down Expand Up @@ -387,7 +408,7 @@ export type OperationOptions = {
transformer?: OutputTransformer;
mutator?: Mutator;
mock?: {
data?: MockProperties;
data?: MockData;
properties?: MockProperties;
};
query?: QueryOptions;
Expand Down