api 4.1.3 → 4.3.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.1.3",
3
+ "version": "4.3.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": "^14.0.4",
27
- "@readme/openapi-parser": "^1.2.1",
26
+ "@readme/oas-to-har": "^16.1.0",
27
+ "@readme/openapi-parser": "^2.1.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,11 +34,11 @@
34
34
  "make-dir": "^3.1.0",
35
35
  "mimer": "^2.0.2",
36
36
  "node-fetch": "^2.6.0",
37
- "oas": "^17.1.0"
37
+ "oas": "^18.1.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@readme/eslint-config": "^8.0.2",
41
- "@readme/oas-examples": "^4.3.2",
41
+ "@readme/oas-examples": "^4.3.3",
42
42
  "eslint": "^8.3.0",
43
43
  "jest": "^27.3.1",
44
44
  "memfs": "^3.2.4",
@@ -50,5 +50,6 @@
50
50
  "testPathIgnorePatterns": [
51
51
  "__tests__/__fixtures__/"
52
52
  ]
53
- }
53
+ },
54
+ "gitHead": "d69e58465d8eff63aec29693f70d085247afb7ef"
54
55
  }
@@ -0,0 +1,34 @@
1
+ const {
2
+ utils: { findSchemaDefinition },
3
+ } = require('oas');
4
+
5
+ // Gets the schema of the first media type defined in the `content` of the path operation
6
+ // or returns the ref if there's no Request Body Object.
7
+ //
8
+ // If the ref looks like a `requestBodies` reference, then do a lookup for the actual schema
9
+ // https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#fixed-fields-8
10
+ module.exports = function getSchema(pathOperation, api) {
11
+ try {
12
+ if (pathOperation.requestBody.content) {
13
+ const type = Object.keys(pathOperation.requestBody.content)[0];
14
+
15
+ return {
16
+ type,
17
+ schema: pathOperation.requestBody.content[type],
18
+ };
19
+ }
20
+
21
+ if (pathOperation.requestBody && pathOperation.requestBody.$ref.match(/^#\/components\/requestBodies\/.*$/)) {
22
+ return getSchema({
23
+ requestBody: findSchemaDefinition(pathOperation.requestBody.$ref, api),
24
+ });
25
+ }
26
+
27
+ return {
28
+ type: 'application/json',
29
+ schema: pathOperation.requestBody,
30
+ };
31
+ } catch (e) {} // eslint-disable-line no-empty
32
+
33
+ return undefined;
34
+ };
@@ -6,18 +6,16 @@ const {
6
6
 
7
7
  module.exports = async function getResponseBody(response) {
8
8
  const contentType = response.headers.get('Content-Type');
9
- const isJson = contentType && (matchesMimeType.json(contentType) || matchesMimeType.wildcard(contentType));
9
+ const isJSON = contentType && (matchesMimeType.json(contentType) || matchesMimeType.wildcard(contentType));
10
10
 
11
- // We have to clone it before reading, just incase
12
- // we cannot parse it as JSON later, then we can
13
- // re-read again as plain text
14
- const clonedResponse = response.clone();
15
- let responseBody;
11
+ const responseBody = await response.text();
16
12
 
17
- try {
18
- responseBody = await response[isJson ? 'json' : 'text']();
19
- } catch (e) {
20
- responseBody = await clonedResponse.text();
13
+ if (isJSON) {
14
+ try {
15
+ return JSON.parse(responseBody);
16
+ } catch (e) {
17
+ // If our JSON parsing failed then we can just return plaintext instead.
18
+ }
21
19
  }
22
20
 
23
21
  return responseBody;
@@ -4,9 +4,7 @@ const stream = require('stream');
4
4
  const mimer = require('mimer');
5
5
  const getStream = require('get-stream');
6
6
  const datauri = require('datauri');
7
- const {
8
- utils: { getSchema },
9
- } = require('oas');
7
+ const getSchema = require('./getSchema');
10
8
 
11
9
  function digestParameters(parameters) {
12
10
  return parameters.reduce((prev, param) => {