diff --git a/packages/elements-core/package.json b/packages/elements-core/package.json index ff4787e37..d7ba2d98b 100644 --- a/packages/elements-core/package.json +++ b/packages/elements-core/package.json @@ -1,6 +1,6 @@ { "name": "@stoplight/elements-core", - "version": "9.0.17", + "version": "9.0.18", "sideEffects": [ "web-components.min.js", "src/web-components/**", diff --git a/packages/elements-core/src/components/TryIt/build-request.spec.ts b/packages/elements-core/src/components/TryIt/build-request.spec.ts index d8a52ee26..6753a6ffa 100644 --- a/packages/elements-core/src/components/TryIt/build-request.spec.ts +++ b/packages/elements-core/src/components/TryIt/build-request.spec.ts @@ -210,4 +210,52 @@ describe('Build Request', () => { ]); }); }); + + describe('Build Request', () => { + describe('shouldIncludeBody for DELETE', () => { + it('Includes body for DELETE requests when bodyInput is provided', () => { + const httpOperation = { + method: 'DELETE', + path: '/delete/path', + request: { + body: { + contents: [ + { + mediaType: 'application/json', + }, + ], + }, + }, + }; + + const bodyInput = '{"key":"value"}'; + const shouldIncludeBody = + ['PUT', 'POST', 'PATCH', 'DELETE'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined; + + expect(shouldIncludeBody).toBe(true); + }); + + it('Does not include body for DELETE requests when bodyInput is undefined', () => { + const httpOperation = { + method: 'DELETE', + path: '/delete/path', + request: { + body: { + contents: [ + { + mediaType: 'application/json', + }, + ], + }, + }, + }; + + const bodyInput = undefined; + const shouldIncludeBody = + ['PUT', 'POST', 'PATCH', 'DELETE'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined; + + expect(shouldIncludeBody).toBe(false); + }); + }); + }); }); diff --git a/packages/elements-core/src/components/TryIt/build-request.ts b/packages/elements-core/src/components/TryIt/build-request.ts index 84ce2dd39..79b7922db 100644 --- a/packages/elements-core/src/components/TryIt/build-request.ts +++ b/packages/elements-core/src/components/TryIt/build-request.ts @@ -147,7 +147,7 @@ export async function buildFetchRequest({ const serverUrl = getServerUrl({ httpOperation, mockData, chosenServer, corsProxy, serverVariableValues }); const shouldIncludeBody = - ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined; + ['PUT', 'POST', 'PATCH', 'DELETE'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined; const queryParams = getQueryParams({ httpOperation, parameterValues }); @@ -264,7 +264,7 @@ export async function buildHarRequest({ const mimeType = mediaTypeContent?.mediaType ?? 'application/json'; const shouldIncludeBody = - ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined; + ['PUT', 'POST', 'PATCH', 'DELETE'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined; const queryParams = getQueryParams({ httpOperation, parameterValues }); diff --git a/packages/elements-dev-portal/package.json b/packages/elements-dev-portal/package.json index 7f34fbae1..149fae4b5 100644 --- a/packages/elements-dev-portal/package.json +++ b/packages/elements-dev-portal/package.json @@ -1,6 +1,6 @@ { "name": "@stoplight/elements-dev-portal", - "version": "3.0.17", + "version": "3.0.18", "description": "UI components for composing beautiful developer documentation.", "keywords": [], "sideEffects": [ @@ -66,7 +66,7 @@ "dependencies": { "@stoplight/markdown-viewer": "^5.7.1", "@stoplight/mosaic": "^1.53.5", - "@stoplight/elements-core": "~9.0.17", + "@stoplight/elements-core": "~9.0.18", "@stoplight/path": "^1.3.2", "@stoplight/types": "^14.0.0", "classnames": "^2.2.6", diff --git a/packages/elements/package.json b/packages/elements/package.json index 2f640b687..a2e84ddaa 100644 --- a/packages/elements/package.json +++ b/packages/elements/package.json @@ -1,6 +1,6 @@ { "name": "@stoplight/elements", - "version": "9.0.17", + "version": "9.0.18", "description": "UI components for composing beautiful developer documentation.", "keywords": [], "sideEffects": [ @@ -63,7 +63,7 @@ ] }, "dependencies": { - "@stoplight/elements-core": "~9.0.17", + "@stoplight/elements-core": "~9.0.18", "@stoplight/http-spec": "^7.1.0", "@stoplight/json": "^3.18.1", "@stoplight/mosaic": "^1.53.5",