Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

feat: allowing for a HAR override to be passed in for snippet creation #1249

Merged
merged 2 commits into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/oas-to-snippet/__tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,19 @@ Object {
"highlightMode": "shell",
}
`;

exports[`should be able to accept a har override 1`] = `
Object {
"code": "const fetch = require('node-fetch');

const url = 'https://dash.readme.io/api/v1/categories/';

const options = {method: 'GET', headers: {authorization: 'Basic xxx'}};

fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error('error:' + err));",
"highlightMode": "javascript",
}
`;
26 changes: 26 additions & 0 deletions packages/oas-to-snippet/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,32 @@ const operation = {

const formData = { path: { id: 123 } };

test('should be able to accept a har override', () => {
const harOverride = {
log: {
entries: [
{
request: {
method: 'GET',
url: 'https://dash.readme.io/api/v1/categories/',
httpVersion: 'HTTPS/1.1',
headers: [
{
name: 'authorization',
value: 'Basic xxx',
},
],
queryString: [],
},
},
],
},
};

const codeSnippet = generateCodeSnippet(oas, operation, {}, {}, 'node', oasUrl, harOverride);
expect(codeSnippet).toMatchSnapshot();
});

test('should return falsy values for an unknown language', () => {
const codeSnippet = generateCodeSnippet(oas, operation, {}, {}, 'css', oasUrl);

Expand Down
5 changes: 3 additions & 2 deletions packages/oas-to-snippet/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ const supportedLanguages = require('./supportedLanguages');
* @param {Object} auth
* @param {String} lang
* @param {String} oasUrl
* @param {Object|undefined} harOverride
*/
module.exports = (oas, operation, values, auth, lang, oasUrl) => {
const har = generateHar(oas, operation, values, auth);
module.exports = (oas, operation, values, auth, lang, oasUrl, harOverride) => {
const har = harOverride || generateHar(oas, operation, values, auth);

// API SDK client needs additional runtime information on the API definition we're showing the user so it can
// generate an appropriate snippet.
Expand Down