api-def 0.14.0 → 0.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -112,9 +112,6 @@ class FetchRequestBackend {
112
112
  let responded = false;
113
113
  const body = context.getParsedBody();
114
114
  const bodyJsonify = body !== null && typeof body === "object" && !Utils.isFormDataLike(body) && !(body instanceof URLSearchParams);
115
- if (context.validation.bodyEncoding === "multipart/form-data" && Utils.isFormDataLike(body)) {
116
- Utils.assertFetchCompatibleFormData(body);
117
- }
118
115
  const headers = Utils.assign({
119
116
  // logic from axios
120
117
  "Content-Type": bodyJsonify ? "application/json;charset=utf-8" : undefined,
@@ -143,7 +140,14 @@ class FetchRequestBackend {
143
140
  if (requestConfig.debug) {
144
141
  console.log(`[api-def] Fetching '${url.href}' with options`, JSON.stringify(fetchOptions, null, 2));
145
142
  }
146
- const promise = this.fetch(url.href, fetchOptions).then((response) => {
143
+ const request = new Request(url.href, fetchOptions);
144
+ if (context.validation.bodyEncoding === "multipart/form-data" && Utils.isFormDataLike(body)) {
145
+ const contentType = request.headers.get("content-type");
146
+ if (!contentType?.toLowerCase().startsWith("multipart/form-data")) {
147
+ throw new Error("[api-def] multipart/form-data requires a fetch-compatible FormData implementation");
148
+ }
149
+ }
150
+ const promise = this.fetch(request).then((response) => {
147
151
  responded = true;
148
152
  if (!response.ok) {
149
153
  const error = new FetchError("Fetch failed");
@@ -77,9 +77,6 @@ export default class FetchRequestBackend {
77
77
  let responded = false;
78
78
  const body = context.getParsedBody();
79
79
  const bodyJsonify = body !== null && typeof body === "object" && !Utils.isFormDataLike(body) && !(body instanceof URLSearchParams);
80
- if (context.validation.bodyEncoding === "multipart/form-data" && Utils.isFormDataLike(body)) {
81
- Utils.assertFetchCompatibleFormData(body);
82
- }
83
80
  const headers = Utils.assign({
84
81
  // logic from axios
85
82
  "Content-Type": bodyJsonify ? "application/json;charset=utf-8" : undefined,
@@ -108,7 +105,14 @@ export default class FetchRequestBackend {
108
105
  if (requestConfig.debug) {
109
106
  console.log(`[api-def] Fetching '${url.href}' with options`, JSON.stringify(fetchOptions, null, 2));
110
107
  }
111
- const promise = this.fetch(url.href, fetchOptions).then((response) => {
108
+ const request = new Request(url.href, fetchOptions);
109
+ if (context.validation.bodyEncoding === "multipart/form-data" && Utils.isFormDataLike(body)) {
110
+ const contentType = request.headers.get("content-type");
111
+ if (!contentType?.toLowerCase().startsWith("multipart/form-data")) {
112
+ throw new Error("[api-def] multipart/form-data requires a fetch-compatible FormData implementation");
113
+ }
114
+ }
115
+ const promise = this.fetch(request).then((response) => {
112
116
  responded = true;
113
117
  if (!response.ok) {
114
118
  const error = new FetchError("Fetch failed");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-def",
3
- "version": "0.14.0",
3
+ "version": "0.14.2",
4
4
  "description": "Typed API definitions with middleware support",
5
5
  "main": "cjs/index.js",
6
6
  "types": "esm/index.d.ts",