Skip to content

Commit

Permalink
fix(core/src/types.ts): operatations option mock data now supports ar…
Browse files Browse the repository at this point in the history
…ray (#1283)

Co-authored-by: Wouter Kroes <[email protected]>
  • Loading branch information
wouterkroes and Wouter Kroes authored Mar 28, 2024
1 parent 6e521b5 commit e990899
Showing 1 changed file with 26 additions and 5 deletions.
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

0 comments on commit e990899

Please sign in to comment.