Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit ff16eda

Browse files
authored
Merge pull request #19 from wrtnio/feature/union-prerequisite
fix: allow union type of prerequisite
2 parents f86633d + d0f27a1 commit ff16eda

File tree

2 files changed

+156
-38
lines changed

2 files changed

+156
-38
lines changed

src/structures/IOpenAiSchema.ts

Lines changed: 78 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -447,24 +447,83 @@ export namespace IOpenAiSchema {
447447
* Path of the endpoint.
448448
*/
449449
path: string;
450-
451-
/**
452-
* Function returning transformed values using JMESPath expression.
453-
*
454-
* `Prerequisite.Props.jmesPath` is a string typed property that extracts desired values
455-
* from the prerequisite API response using a JMESPath expression. This property simplifies
456-
* and replaces the `label`, `value`, and `array` properties.
457-
*
458-
* JMESPath expressions are used to extract the desired data based on the API response.
459-
* The expression must always be a valid JMESPath syntax.
460-
*
461-
* - Type: `jmesPath: string`
462-
* - Example: `"members[*].data.title"`
463-
* - Usage: `jmespath.search(response, jmesPath)`
464-
*
465-
* Note: The `label`, `value`, and `array` properties are no longer in use.
466-
*/
467-
jmesPath: string;
468-
};
450+
} & (
451+
| {
452+
/**
453+
* Function returning transformed values using JMESPath expression.
454+
*
455+
* `Prerequisite.Props.jmesPath` is a string typed property that extracts desired values
456+
* from the prerequisite API response using a JMESPath expression. This property simplifies
457+
* and replaces the `label`, `value`, and `array` properties.
458+
*
459+
* JMESPath expressions are used to extract the desired data based on the API response.
460+
* The expression must always be a valid JMESPath syntax.
461+
*
462+
* - Type: `jmesPath: string`
463+
* - Example: `"members[*].data.title"`
464+
* - Usage: `jmespath.search(response, jmesPath)`
465+
*
466+
* Note: The `label`, `value`, and `array` properties are no longer in use.
467+
*/
468+
jmesPath: string;
469+
}
470+
| {
471+
/**
472+
* Transform function returning label.
473+
*
474+
* `Prerequisite.Props.label` is a string typed property representing
475+
* a function returning the label from the element instance of the
476+
* prerequisite API respond array.
477+
*
478+
* The function script must be a string value that can be parsed by
479+
* `new Function(string)` statement. Also, its parameter names are
480+
* always `elem`, `index` and `array`. Of course, the function's
481+
* return type must be always `string`.
482+
*
483+
* - type: `label: (elem: Element, index: number, array: Element[]) => string`
484+
* - example: `return elem.title`
485+
* - how to use: `new Function("elem", "index", "array", labelScript)(...)`
486+
*/
487+
label: string;
488+
489+
/**
490+
* Transform function returning target value.
491+
*
492+
* `Prerequisite.Props.value` is a string typed property representing
493+
* a function returning the target value from the element instance of
494+
* the prerequisite API respond array. If you've defined this `Prerequisite`
495+
* type to a `number` type, the returned value must be actual number type.
496+
*
497+
* The function script must be a string value that can be parsed by
498+
* `new Function(string)` statement. Also, its parameter names are always
499+
* `elem`, `index` and `array`.
500+
*
501+
* - type: `value: (elem: Element, index: number, array: Element[]) => Value`
502+
* - example: `return elem.no`
503+
* - how to use: `new Function("elem", "index", "array", valueScript)(...)`
504+
*/
505+
value: string;
506+
507+
/**
508+
* Transform function returning array instance.
509+
*
510+
* `Prerequisite.Props.array` is a string typed property representing
511+
* a function returning an array instance from the response of the
512+
* prerequisite API.
513+
*
514+
* The function script must be a string value that can be parsed by
515+
* `new Function(string)` statement. Also, its parameter name is
516+
* always `response`.
517+
*
518+
* If the prerequisite API responses an array and it is the desired one,
519+
* you don't need to specify this property.
520+
*
521+
* - type: `array: (response: Response) => Elemenet[]`
522+
* - example: `return response.members.map(m => m.data)`
523+
* - how to use: `new Function("response", arrayScript)(response)`
524+
*/
525+
array?: string;
526+
}
527+
);
469528
}
470529
}

