Skip to content

Commit 4f9d4ef

Browse files
authored
Merge pull request #66 from dev-five-git/allow-all
Allow all
2 parents eff4995 + 78bda78 commit 4f9d4ef

File tree

3 files changed

+73
-8
lines changed

3 files changed

+73
-8
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"changes":{"packages/core/package.json":"Patch"},"note":"Allow allof schema","date":"2026-04-13T08:11:19.490039800Z"}

packages/core/src/__tests__/types.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,55 @@ describe('DevupObject', () => {
345345
>().toEqualTypeOf<CreateUserRequest>()
346346
expectTypeOf<ReturnType<typeof createUser>>().toEqualTypeOf<User>()
347347
})
348+
349+
test('default (no R) accesses all component schemas merged', () => {
350+
// DevupObject without R should merge response + request + error
351+
type All = DevupObject<
352+
keyof { response: never; request: never; error: never },
353+
'test-api.json'
354+
>
355+
356+
// response keys accessible
357+
type User = All['User']
358+
expectTypeOf<User>().toEqualTypeOf<{
359+
id: number
360+
name: string
361+
email: string
362+
}>()
363+
364+
// request keys accessible
365+
type CreateUser = All['CreateUserRequest']
366+
expectTypeOf<CreateUser>().toEqualTypeOf<{ name: string; email: string }>()
367+
368+
// error keys accessible
369+
type ApiError = All['ApiError']
370+
expectTypeOf<ApiError>().toEqualTypeOf<{ code: string; message: string }>()
371+
})
372+
373+
test('default DevupObject includes all schemas from all contexts', () => {
374+
// Verify that response, request, error keys all exist
375+
type AllKeys = keyof DevupObject<
376+
keyof { response: never; request: never; error: never },
377+
'test-api.json'
378+
>
379+
380+
// response keys
381+
type HasUser = 'User' extends AllKeys ? true : false
382+
type HasUserList = 'UserList' extends AllKeys ? true : false
383+
// request keys
384+
type HasCreateUser = 'CreateUserRequest' extends AllKeys ? true : false
385+
type HasUpdateUser = 'UpdateUserRequest' extends AllKeys ? true : false
386+
// error keys
387+
type HasApiError = 'ApiError' extends AllKeys ? true : false
388+
type HasNotFound = 'NotFoundError' extends AllKeys ? true : false
389+
390+
expectTypeOf<HasUser>().toEqualTypeOf<true>()
391+
expectTypeOf<HasUserList>().toEqualTypeOf<true>()
392+
expectTypeOf<HasCreateUser>().toEqualTypeOf<true>()
393+
expectTypeOf<HasUpdateUser>().toEqualTypeOf<true>()
394+
expectTypeOf<HasApiError>().toEqualTypeOf<true>()
395+
expectTypeOf<HasNotFound>().toEqualTypeOf<true>()
396+
})
348397
})
349398

350399
// =============================================================================

packages/core/src/api-struct.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,31 @@ export interface DevupPrecomputedScopes {}
3636

3737
type LowercaseMethod = 'get' | 'post' | 'put' | 'delete' | 'patch'
3838

39+
type DevupComponentStructByRole = {
40+
response: DevupResponseComponentStruct
41+
request: DevupRequestComponentStruct
42+
error: DevupErrorComponentStruct
43+
}
44+
45+
type DevupObjectAll<T extends string> = ExtractValue<
46+
DevupResponseComponentStruct,
47+
T,
48+
unknown
49+
> &
50+
ExtractValue<DevupRequestComponentStruct, T, unknown> &
51+
ExtractValue<DevupErrorComponentStruct, T, unknown>
52+
53+
type DevupObjectSpecific<
54+
R extends keyof DevupComponentStructByRole,
55+
T extends string,
56+
> = ExtractValue<DevupComponentStructByRole[R], T>
57+
3958
export type DevupObject<
40-
R extends 'response' | 'request' | 'error' = 'response',
59+
R extends keyof DevupComponentStructByRole = keyof DevupComponentStructByRole,
4160
T extends keyof DevupApiServers | (string & {}) = 'openapi.json',
42-
> = R extends 'response'
43-
? ExtractValue<DevupResponseComponentStruct, T>
44-
: R extends 'request'
45-
? ExtractValue<DevupRequestComponentStruct, T>
46-
: R extends 'error'
47-
? ExtractValue<DevupErrorComponentStruct, T>
48-
: never
61+
> = [keyof DevupComponentStructByRole] extends [R]
62+
? DevupObjectAll<T & string>
63+
: DevupObjectSpecific<R, T & string>
4964

5065
export type DevupGetApiStructScope<O extends string> = ConditionalScope<
5166
DevupGetApiStruct,

0 commit comments

Comments
 (0)