diff --git a/packages/api/package-lock.json b/packages/api/package-lock.json index d21b830d..2b506a33 100644 --- a/packages/api/package-lock.json +++ b/packages/api/package-lock.json @@ -1729,45 +1729,18 @@ "dev": true }, "@readme/oas-extensions": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/@readme/oas-extensions/-/oas-extensions-9.0.0.tgz", - "integrity": "sha512-IYGh/ijZrDAeVxuc1/2YccZgdI7yWmh2HRE15BbD1GH174igvQlyndCaruXrzDdQ3r+V88NsEMRDfM2LFULJfA==" + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/@readme/oas-extensions/-/oas-extensions-10.0.0.tgz", + "integrity": "sha512-3x5ICxcyrXrG5bqwMKsrcJ7q4T6LmSx1cpPT0o5Xt/9mcu4ZB5hSUbYR0e1YbztqpHIru5hVEFKirSRVgieztA==" }, "@readme/oas-to-har": { - "version": "9.2.2", - "resolved": "https://registry.npmjs.org/@readme/oas-to-har/-/oas-to-har-9.2.2.tgz", - "integrity": "sha512-rcdkDIlWXgcMnE3AONNZHlqmc6EvGEGVYkt8Yy4eSACfynCNYDcYKmu83K7mXJtvi2mmsf2lWcHBfcZgBTB3nA==", + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/@readme/oas-to-har/-/oas-to-har-10.0.0.tgz", + "integrity": "sha512-CEG9n9/sVSovLMhhKfAn1i/TMx6KXWX0xzxWItv1qVohzPwRX2NoQJsz7z44rqUUlzc2GorOBdadi4WvjG82tQ==", "requires": { - "@readme/oas-extensions": "^9.0.0", - "oas": "^5.2.1", + "@readme/oas-extensions": "^10.0.0", + "oas": "^6.1.0", "parse-data-url": "^3.0.0" - }, - "dependencies": { - "oas": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/oas/-/oas-5.2.1.tgz", - "integrity": "sha512-8cVCAVbKb9YCmWTKr3sClZzD2QyUHPTnh8CXQ4m4N0yA4FSIZuaZIryxl8L03hKsjdGE/B5PtAjPRWmqwWEQgw==", - "requires": { - "@apidevtools/json-schema-ref-parser": "^9.0.6", - "cardinal": "^2.1.1", - "colors": "^1.1.2", - "figures": "^3.0.0", - "glob": "^7.1.2", - "inquirer": "^7.0.1", - "json-schema-merge-allof": "^0.7.0", - "json2yaml": "^1.1.0", - "jsonfile": "^6.0.0", - "jsonpointer": "^4.1.0", - "lodash": "^4.17.11", - "minimist": "^1.2.0", - "node-status": "^1.0.0", - "oas-normalize": "2.3.1", - "open": "^7.0.0", - "path-to-regexp": "^6.2.0", - "request": "^2.88.0", - "swagger-inline": "3.2.2" - } - } } }, "@sinonjs/commons": { @@ -6432,6 +6405,11 @@ "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=" }, + "lodash.kebabcase": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz", + "integrity": "sha1-hImxyw0p/4gZXM7KRI/21swpXDY=" + }, "lodash.set": { "version": "4.3.2", "resolved": "https://registry.npmjs.org/lodash.set/-/lodash.set-4.3.2.tgz", @@ -6830,9 +6808,9 @@ "dev": true }, "oas": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/oas/-/oas-5.2.0.tgz", - "integrity": "sha512-Dd5JELlCeAy45ZQuRnozW9SiT/devRyv8df4bcAm+kP/0uVlJku6p4bHNWFS+E+JNTqzj+Xx637ogAikQ2O8Hw==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/oas/-/oas-6.1.0.tgz", + "integrity": "sha512-2xl2UKxsF9Eyw8KTQUFwwwmvu3H1sOvwQuAiaTCR20uWWtcu7sjzXcrat7/Z0zsa+eyIhdLK/KkYz5JIjaZ/MA==", "requires": { "@apidevtools/json-schema-ref-parser": "^9.0.6", "cardinal": "^2.1.1", @@ -6840,10 +6818,12 @@ "figures": "^3.0.0", "glob": "^7.1.2", "inquirer": "^7.0.1", + "json-schema-merge-allof": "^0.7.0", "json2yaml": "^1.1.0", "jsonfile": "^6.0.0", "jsonpointer": "^4.1.0", "lodash": "^4.17.11", + "lodash.kebabcase": "^4.1.1", "minimist": "^1.2.0", "node-status": "^1.0.0", "oas-normalize": "2.3.1", diff --git a/packages/api/package.json b/packages/api/package.json index d75ec4a6..0cc32dde 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -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", @@ -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", diff --git a/packages/api/src/index.js b/packages/api/src/index.js index b913dc51..64d08b78 100644 --- a/packages/api/src/index.js +++ b/packages/api/src/index.js @@ -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), }); diff --git a/packages/api/src/lib/prepareAuth.js b/packages/api/src/lib/prepareAuth.js index a90d7669..be0cc1c4 100644 --- a/packages/api/src/lib/prepareAuth.js +++ b/packages/api/src/lib/prepareAuth.js @@ -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 {}; diff --git a/packages/api/src/lib/prepareParams.js b/packages/api/src/lib/prepareParams.js index ccf9ac22..11dc9480 100644 --- a/packages/api/src/lib/prepareParams.js +++ b/packages/api/src/lib/prepareParams.js @@ -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 @@ -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. diff --git a/packages/httpsnippet-client-api/package-lock.json b/packages/httpsnippet-client-api/package-lock.json index 83b286cb..45fc6cba 100644 --- a/packages/httpsnippet-client-api/package-lock.json +++ b/packages/httpsnippet-client-api/package-lock.json @@ -2736,6 +2736,27 @@ "integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==", "dev": true }, + "compute-gcd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/compute-gcd/-/compute-gcd-1.2.0.tgz", + "integrity": "sha1-/B7eW2UAHpUCJlAvRlQ4Y+T+oQ4=", + "requires": { + "validate.io-array": "^1.0.3", + "validate.io-function": "^1.0.2", + "validate.io-integer-array": "^1.0.0" + } + }, + "compute-lcm": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/compute-lcm/-/compute-lcm-1.1.0.tgz", + "integrity": "sha1-q9ltBAtBsKFm+JlEtci3xRHiGtU=", + "requires": { + "compute-gcd": "^1.2.0", + "validate.io-array": "^1.0.3", + "validate.io-function": "^1.0.2", + "validate.io-integer-array": "^1.0.0" + } + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -6314,6 +6335,24 @@ "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=" }, + "json-schema-compare": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/json-schema-compare/-/json-schema-compare-0.2.2.tgz", + "integrity": "sha512-c4WYmDKyJXhs7WWvAWm3uIYnfyWFoIp+JEoX34rctVvEkMYCPGhXtvmFFXiffBbxfZsvQ0RNnV5H7GvDF5HCqQ==", + "requires": { + "lodash": "^4.17.4" + } + }, + "json-schema-merge-allof": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/json-schema-merge-allof/-/json-schema-merge-allof-0.7.0.tgz", + "integrity": "sha512-kvsuSVnl1n5xnNEu5ed4o8r8ujSA4/IgRtHmpgfMfa7FOMIRAzN4F9qbuklouTn5J8bi83y6MQ11n+ERMMTXZg==", + "requires": { + "compute-lcm": "^1.1.0", + "json-schema-compare": "^0.2.2", + "lodash": "^4.17.4" + } + }, "json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", @@ -6480,6 +6519,11 @@ "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=" }, + "lodash.kebabcase": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz", + "integrity": "sha1-hImxyw0p/4gZXM7KRI/21swpXDY=" + }, "lodash.sortby": { "version": "4.7.0", "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", @@ -6838,9 +6882,9 @@ "dev": true }, "oas": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/oas/-/oas-5.2.0.tgz", - "integrity": "sha512-Dd5JELlCeAy45ZQuRnozW9SiT/devRyv8df4bcAm+kP/0uVlJku6p4bHNWFS+E+JNTqzj+Xx637ogAikQ2O8Hw==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/oas/-/oas-6.1.0.tgz", + "integrity": "sha512-2xl2UKxsF9Eyw8KTQUFwwwmvu3H1sOvwQuAiaTCR20uWWtcu7sjzXcrat7/Z0zsa+eyIhdLK/KkYz5JIjaZ/MA==", "requires": { "@apidevtools/json-schema-ref-parser": "^9.0.6", "cardinal": "^2.1.1", @@ -6848,10 +6892,12 @@ "figures": "^3.0.0", "glob": "^7.1.2", "inquirer": "^7.0.1", + "json-schema-merge-allof": "^0.7.0", "json2yaml": "^1.1.0", "jsonfile": "^6.0.0", "jsonpointer": "^4.1.0", "lodash": "^4.17.11", + "lodash.kebabcase": "^4.1.1", "minimist": "^1.2.0", "node-status": "^1.0.0", "oas-normalize": "2.3.1", @@ -9015,6 +9061,38 @@ "spdx-expression-parse": "^3.0.0" } }, + "validate.io-array": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/validate.io-array/-/validate.io-array-1.0.6.tgz", + "integrity": "sha1-W1osr9j4uFq7L4hroVPy2Tond00=" + }, + "validate.io-function": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/validate.io-function/-/validate.io-function-1.0.2.tgz", + "integrity": "sha1-NDoZgC7TsZaCaceA5VjpNBHAutc=" + }, + "validate.io-integer": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/validate.io-integer/-/validate.io-integer-1.0.5.tgz", + "integrity": "sha1-FoSWSAuVviJH7EQ/IjPeT4mHgGg=", + "requires": { + "validate.io-number": "^1.0.3" + } + }, + "validate.io-integer-array": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/validate.io-integer-array/-/validate.io-integer-array-1.0.0.tgz", + "integrity": "sha1-LKveAzKTpry+Bj/q/pHq9GsToIk=", + "requires": { + "validate.io-array": "^1.0.3", + "validate.io-integer": "^1.0.4" + } + }, + "validate.io-number": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/validate.io-number/-/validate.io-number-1.0.3.tgz", + "integrity": "sha1-9j/+2iSL8opnqNSODjtGGhZluvg=" + }, "validator": { "version": "12.2.0", "resolved": "https://registry.npmjs.org/validator/-/validator-12.2.0.tgz", diff --git a/packages/httpsnippet-client-api/package.json b/packages/httpsnippet-client-api/package.json index b0f5f934..650fac38 100644 --- a/packages/httpsnippet-client-api/package.json +++ b/packages/httpsnippet-client-api/package.json @@ -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" }, diff --git a/packages/httpsnippet-client-api/src/index.js b/packages/httpsnippet-client-api/src/index.js index 35a0e5aa..14e79e6a 100644 --- a/packages/httpsnippet-client-api/src/index.js +++ b/packages/httpsnippet-client-api/src/index.js @@ -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. @@ -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) { @@ -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 => { @@ -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)}'`); }