Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Print validation results even when --errors flag is passed #2634

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions packages/http-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,12 @@ export const createServer = (operations: IHttpOperation[], opts: IPrismHttpServe

if (inputOutputValidationErrors.length > 0) {
addViolationHeader(reply, inputOutputValidationErrors);

const errorViolations = outputValidationErrors.filter(
v => v.severity === DiagnosticSeverity[DiagnosticSeverity.Error]
);

if (opts.config.errors && errorViolations.length > 0) {
return IOE.left(
ProblemJsonError.fromTemplate(
VIOLATIONS,
'Your request/response is not valid and the --errors flag is set, so Prism is generating this error for you.',
{ validation: errorViolations }
)
);
}
}

const errorViolations = outputValidationErrors.filter(
v => v.severity === DiagnosticSeverity[DiagnosticSeverity.Error]
);

inputOutputValidationErrors.forEach(validation => {
const message = `Violation: ${validation.location.join('.') || ''} ${validation.message}`;
if (validation.severity === DiagnosticSeverity[DiagnosticSeverity.Error]) {
Expand All @@ -148,6 +138,16 @@ export const createServer = (operations: IHttpOperation[], opts: IPrismHttpServe
}
});

if (opts.config.errors && errorViolations.length > 0) {
return IOE.left(
ProblemJsonError.fromTemplate(
VIOLATIONS,
'Your request/response is not valid and the --errors flag is set, so Prism is generating this error for you.',
{ validation: errorViolations }
)
);
}

return IOE.fromEither(
E.tryCatch(() => {
if (output.headers) Object.entries(output.headers).forEach(([name, value]) => reply.setHeader(name, value));
Expand Down