Skip to content

Commit

Permalink
fix(client): respect multiple request body types (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan authored Jul 19, 2023
1 parent b1114a5 commit 098806a
Show file tree
Hide file tree
Showing 4 changed files with 862 additions and 42 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-parents-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'fets': patch
---

Respect multiple request body types
82 changes: 40 additions & 42 deletions packages/fets/src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,46 @@ export type OASRequestParams<
OASMethodMap<TOAS, TPath>[TMethod]['requestBody']['content']['application/json']['schema']
>;
}
: OASMethodMap<TOAS, TPath>[TMethod] extends {
requestBody: { content: { 'multipart/form-data': { schema: JSONSchema } } };
}
? OASMethodMap<TOAS, TPath>[TMethod]['requestBody'] extends { required: true }
? {
formData: FromSchema<
OASMethodMap<
TOAS,
TPath
>[TMethod]['requestBody']['content']['multipart/form-data']['schema']
>;
}
: {
formData?: FromSchema<
OASMethodMap<
TOAS,
TPath
>[TMethod]['requestBody']['content']['multipart/form-data']['schema']
>;
}
: OASMethodMap<TOAS, TPath>[TMethod] extends {
requestBody: { content: { 'application/x-www-form-urlencoded': { schema: JSONSchema } } };
}
? OASMethodMap<TOAS, TPath>[TMethod]['requestBody'] extends { required: true }
? {
formUrlEncoded: FromSchema<
OASMethodMap<
TOAS,
TPath
>[TMethod]['requestBody']['content']['application/x-www-form-urlencoded']['schema']
>;
}
: {
formUrlEncoded?: FromSchema<
OASMethodMap<
TOAS,
TPath
>[TMethod]['requestBody']['content']['application/x-www-form-urlencoded']['schema']
>;
}
: {}) &
(OASMethodMap<TOAS, TPath>[TMethod] extends { parameters: { name: string; in: string }[] }
? OASParamMap<OASMethodMap<TOAS, TPath>[TMethod]['parameters']>
Expand Down Expand Up @@ -305,48 +345,6 @@ export type OASRequestParams<
}
? OASSecurityParams<TSecurityScheme>
: {}
: {}) &
(OASMethodMap<TOAS, TPath>[TMethod] extends {
requestBody: { content: { 'multipart/form-data': { schema: JSONSchema } } };
}
? OASMethodMap<TOAS, TPath>[TMethod]['requestBody'] extends { required: true }
? {
formData: FromSchema<
OASMethodMap<
TOAS,
TPath
>[TMethod]['requestBody']['content']['multipart/form-data']['schema']
>;
}
: {
formData?: FromSchema<
OASMethodMap<
TOAS,
TPath
>[TMethod]['requestBody']['content']['multipart/form-data']['schema']
>;
}
: {}) &
(OASMethodMap<TOAS, TPath>[TMethod] extends {
requestBody: { content: { 'application/x-www-form-urlencoded': { schema: JSONSchema } } };
}
? OASMethodMap<TOAS, TPath>[TMethod]['requestBody'] extends { required: true }
? {
formUrlEncoded: FromSchema<
OASMethodMap<
TOAS,
TPath
>[TMethod]['requestBody']['content']['application/x-www-form-urlencoded']['schema']
>;
}
: {
formUrlEncoded?: FromSchema<
OASMethodMap<
TOAS,
TPath
>[TMethod]['requestBody']['content']['application/x-www-form-urlencoded']['schema']
>;
}
: {});

export type OASInput<
Expand Down
Loading

0 comments on commit 098806a

Please sign in to comment.