api 4.2.1 → 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.2.1",
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,8 +23,8 @@
23
23
  "node": "^12 || ^14 || ^16"
24
24
  },
25
25
  "dependencies": {
26
- "@readme/oas-to-har": "^14.0.5",
27
- "@readme/openapi-parser": "^2.0.0",
26
+ "@readme/oas-to-har": "^16.1.0",
27
+ "@readme/openapi-parser": "^2.1.0",
28
28
  "datauri": "^4.1.0",
29
29
  "fetch-har": "^5.0.5",
30
30
  "find-cache-dir": "^3.3.1",
@@ -34,7 +34,7 @@
34
34
  "make-dir": "^3.1.0",
35
35
  "mimer": "^2.0.2",
36
36
  "node-fetch": "^2.6.0",
37
- "oas": "^17.4.1"
37
+ "oas": "^18.1.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@readme/eslint-config": "^8.0.2",
@@ -51,5 +51,5 @@
51
51
  "__tests__/__fixtures__/"
52
52
  ]
53
53
  },
54
- "gitHead": "0cdb386e34d37de51ce8909f5dc9c4cd338ef4de"
54
+ "gitHead": "d69e58465d8eff63aec29693f70d085247afb7ef"
55
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
+ };
@@ -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) => {