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

Commit

Permalink
feat: allowing for a HAR override to be passed in for snippet creation (
Browse files Browse the repository at this point in the history
#1249)

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

* test: fixing the test i added so auth shows up
  • Loading branch information
erunion authored Apr 13, 2021
1 parent 1492b0f commit df35bb8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
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

0 comments on commit df35bb8

Please sign in to comment.