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

Commit 3b375fa

Browse files
authored
Merge pull request #18 from wrtnio/feature/jmespath
feat: change `x-wrtn-prerequisite` property to use jmespath
2 parents 1682a08 + ab191cb commit 3b375fa

File tree

2 files changed

+23
-99
lines changed

2 files changed

+23
-99
lines changed

src/structures/IOpenAiSchema.ts

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -449,60 +449,22 @@ export namespace IOpenAiSchema {
449449
path: string;
450450

451451
/**
452-
* Transform function returning label.
452+
* Function returning transformed values using JMESPath expression.
453453
*
454-
* `Prerequisite.Props.label` is a string typed property representing
455-
* a function returning the label from the element instance of the
456-
* prerequisite API respond array.
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.
457457
*
458-
* The function script must be a string value that can be parsed by
459-
* `new Function(string)` statement. Also, its parameter names are
460-
* always `elem`, `index` and `array`. Of course, the function's
461-
* return type must be always `string`.
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.
462460
*
463-
* - type: `label: (elem: Element, index: number, array: Element[]) => string`
464-
* - example: `return elem.title`
465-
* - how to use: `new Function("elem", "index", "array", labelScript)(...)`
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.
466466
*/
467-
label: string;
468-
469-
/**
470-
* Transform function returning target value.
471-
*
472-
* `Prerequisite.Props.value` is a string typed property representing
473-
* a function returning the target value from the element instance of
474-
* the prerequisite API respond array. If you've defined this `Prerequisite`
475-
* type to a `number` type, the returned value must be actual number type.
476-
*
477-
* The function script must be a string value that can be parsed by
478-
* `new Function(string)` statement. Also, its parameter names are always
479-
* `elem`, `index` and `array`.
480-
*
481-
* - type: `value: (elem: Element, index: number, array: Element[]) => Value`
482-
* - example: `return elem.no`
483-
* - how to use: `new Function("elem", "index", "array", valueScript)(...)`
484-
*/
485-
value: string;
486-
487-
/**
488-
* Transform function returning array instance.
489-
*
490-
* `Prerequisite.Props.array` is a string typed property representing
491-
* a function returning an array instance from the response of the
492-
* prerequisite API.
493-
*
494-
* The function script must be a string value that can be parsed by
495-
* `new Function(string)` statement. Also, its parameter name is
496-
* always `response`.
497-
*
498-
* If the prerequisite API responses an array and it is the desired one,
499-
* you don't need to specify this property.
500-
*
501-
* - type: `array: (response: Response) => Elemenet[]`
502-
* - example: `return response.members.map(m => m.data)`
503-
* - how to use: `new Function("response", arrayScript)(response)`
504-
*/
505-
array?: string;
467+
jmesPath: string;
506468
};
507469
}
508470
}

src/structures/ISwaggerSchema.ts

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -171,60 +171,22 @@ export namespace ISwaggerSchema {
171171
path: string;
172172

173173
/**
174-
* Transform function returning label.
174+
* Function returning transformed values using JMESPath expression.
175175
*
176-
* `Prerequisite.Props.label` is a string typed property representing
177-
* a function returning the label from the element instance of the
178-
* prerequisite API respond array.
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.
179179
*
180-
* The function script must be a string value that can be parsed by
181-
* `new Function(string)` statement. Also, its parameter names are
182-
* always `elem`, `index` and `array`. Of course, the function's
183-
* return type must be always `string`.
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.
184182
*
185-
* - type: `label: (elem: Element, index: number, array: Element[]) => string`
186-
* - example: `return elem.title`
187-
* - how to use: `new Function("elem", "index", "array", labelScript)(...)`
188-
*/
189-
label: string;
190-
191-
/**
192-
* Transform function returning target value.
193-
*
194-
* `Prerequisite.Props.value` is a string typed property representing
195-
* a function returning the target value from the element instance of
196-
* the prerequisite API respond array. If you've defined this `Prerequisite`
197-
* type to a `number` type, the returned value must be actual number type.
198-
*
199-
* The function script must be a string value that can be parsed by
200-
* `new Function(string)` statement. Also, its parameter names are always
201-
* `elem`, `index` and `array`.
202-
*
203-
* - type: `value: (elem: Element, index: number, array: Element[]) => Value`
204-
* - example: `return elem.no`
205-
* - how to use: `new Function("elem", "index", "array", valueScript)(...)`
206-
*/
207-
value: string;
208-
209-
/**
210-
* Transform function returning array instance.
211-
*
212-
* `Prerequisite.Props.array` is a string typed property representing
213-
* a function returning an array instance from the response of the
214-
* prerequisite API.
215-
*
216-
* The function script must be a string value that can be parsed by
217-
* `new Function(string)` statement. Also, its parameter name is
218-
* always `response`.
219-
*
220-
* If the prerequisite API responses an array and it is the desired one,
221-
* you don't need to specify this property.
183+
* - Type: `jmesPath: string`
184+
* - Example: `"members[*].data.title"`
185+
* - Usage: `jmespath.search(response, jmesPath)`
222186
*
223-
* - type: `array: (response: Response) => Elemenet[]`
224-
* - example: `return response.members.map(m => m.data)`
225-
* - how to use: `new Function("response", arrayScript)(response)`
187+
* Note: The `label`, `value`, and `array` properties are no longer in use.
226188
*/
227-
array?: string;
189+
jmesPath: string;
228190
};
229191
}
230192
}

0 commit comments

Comments
 (0)