serverless-openapi-documenter 0.0.124-beta.1 → 0.0.124

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,9 +12,7 @@
12
12
  </a>
13
13
  </p>
14
14
 
15
- This will generate an OpenAPI V3 (up to v3.0.4) 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
- If you are using the beta of 0.0.115, it will now try and create [OpenAPI V3.1 (3.1.x)](https://spec.openapis.org/oas/v3.1.0.html) Document for you, should you run the command `serverless openapi generate -o openapi.json -f json -a 3.1.1 -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.
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.
18
16
 
19
17
  Originally based off of: https://github.com/temando/serverless-openapi-documentation
20
18
 
@@ -1111,7 +1109,7 @@ module.exports = {
1111
1109
  dereference: {
1112
1110
  circular: false, // Don't allow circular $refs
1113
1111
  excludedPathMatcher: (
1114
- path, // Skip dereferencing content under any 'example' key
1112
+ path // Skip dereferencing content under any 'example' key
1115
1113
  ) => path.includes("/example/"),
1116
1114
  },
1117
1115
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serverless-openapi-documenter",
3
- "version": "0.0.124-beta.1",
3
+ "version": "0.0.124",
4
4
  "description": "Generate OpenAPI v3 documentation and Postman Collections from your Serverless Config",
5
5
  "main": "index.js",
6
6
  "keywords": [
@@ -49,8 +49,8 @@
49
49
  "license": "MIT",
50
50
  "dependencies": {
51
51
  "@apidevtools/json-schema-ref-parser": "^9.1.0",
52
+ "@redocly/openapi-core": "^1.2.0",
52
53
  "@usebruno/converters": "^0.16.0",
53
- "@redocly/openapi-core": "^1.34.5",
54
54
  "chalk": "^4.1.2",
55
55
  "js-yaml": "^4.1.1",
56
56
  "json-schema-for-openapi": "^0.5.0",
@@ -713,7 +713,6 @@ class DefinitionGenerator {
713
713
  }
714
714
 
715
715
  if (contentKey) {
716
-
717
716
  const obj = {};
718
717
  let schema;
719
718
  if (mediaTypeDocumentation.content) {
@@ -734,7 +733,9 @@ class DefinitionGenerator {
734
733
  }
735
734
 
736
735
  if (mediaTypeDocumentation.examples) {
737
- obj.example = mediaTypeDocumentation.examples;
736
+ obj.examples = this.createExamples(
737
+ mediaTypeDocumentation.examples
738
+ );
738
739
  }
739
740
 
740
741
  schema = mediaTypeDocumentation.schema;
@@ -16,12 +16,6 @@ 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
-
25
19
  this.modelReferences = {};
26
20
 
27
21
  this.__standardiseModels();
@@ -59,7 +53,7 @@ class SchemaHandler {
59
53
  model.schema = null;
60
54
  model.schemas = {};
61
55
  for (const key in model.content) {
62
- Object.assign(model.schemas, { [key]: { schema: model.content[key].schema } });
56
+ Object.assign(model.schemas, {[key]: {schema: model.content[key].schema}});
63
57
  }
64
58
  // model.schema = model.content[contentType].schema;
65
59
  }
@@ -88,7 +82,7 @@ class SchemaHandler {
88
82
  for (const model of this.models) {
89
83
  const modelName = model.name;
90
84
  const schemas = []
91
- if (model.schema) {
85
+ if (model.schema){
92
86
  // const modelSchema = model.schema;
93
87
  schemas.push(model.schema)
94
88
  } else {
@@ -125,7 +119,8 @@ class SchemaHandler {
125
119
  }
126
120
  } else {
127
121
  throw new Error(
128
- `There was an error converting the ${model.name
122
+ `There was an error converting the ${
123
+ model.name
129
124
  } schema. Model received looks like: \n\n${JSON.stringify(
130
125
  model
131
126
  )}. The convereted schema looks like \n\n${JSON.stringify(
@@ -184,30 +179,18 @@ class SchemaHandler {
184
179
  }
185
180
  );
186
181
 
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
- );
182
+ this.logger.verbose(
183
+ `dereferenced model: ${JSON.stringify(dereferencedSchema)}`
184
+ );
197
185
 
198
- this.logger.verbose(
199
- `converted schemas: ${JSON.stringify(convertedSchemas)}`
200
- );
201
- return convertedSchemas;
202
- }
186
+ this.logger.verbose(`converting model: ${name}`);
187
+ const convertedSchemas = SchemaConvertor.convert(dereferencedSchema, name);
203
188
 
204
189
  this.logger.verbose(
205
- `dereferenced model: ${JSON.stringify({
206
- schemas: { [name]: dereferencedSchema },
207
- })}`
190
+ `converted schemas: ${JSON.stringify(convertedSchemas)}`
208
191
  );
209
192
 
210
- return { schemas: { [name]: dereferencedSchema } };
193
+ return convertedSchemas;
211
194
  }
212
195
 
213
196
  async __dereferenceSchema(schema) {
@@ -309,8 +292,10 @@ class SchemaHandler {
309
292
  __HTTPError(error, model) {
310
293
  if (error.message.includes("HTTP ERROR")) {
311
294
  throw new Error(
312
- `There was an error dereferencing ${model.name
313
- } schema. \n\n dereferencing message: ${error.message
295
+ `There was an error dereferencing ${
296
+ model.name
297
+ } schema. \n\n dereferencing message: ${
298
+ error.message
314
299
  } \n\n Model received: ${JSON.stringify(model)}`
315
300
  );
316
301
  }