Skip to content

Commit 0b43bbb

Browse files
committed
switch to Description and output redocly errors correctly
1 parent 1dc2851 commit 0b43bbb

File tree

1 file changed

+32
-33
lines changed

1 file changed

+32
-33
lines changed

src/openAPIGenerator.js

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class OpenAPIGenerator {
3030
commands: {
3131
generate: {
3232
lifecycleEvents: ["serverless"],
33-
usage: "Generate OpenAPI v3 Documentation",
33+
usage: "Generate OpenAPI v3 Description",
3434
options: {
3535
output: {
3636
usage: "Output file location [default: openapi.json|yml]",
@@ -60,7 +60,7 @@ class OpenAPIGenerator {
6060
},
6161
validationWarn: {
6262
usage:
63-
"Only warn about validation errors of the OpenAPI document, write the file if parsing is successful [default: false]",
63+
"Only warn about validation errors of the OpenAPI Description, write the file if parsing is successful [default: false]",
6464
shortcut: "w",
6565
type: "boolean",
6666
},
@@ -144,7 +144,7 @@ class OpenAPIGenerator {
144144
}
145145

146146
async generate() {
147-
this.log(chalk.bold.underline("OpenAPI v3 Document Generation"));
147+
this.log(chalk.bold.underline("OpenAPI v3 Description Generation"));
148148
this.processCliInput();
149149

150150
const validOpenAPI = await this.generationAndValidation().catch((err) => {
@@ -168,12 +168,12 @@ class OpenAPIGenerator {
168168
try {
169169
fs.writeFileSync(this.config.file, output);
170170
this.log(
171-
"OpenAPI v3 Documentation Successfully Written",
171+
"OpenAPI v3 Description Successfully Written",
172172
this.logTypes.SUCCESS
173173
);
174174
} catch (err) {
175175
this.log(
176-
`ERROR: An error was thrown whilst writing the openAPI Documentation`,
176+
`ERROR: An error was thrown whilst writing the OpenAPI Description`,
177177
this.logTypes.ERROR
178178
);
179179
throw new this.serverless.classes.Error(err);
@@ -183,33 +183,37 @@ class OpenAPIGenerator {
183183
async generationAndValidation() {
184184
const generator = new DefinitionGenerator(this.serverless);
185185

186-
this.log(`Generating OpenAPI documentation`, this.logTypes.NOTICE);
186+
this.log(`Generating OpenAPI Description`, this.logTypes.NOTICE);
187187
await generator.parse().catch((err) => {
188188
this.log(
189-
`ERROR: An error was thrown generating the OpenAPI v3 documentation`,
189+
`ERROR: An error was thrown generating the OpenAPI v3 Description`,
190190
this.logTypes.ERROR
191191
);
192192
throw new this.serverless.classes.Error(err);
193193
});
194194

195-
this.log(
196-
`Validating generated OpenAPI documentation`,
197-
this.logTypes.NOTICE
198-
);
195+
this.log(`Validating generated OpenAPI Description`, this.logTypes.NOTICE);
199196

200197
await generator.validate().catch((err) => {
201198
this.log(
202-
`ERROR: An error was thrown validating the OpenAPI v3 documentation`,
199+
`ERROR: An error was thrown validating the OpenAPI v3 Description`,
203200
this.logTypes.ERROR
204201
);
202+
205203
this.validationErrorDetails(err);
204+
206205
if (this.config.validationWarn === false) {
207-
throw new this.serverless.classes.Error(err);
206+
let message = "Error validating OpenAPI Description:\r\n";
207+
for (const errorMessage of err) {
208+
message += `${errorMessage.message}\r\n`;
209+
}
210+
211+
throw new this.serverless.classes.Error(message);
208212
}
209213
});
210214

211215
this.log(
212-
"OpenAPI v3 Documentation Successfully Generated",
216+
"OpenAPI v3 Description Successfully Generated",
213217
this.logTypes.SUCCESS
214218
);
215219

@@ -305,27 +309,22 @@ class OpenAPIGenerator {
305309
this.log(
306310
`${chalk.bold.yellow(
307311
"[VALIDATION]"
308-
)} Failed to validate OpenAPI document: \n`,
309-
this.logTypes.ERROR
310-
);
311-
this.log(
312-
`${chalk.bold.yellow("Context:")} ${JSON.stringify(
313-
validationError.options.context[
314-
validationError.options.context.length - 1
315-
],
316-
null,
317-
2
318-
)}\n`,
319-
this.logTypes.ERROR
320-
);
321-
this.log(
322-
`${chalk.bold.yellow("Error Message:")} ${JSON.stringify(
323-
validationError.message,
324-
null,
325-
2
326-
)}\n`,
312+
)} Validation errors found in OpenAPI Description: \n`,
327313
this.logTypes.ERROR
328314
);
315+
316+
for (const error of validationError) {
317+
this.log(
318+
`${chalk.bold.yellow("Message:")} ${error.message}`,
319+
this.logTypes.ERROR
320+
);
321+
for (const location of error.location) {
322+
this.log(
323+
`${chalk.bold.yellow("found at location:")} ${location.pointer}`,
324+
this.logTypes.ERROR
325+
);
326+
}
327+
}
329328
}
330329
}
331330

0 commit comments

Comments
 (0)