api 4.0.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api",
3
- "version": "4.0.0",
3
+ "version": "4.2.0",
4
4
  "description": "Generate an SDK from an OpenAPI definition",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -23,10 +23,10 @@
23
23
  "node": "^12 || ^14 || ^16"
24
24
  },
25
25
  "dependencies": {
26
- "@readme/oas-to-har": "^13.8.1",
27
- "@readme/openapi-parser": "^1.1.0",
26
+ "@readme/oas-to-har": "^14.0.5",
27
+ "@readme/openapi-parser": "^2.0.0",
28
28
  "datauri": "^4.1.0",
29
- "fetch-har": "^5.0.0",
29
+ "fetch-har": "^5.0.5",
30
30
  "find-cache-dir": "^3.3.1",
31
31
  "form-data": "^4.0.0",
32
32
  "get-stream": "^6.0.0",
@@ -34,12 +34,12 @@
34
34
  "make-dir": "^3.1.0",
35
35
  "mimer": "^2.0.2",
36
36
  "node-fetch": "^2.6.0",
37
- "oas": "^16.0.3"
37
+ "oas": "^17.4.1"
38
38
  },
39
39
  "devDependencies": {
40
- "@readme/eslint-config": "^7.2.2",
41
- "@readme/oas-examples": "^4.3.2",
42
- "eslint": "^7.32.0",
40
+ "@readme/eslint-config": "^8.0.2",
41
+ "@readme/oas-examples": "^4.3.3",
42
+ "eslint": "^8.3.0",
43
43
  "jest": "^27.3.1",
44
44
  "memfs": "^3.2.4",
45
45
  "nock": "^13.1.3",
@@ -51,5 +51,5 @@
51
51
  "__tests__/__fixtures__/"
52
52
  ]
53
53
  },
54
- "gitHead": "f1d2c251f1468bceb78e39731e20f30c6745c419"
54
+ "gitHead": "eb3b741b7776ce01f3bafe7f23d2cd0df7ca8b21"
55
55
  }
package/src/cache.js CHANGED
@@ -123,7 +123,7 @@ class SdkCache {
123
123
  }
124
124
 
125
125
  return new Promise(resolve => {
126
- return resolve(json);
126
+ resolve(json);
127
127
  })
128
128
  .then(res => {
129
129
  // The `validate` method handles dereferencing for us.
@@ -193,7 +193,7 @@ class SdkCache {
193
193
 
194
194
  saveFile() {
195
195
  return new Promise(resolve => {
196
- return resolve(fs.readFileSync(this.uri, 'utf8'));
196
+ resolve(fs.readFileSync(this.uri, 'utf8'));
197
197
  })
198
198
  .then(res => {
199
199
  if (/\.(yaml|yml)/.test(this.uri)) {
package/src/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  const fetch = require('node-fetch');
2
2
  const fetchHar = require('fetch-har');
3
- const Oas = require('oas');
3
+ const Oas = require('oas').default;
4
4
  const oasToHar = require('@readme/oas-to-har');
5
5
  const pkg = require('../package.json');
6
6
 
7
7
  const Cache = require('./cache');
8
- const { parseResponse, prepareAuth, prepareParams, prepareServer } = require('./lib/index');
8
+ const { parseResponse, prepareAuth, prepareParams, prepareServer } = require('./lib');
9
9
 
10
10
  global.fetch = fetch;
11
11
  global.Request = fetch.Request;
@@ -19,9 +19,9 @@ class Sdk {
19
19
  }
20
20
 
21
21
  static getOperations(spec) {
22
- return Object.keys(spec.paths)
22
+ return Object.keys(spec.api.paths)
23
23
  .map(path => {
24
- return Object.keys(spec.paths[path]).map(method => {
24
+ return Object.keys(spec.api.paths[path]).map(method => {
25
25
  return spec.operation(path, method);
26
26
  });
27
27
  })
@@ -89,7 +89,7 @@ module.exports = async (operation, body, metadata) => {
89
89
  // body payload to see if anything in there is either a file path or a file stream so we can translate those into a
90
90
  // data URL for `@readme/oas-to-har` to make a request.
91
91
  if ('body' in params && operation.isMultipart()) {
92
- let requestBody = getSchema(operation.schema, operation.oas);
92
+ let requestBody = getSchema(operation.schema, operation.api);
93
93
  if (requestBody) {
94
94
  requestBody = requestBody.schema;
95
95
  } else {
@@ -111,7 +111,9 @@ module.exports = async (operation, body, metadata) => {
111
111
  file = path.resolve(file);
112
112
  if (fs.existsSync(file)) {
113
113
  conversions.push(
114
- new Promise(resolve => resolve(datauri(file))).then(dataurl => {
114
+ new Promise(resolve => {
115
+ resolve(datauri(file));
116
+ }).then(dataurl => {
115
117
  // Doing this manually for now until when/if https://github.com/data-uri/datauri/pull/29 is accepted.
116
118
  params.body[prop] = dataurl.replace(
117
119
  ';base64',
@@ -124,7 +126,9 @@ module.exports = async (operation, body, metadata) => {
124
126
  }
125
127
  } else if (file instanceof stream.Readable) {
126
128
  conversions.push(
127
- new Promise(resolve => resolve(getStream.buffer(file))).then(buffer => {
129
+ new Promise(resolve => {
130
+ resolve(getStream.buffer(file));
131
+ }).then(buffer => {
128
132
  // This logic was taken from the `datauri` package, and ideally it should be able to accept the content
129
133
  // of a file, or a file stream, but I'll PR that later to that package.
130
134
  // @todo
@@ -18,7 +18,7 @@ function stripTrailingSlash(url) {
18
18
  module.exports = (spec, url, variables = {}) => {
19
19
  let serverIdx;
20
20
  const sanitizedUrl = stripTrailingSlash(url);
21
- (spec.servers || []).forEach((server, i) => {
21
+ (spec.api.servers || []).forEach((server, i) => {
22
22
  if (server.url === sanitizedUrl) {
23
23
  serverIdx = i;
24
24
  }