Skip to content

Commit

Permalink
infer arg type when only header or cookie parameter is present - fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaishankar committed Apr 4, 2022
1 parent 49d1451 commit b62ee71
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export type OpArgType<OP> = OP extends {
path?: infer P
query?: infer Q
body?: infer B
header?: unknown // ignore
cookie?: unknown // ignore
}
// openapi 3
requestBody?: {
Expand Down
28 changes: 28 additions & 0 deletions test/infer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,34 @@ describe('infer', () => {
expect(same).toBe(true)
})

it('only header/cookie parameter with requestBody', () => {
type RequestBody = {
requestBody: {
content: {
'application/json': { bar: boolean }
}
}
}

type HeaderOnly = {
parameters: {
header: { foo: string }
}
} & RequestBody

type CookieOnly = {
parameters: {
cookie: { foo: string }
}
} & RequestBody

const header: Same<OpArgType<HeaderOnly>, { bar: boolean }> = true
const cookie: Same<OpArgType<CookieOnly>, { bar: boolean }> = true

expect(header).toBe(true)
expect(cookie).toBe(true)
})

const err: Err = { data: { error: {} } } as any
expect(err.data.error.charge).toBeUndefined()
})
Expand Down

0 comments on commit b62ee71

Please sign in to comment.