src/structures/ISwaggerSchema.ts

Lines changed: 78 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -169,24 +169,83 @@ export namespace ISwaggerSchema {
169169
* Path of the endpoint.
170170
*/
171171
path: string;
172-
173-
/**
174-
* Function returning transformed values using JMESPath expression.
175-
*
176-
* `Prerequisite.Props.jmesPath` is a string typed property that extracts desired values
177-
* from the prerequisite API response using a JMESPath expression. This property simplifies
178-
* and replaces the `label`, `value`, and `array` properties.
179-
*
180-
* JMESPath expressions are used to extract the desired data based on the API response.
181-
* The expression must always be a valid JMESPath syntax.
182-
*
183-
* - Type: `jmesPath: string`
184-
* - Example: `"members[*].data.title"`
185-
* - Usage: `jmespath.search(response, jmesPath)`
186-
*
187-
* Note: The `label`, `value`, and `array` properties are no longer in use.
188-
*/
189-
jmesPath: string;
190-
};
172+
} & (
173+
| {
174+
/**
175+
* Function returning transformed values using JMESPath expression.
176+
*
177+
* `Prerequisite.Props.jmesPath` is a string typed property that extracts desired values
178+
* from the prerequisite API response using a JMESPath expression. This property simplifies
179+
* and replaces the `label`, `value`, and `array` properties.
180+
*
181+
* JMESPath expressions are used to extract the desired data based on the API response.
182+
* The expression must always be a valid JMESPath syntax.
183+
*
184+
* - Type: `jmesPath: string`
185+
* - Example: `"members[*].data.title"`
186+
* - Usage: `jmespath.search(response, jmesPath)`
187+
*
188+
* Note: The `label`, `value`, and `array` properties are no longer in use.
189+
*/
190+
jmesPath: string;
191+
}
192+
| {
193+
/**
194+
* Transform function returning label.
195+
*
196+
* `Prerequisite.Props.label` is a string typed property representing
197+
* a function returning the label from the element instance of the
198+
* prerequisite API respond array.
199+
*
200+
* The function script must be a string value that can be parsed by
201+
* `new Function(string)` statement. Also, its parameter names are
202+
* always `elem`, `index` and `array`. Of course, the function's
203+
* return type must be always `string`.
204+
*
205+
* - type: `label: (elem: Element, index: number, array: Element[]) => string`
206+
* - example: `return elem.title`
207+
* - how to use: `new Function("elem", "index", "array", labelScript)(...)`
208+
*/
209+
label: string;
210+
211+
/**
212+
* Transform function returning target value.
213+
*
214+
* `Prerequisite.Props.value` is a string typed property representing
215+
* a function returning the target value from the element instance of
216+
* the prerequisite API respond array. If you've defined this `Prerequisite`
217+
* type to a `number` type, the returned value must be actual number type.
218+
*
219+
* The function script must be a string value that can be parsed by
220+
* `new Function(string)` statement. Also, its parameter names are always
221+
* `elem`, `index` and `array`.
222+
*
223+
* - type: `value: (elem: Element, index: number, array: Element[]) => Value`
224+
* - example: `return elem.no`
225+
* - how to use: `new Function("elem", "index", "array", valueScript)(...)`
226+
*/
227+
value: string;
228+
229+
/**
230+
* Transform function returning array instance.
231+
*
232+
* `Prerequisite.Props.array` is a string typed property representing
233+
* a function returning an array instance from the response of the
234+
* prerequisite API.
235+
*
236+
* The function script must be a string value that can be parsed by
237+
* `new Function(string)` statement. Also, its parameter name is
238+
* always `response`.
239+
*
240+
* If the prerequisite API responses an array and it is the desired one,
241+
* you don't need to specify this property.
242+
*
243+
* - type: `array: (response: Response) => Elemenet[]`
244+
* - example: `return response.members.map(m => m.data)`
245+
* - how to use: `new Function("response", arrayScript)(response)`
246+
*/
247+
array?: string;
248+
}
249+
);
191250
}
192251
}

0 commit comments

Comments
 (0)