@@ -97,11 +97,17 @@ export type ResponseObjectMap<T> = T extends { responses: any } ? T["responses"]
97
97
/** Return `content` for a Response Object */
98
98
export type ResponseContent < T > = T extends { content : any } ? T [ "content" ] : unknown ;
99
99
100
- /** Return `requestBody` for an Operation Object */
101
- export type OperationRequestBody < T > = T extends { requestBody ?: any } ? T [ "requestBody" ] : never ;
100
+ /** Return type of `requestBody` for an Operation Object */
101
+ export type OperationRequestBody < T > = "requestBody" extends keyof T ? T [ "requestBody" ] : never ;
102
+
103
+ /** Internal helper to get object type with only the `requestBody` property */
104
+ type PickRequestBody < T > = "requestBody" extends keyof T ? Pick < T , "requestBody" > : never ;
105
+
106
+ /** Resolve to `true` if request body is optional, else `false` */
107
+ export type IsOperationRequestBodyOptional < T > = RequiredKeysOf < PickRequestBody < T > > extends never ? true : false ;
102
108
103
109
/** Internal helper used in OperationRequestBodyContent */
104
- export type OperationRequestBodyMediaContent < T > = undefined extends OperationRequestBody < T >
110
+ export type OperationRequestBodyMediaContent < T > = IsOperationRequestBodyOptional < T > extends true
105
111
? ResponseContent < NonNullable < OperationRequestBody < T > > > | undefined
106
112
: ResponseContent < OperationRequestBody < T > > ;
107
113
@@ -152,7 +158,22 @@ export type GetValueWithDefault<Obj, KeyPattern, Default> = Obj extends any
152
158
export type MediaType = `${string } /${string } `;
153
159
/** Return any media type containing "json" (works for "application/json", "application/vnd.api+json", "application/vnd.oai.openapi+json") */
154
160
export type JSONLike < T > = FilterKeys < T , `${string } /json`> ;
155
- /** Filter objects that have required keys */
161
+
162
+ /**
163
+ * Filter objects that have required keys
164
+ * @deprecated Use `RequiredKeysOf` instead
165
+ */
156
166
export type FindRequiredKeys < T , K extends keyof T > = K extends unknown ? ( undefined extends T [ K ] ? never : K ) : K ;
157
- /** Does this object contain required keys? */
167
+ /**
168
+ * Does this object contain required keys?
169
+ * @deprecated Use `RequiredKeysOf` instead
170
+ */
158
171
export type HasRequiredKeys < T > = FindRequiredKeys < T , keyof T > ;
172
+
173
+ /** Helper to get the required keys of an object. If no keys are required, will be `undefined` with strictNullChecks enabled, else `never` */
174
+ type RequiredKeysOfHelper < T > = {
175
+ // biome-ignore lint/complexity/noBannedTypes: `{}` is necessary here
176
+ [ K in keyof T ] : { } extends Pick < T , K > ? never : K ;
177
+ } [ keyof T ] ;
178
+ /** Get the required keys of an object, or `never` if no keys are required */
179
+ export type RequiredKeysOf < T > = RequiredKeysOfHelper < T > extends undefined ? never : RequiredKeysOfHelper < T > ;
0 commit comments