serverless-openapi-documenter 0.0.124 → 0.1.1

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/README.md CHANGED
@@ -12,7 +12,9 @@
12
12
  </a>
13
13
  </p>
14
14
 
15
- This will generate an OpenAPI V3 (up to v3.0.4) file for you from your serverless file. It can optionally generate a [Postman Collection V2](https://github.com/postmanlabs/openapi-to-postman) or (as of 0.0.120) [Bruno Collection](https://docs.usebruno.com/) from the OpenAPI file. This currently works for `http` and `httpApi` configurations.
15
+ This will generate an OpenAPI V3 (up to v3.1.2) Document file for you from your serverless file. It can optionally generate a [Postman Collection V2](https://github.com/postmanlabs/openapi-to-postman) or (as of 0.0.120) [Bruno Collection](https://docs.usebruno.com/) from the OpenAPI file. This currently works for `http` and `httpApi` configurations.
16
+
17
+ As of version 0.1.0, you can now create [OpenAPI V3.1 (3.1.x)](https://spec.openapis.org/oas/v3.1.2.html) Documents, should you run the command `serverless openapi generate -o openapi.json -f json -a 3.1.2 -p postman.json`. Please see this [guide on migrating to V3.1](https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0). Whilst I perosnally use this plugin all the time, please do open and report bugs, and I will do my best to fix them.
16
18
 
17
19
  Originally based off of: https://github.com/temando/serverless-openapi-documentation
18
20
 
@@ -1109,7 +1111,7 @@ module.exports = {
1109
1111
  dereference: {
1110
1112
  circular: false, // Don't allow circular $refs
1111
1113
  excludedPathMatcher: (
1112
- path // Skip dereferencing content under any 'example' key
1114
+ path, // Skip dereferencing content under any 'example' key
1113
1115
  ) => path.includes("/example/"),
1114
1116
  },
1115
1117
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serverless-openapi-documenter",
3
- "version": "0.0.124",
3
+ "version": "0.1.1",
4
4
  "description": "Generate OpenAPI v3 documentation and Postman Collections from your Serverless Config",
5
5
  "main": "index.js",
6
6
  "keywords": [
@@ -17,7 +17,11 @@
17
17
  "swagger",
18
18
  "openAPI",
19
19
  "openAPIv3",
20
+ "openAPIv3.1",
20
21
  "openAPI3",
22
+ "openAPI3.1",
23
+ "OpenAPI 3",
24
+ "OpenAPI 3.1",
21
25
  "Postman",
22
26
  "PostmanCollections",
23
27
  "Postman-Collections",
@@ -49,8 +53,8 @@
49
53
  "license": "MIT",
50
54
  "dependencies": {
51
55
  "@apidevtools/json-schema-ref-parser": "^9.1.0",
52
- "@redocly/openapi-core": "^1.2.0",
53
- "@usebruno/converters": "^0.16.0",
56
+ "@redocly/openapi-core": "^1.34.5",
57
+ "@usebruno/converters": "^0.17.1",
54
58
  "chalk": "^4.1.2",
55
59
  "js-yaml": "^4.1.1",
56
60
  "json-schema-for-openapi": "^0.5.0",
@@ -16,6 +16,12 @@ class SchemaHandler {
16
16
  this.documentation = serverless.service.custom.documentation;
17
17
  this.openAPI = openAPI;
18
18
 
19
+ this.shouldConvert = true;
20
+ if (/(3\.1\.\d)/g.test(this.openAPI.openapi)) this.shouldConvert = false;
21
+
22
+ this.logger.verbose(`OpenAPI version: ${this.openAPI.openapi}`);
23
+ this.logger.verbose(`Convert Schemas: ${this.shouldConvert}`);
24
+
19
25
  this.modelReferences = {};
20
26
 
21
27
  this.__standardiseModels();
@@ -53,7 +59,7 @@ class SchemaHandler {
53
59
  model.schema = null;
54
60
  model.schemas = {};
55
61
  for (const key in model.content) {
56
- Object.assign(model.schemas, {[key]: {schema: model.content[key].schema}});
62
+ Object.assign(model.schemas, { [key]: { schema: model.content[key].schema } });
57
63
  }
58
64
  // model.schema = model.content[contentType].schema;
59
65
  }
@@ -82,7 +88,7 @@ class SchemaHandler {
82
88
  for (const model of this.models) {
83
89
  const modelName = model.name;
84
90
  const schemas = []
85
- if (model.schema){
91
+ if (model.schema) {
86
92
  // const modelSchema = model.schema;
87
93
  schemas.push(model.schema)
88
94
  } else {
@@ -119,8 +125,7 @@ class SchemaHandler {
119
125
  }
120
126
  } else {
121
127
  throw new Error(
122
- `There was an error converting the ${
123
- model.name
128
+ `There was an error converting the ${model.name
124
129
  } schema. Model received looks like: \n\n${JSON.stringify(
125
130
  model
126
131
  )}. The convereted schema looks like \n\n${JSON.stringify(
@@ -179,18 +184,30 @@ class SchemaHandler {
179
184
  }
180
185
  );
181
186
 
182
- this.logger.verbose(
183
- `dereferenced model: ${JSON.stringify(dereferencedSchema)}`
184
- );
187
+ if (this.shouldConvert) {
188
+ this.logger.verbose(
189
+ `dereferenced model: ${JSON.stringify(dereferencedSchema)}`
190
+ );
191
+
192
+ this.logger.verbose(`converting model: ${name}`);
193
+ const convertedSchemas = SchemaConvertor.convert(
194
+ dereferencedSchema,
195
+ name
196
+ );
185
197
 
186
- this.logger.verbose(`converting model: ${name}`);
187
- const convertedSchemas = SchemaConvertor.convert(dereferencedSchema, name);
198
+ this.logger.verbose(
199
+ `converted schemas: ${JSON.stringify(convertedSchemas)}`
200
+ );
201
+ return convertedSchemas;
202
+ }
188
203
 
189
204
  this.logger.verbose(
190
- `converted schemas: ${JSON.stringify(convertedSchemas)}`
205
+ `dereferenced model: ${JSON.stringify({
206
+ schemas: { [name]: dereferencedSchema },
207
+ })}`
191
208
  );
192
209
 
193
- return convertedSchemas;
210
+ return { schemas: { [name]: dereferencedSchema } };
194
211
  }
195
212
 
196
213
  async __dereferenceSchema(schema) {
@@ -292,10 +309,8 @@ class SchemaHandler {
292
309
  __HTTPError(error, model) {
293
310
  if (error.message.includes("HTTP ERROR")) {
294
311
  throw new Error(
295
- `There was an error dereferencing ${
296
- model.name
297
- } schema. \n\n dereferencing message: ${
298
- error.message
312
+ `There was an error dereferencing ${model.name
313
+ } schema. \n\n dereferencing message: ${error.message
299
314
  } \n\n Model received: ${JSON.stringify(model)}`
300
315
  );
301
316
  }