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

Commit ab191cb

Browse files
committed
feat: apply jmespath to ISwaggerSchema too
1 parent d2a50f2 commit ab191cb

File tree

1 file changed

+11
-49
lines changed

1 file changed

+11
-49
lines changed

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)