@@ -67,11 +67,16 @@ export type OperationRequestBodyContent<T> = FilterKeys<
67
67
| undefined
68
68
: FilterKeys < OperationRequestBodyMediaContent < T > , MediaType > ;
69
69
/** Return first 2XX response from a Response Object Map */
70
- export type SuccessResponse < T > = FilterKeys < FilterKeys < T , OkStatus > , "content" > ;
70
+ export type SuccessResponse < T > = ResponseContent < FilterKeys < T , OkStatus > > ;
71
71
/** Return first 5XX or 4XX response (in that order) from a Response Object Map */
72
- export type ErrorResponse < T > = FilterKeys <
73
- FilterKeys < T , ErrorStatus > ,
74
- "content"
72
+ export type ErrorResponse < T > = ResponseContent < FilterKeys < T , ErrorStatus > > ;
73
+ /** Return first JSON-like 2XX response from a path + HTTP method */
74
+ export type SuccessResponseJSON < PathMethod > = JSONLike <
75
+ SuccessResponse < ResponseObjectMap < PathMethod > >
76
+ > ;
77
+ /** Return first JSON-like 5XX or 4XX response from a path + HTTP method */
78
+ export type ErrorResponseJSON < PathMethod > = JSONLike <
79
+ ErrorResponse < ResponseObjectMap < PathMethod > >
75
80
> ;
76
81
77
82
// Generic TS utils
@@ -82,6 +87,8 @@ export type FilterKeys<Obj, Matchers> = {
82
87
} [ keyof Obj ] ;
83
88
/** Return any `[string]/[string]` media type (important because openapi-fetch allows any content response, not just JSON-like) */
84
89
export type MediaType = `${string } /${string } `;
90
+ /** Return any media type containing "json" (works for "application/json", "application/vnd.api+json", "application/vnd.oai.openapi+json") */
91
+ export type JSONLike < T > = FilterKeys < T , `${string } /json`> ;
85
92
/** Filter objects that have required keys */
86
93
export type FindRequiredKeys < T , K extends keyof T > = K extends unknown
87
94
? undefined extends T [ K ]
0 commit comments