Skip to content

Commit

Permalink
Fix escaping header values and remove dead code.
Browse files Browse the repository at this point in the history
  • Loading branch information
wparad committed Sep 6, 2024
1 parent c32578f commit c697b02
Showing 1 changed file with 1 addition and 36 deletions.
37 changes: 1 addition & 36 deletions src/components/api-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,6 @@ export default class ApiRequest extends LitElement {
const requestPanelEl = this.closest('.request-panel');
const pathParamEls = [...requestPanelEl.querySelectorAll("[data-ptype='path']")];
const queryParamEls = [...requestPanelEl.querySelectorAll("[data-ptype='query']")];

const queryParamObjTypeEls = [...requestPanelEl.querySelectorAll("[data-ptype='query-object']")];
const headerParamEls = [...requestPanelEl.querySelectorAll("[data-ptype='header']")];
const requestBodyContainerEl = requestPanelEl.querySelector('.request-body-container');

Expand Down Expand Up @@ -758,39 +756,6 @@ export default class ApiRequest extends LitElement {
}
});

// Query Params (Dynamic - create from JSON)
queryParamObjTypeEls.map((el) => {
try {
let queryParamObj = {};
const paramSerializeStyle = el.dataset.paramSerializeStyle;
const paramSerializeExplode = el.dataset.paramSerializeExplode;
queryParamObj = Object.assign(queryParamObj, JSON.parse(el.value.replace(/\s+/g, ' ')));
for (const key in queryParamObj) {
if (typeof queryParamObj[key] === 'object') {
if (Array.isArray(queryParamObj[key])) {
if (paramSerializeStyle === 'spaceDelimited') {
fetchUrl.searchParams.append(key, queryParamObj[key].join(' '));
} else if (paramSerializeStyle === 'pipeDelimited') {
fetchUrl.searchParams.append(key, queryParamObj[key].join('|'));
} else {
if (paramSerializeExplode === 'true' || paramSerializeExplode === true) { // eslint-disable-line no-lonely-if
queryParamObj[key].forEach((v) => {
fetchUrl.searchParams.append(key, v);
});
} else {
fetchUrl.searchParams.append(key, queryParamObj[key]);
}
}
}
} else {
fetchUrl.searchParams.append(key, queryParamObj[key]);
}
}
} catch (err) {
console.log('OpenAPI Explorer: unable to parse %s into object', el.value); // eslint-disable-line no-console
}
});

// Add Authentication api keys if provided
this.api_keys.filter((v) => v.finalKeyValue).forEach((v) => {
if (v.in === 'query') {
Expand Down Expand Up @@ -938,7 +903,7 @@ export default class ApiRequest extends LitElement {
const { fetchOptions, fetchUrl, curlParts } = this.recomputeFetchOptions();
const curl = `curl -X ${this.method.toUpperCase()} "${fetchUrl.toString()}"`;
const headers = headerOverride ?? fetchOptions.headers;
const curlHeaders = [...headers.entries()].reduce((acc, [key, value]) => `${acc} \\\n -H "${key}: ${value}"`, '');
const curlHeaders = [...headers.entries()].reduce((acc, [key, value]) => `${acc} \\\n -H "${key}: ${value.replace(/"/g, '\\"')}"`, '');
this.curlSyntax = `${curl}${curlHeaders}${curlParts.data}${curlParts.form}`;
} catch (error) {
/* There was an explicit issue and likely it was because the fetch options threw. */
Expand Down

0 comments on commit c697b02

Please sign in to comment.