Skip to content
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
56 changes: 18 additions & 38 deletions packages/api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dependencies": {
"@apidevtools/json-schema-ref-parser": "^9.0.1",
"@apidevtools/swagger-parser": "^10.0.1",
"@readme/oas-to-har": "^9.0.0",
"@readme/oas-to-har": "^10.0.0",
"datauri": "^3.0.0",
"fetch-har": "^4.0.1",
"find-cache-dir": "^3.3.1",
Expand All @@ -35,7 +35,7 @@
"make-dir": "^3.1.0",
"mimer": "^1.1.0",
"node-fetch": "^2.6.0",
"oas": "^5.0.0"
"oas": "^6.1.0"
},
"devDependencies": {
"@readme/eslint-config": "^3.4.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ class Sdk {

function loadOperations(spec) {
return Sdk.getOperations(spec)
.filter(operation => operation.operationId)
.filter(operation => operation.schema.operationId)
.reduce((prev, next) => {
return Object.assign(prev, {
[next.operationId]: ((operation, ...args) => {
[next.schema.operationId]: ((operation, ...args) => {
return fetchOperation(spec, operation, ...args);
}).bind(null, next),
});
Expand Down
11 changes: 8 additions & 3 deletions packages/api/src/lib/prepareAuth.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/* eslint-disable no-underscore-dangle */
// Needs work for supporting multiple different kinds of auth at the same time. for example if an operation uses
// OAuth and HTTP bearer, how can we guarantee that the OAuth bearer is used with oauth?
// @todo
/**
* @todo Needs work for supporting multiple different kinds of auth at the same time. for example if
* an operation uses OAuth and HTTP bearer, how can we guarantee that the OAuth bearer is used with
* OAuth?
*
* @param {Array} authKeys
* @param {Operation} operation
*/
module.exports = (authKeys, operation) => {
if (authKeys.length === 0) {
return {};
Expand Down
9 changes: 3 additions & 6 deletions packages/api/src/lib/prepareParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,8 @@ module.exports = async (operation, body, metadata) => {
let digested = {};
let hasDigestedParams = false;
if (shouldDigestParams) {
// @todo `operation.parameters` should also pull in common params (this does not happen automatically when dereffing!)
if ('parameters' in operation) {
digested = digestParameters(operation.parameters);
hasDigestedParams = Object.keys(digested).length;
}
digested = digestParameters(operation.getParameters());
hasDigestedParams = Object.keys(digested).length;
}

// No metadata was explicitly defined so we need to analyze the supplied, and we haven't already set a body then we
Expand Down Expand Up @@ -90,7 +87,7 @@ module.exports = async (operation, body, metadata) => {
// body payload to see if anything in there is either a file path or a file stream so we can translate those into a
// data URL for `@readme/oas-to-har` to make a request.
if ('body' in params && operation.isMultipart()) {
const schema = getSchema(operation, operation.oas) || { schema: {} };
const schema = getSchema(operation.schema, operation.oas) || { schema: {} };
const bodyKeys = Object.keys(params.body);

// Loop through the schema to look for `binary` properties so we know what we need to convert.
Expand Down
84 changes: 81 additions & 3 deletions packages/httpsnippet-client-api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/httpsnippet-client-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dependencies": {
"@readme/httpsnippet": "^2.2.2",
"content-type": "^1.0.4",
"oas": "^5.0.0",
"oas": "^6.1.0",
"path-to-regexp": "^6.1.0",
"stringify-object": "^3.3.0"
},
Expand Down
10 changes: 5 additions & 5 deletions packages/httpsnippet-client-api/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { match } = require('path-to-regexp');
const stringifyObject = require('stringify-object');
const CodeBuilder = require('@readme/httpsnippet/src/helpers/code-builder');
const contentType = require('content-type');
const OAS = require('oas/tooling');
const Oas = require('oas/tooling');

function buildAuthSnippet(authKey) {
// Auth key will be an array for Basic auth cases.
Expand Down Expand Up @@ -85,7 +85,7 @@ module.exports = function (source, options) {
}

const method = source.method.toLowerCase();
const oas = new OAS(opts.apiDefinition);
const oas = new Oas(opts.apiDefinition);
const operation = oas.getOperation(source.url, method);

if (!operation) {
Expand Down Expand Up @@ -120,7 +120,7 @@ module.exports = function (source, options) {

// If we have path parameters present, we should only add them in if we have an operationId as we don't want metadata
// to duplicate what we'll be setting the path in the snippet to.
if (typeof operation.operationId !== 'undefined') {
if ('operationId' in operation.schema) {
const pathParams = getParamsInPath(operation, path);
if (Object.keys(pathParams).length) {
Object.keys(pathParams).forEach(param => {
Expand Down Expand Up @@ -215,8 +215,8 @@ module.exports = function (source, options) {
const args = [];

let accessor = method;
if ('operationId' in operation && operation.operationId.length > 0) {
accessor = operation.operationId;
if ('operationId' in operation.schema && operation.schema.operationId.length > 0) {
accessor = operation.schema.operationId;
} else {
args.push(`'${decodeURIComponent(path)}'`);
}
Expand Down