You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: helpers for Type Inference from API Endpoints (#4)
* feat(OpenAPI): enhance type exports and module declarations in generateDTS function
* fix: remove unnecessary blank line before return statement in generateDTS function
* docs: update section titles and add path-based type helpers with examples
* fix: reorder import statements in openapi-type-helpers.md for clarity
* feat(OpenAPI): add advanced type helpers for OpenAPI schema operations
* chore: improve type export formatting and indentation
* chore: move ParseInt type definition
* chore: add @productdevbook to license
---------
Co-authored-by: Johann Schopplich <mail@johannschopplich.com>
Copy file name to clipboardExpand all lines: docs/reference/openapi-type-helpers.md
+53-1Lines changed: 53 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
When building clients with the [`OpenAPIBuilder` extension](/extensions/openapi), you may want to access the request and response types for each operation in the OpenAPI schema. APIful provides a set of shorthand types to help you with this.
4
4
5
-
## Example
5
+
## Basic Operation Helpers
6
6
7
7
Given the API service name `petStore`, APIful generates the following types:
8
8
@@ -37,3 +37,55 @@ interface _Pet {
37
37
status?:'available'|'pending'|'sold'
38
38
}
39
39
```
40
+
41
+
## Path-based Type Helpers
42
+
43
+
In addition to operation-based helpers, APIful also provides more direct path-based type helpers. These allow you to extract types directly from path and HTTP method combinations:
44
+
45
+
-`PathParamsFrom<API>` - Extract path parameters for a specific path and method
46
+
-`RequestBodyFrom<API>` - Extract request body type for a specific path and method
47
+
-`QueryParamsFrom<API>` - Extract query parameters for a specific path and method
48
+
-`ResponseFrom<API>` - Extract response body type for a specific path and method with optional status code
49
+
50
+
### Examples
51
+
52
+
Using the same `petStore` API, you can access types directly from paths:
1. **Direct access by URL path** - Use the actual API path as you would write it in your code
87
+
2. **HTTP method specificity** - Extract types for specific HTTP methods on the same path
88
+
3. **Status code support** - Extract response types for specific status codes
89
+
4. **IDE integration** - Better completion support in IDEs since paths are directly tied to your OpenAPI schema
90
+
91
+
These path-based helpers work particularly well when you want to type parameters or responses for specific API endpoints that you're working with in your code.
0 commit comments