diff --git a/compiler/src/steps/validate-model.ts b/compiler/src/steps/validate-model.ts index d963c57b6a..29b1b89016 100644 --- a/compiler/src/steps/validate-model.ts +++ b/compiler/src/steps/validate-model.ts @@ -45,14 +45,10 @@ const privateNamespaces = ['_internal', 'profiling'] * Any inconsistency is logged as an error. * * Missing validations: - * - verify uniqueness of property names in the inheritance chain * - verify that request parents don't define properties (would they be path/request/body properties?) * - verify that unions can be distinguished in a JSON stream (otherwise they should be inheritance trees) */ export default async function validateModel (apiModel: model.Model, restSpec: Map, errors: ValidationErrors): Promise { - // Fail hard if the FAIL_HARD env var is defined - const failHard = process.env.FAIL_HARD != null - const initialTypeCount = apiModel.types.length // Returns the fully-qualified name of a type name @@ -87,13 +83,20 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma function modelError (msg: string): void { const fullMsg = (context.length === 0) ? msg : context.join(' / ') + ' - ' + msg + let ignored = false if (currentEndpoint != null) { - errors.addEndpointError(currentEndpoint, currentPart, fullMsg) + ignored = errors.addEndpointError(currentEndpoint, currentPart, fullMsg) + if (!ignored) { + console.error(currentEndpoint, currentPart, fullMsg) + } } else { errors.addGeneralError(fullMsg) + console.error(fullMsg) } - errorCount++ + if (!ignored) { + errorCount++ + } } // ----- Type definition management @@ -206,8 +209,8 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma const danglingTypesCount = initialTypeCount - apiModel.types.length console.info(`Model validation: ${typesSeen.size} types visited, ${danglingTypesCount} dangling types.`) - if (errorCount > 0 && failHard) { - throw new Error('Model is inconsistent. Check logs for details') + if (errorCount > 0) { + throw new Error('Model is inconsistent.') } return apiModel diff --git a/compiler/src/validation-errors.ts b/compiler/src/validation-errors.ts index 5260775f3e..a89c61a8f5 100644 --- a/compiler/src/validation-errors.ts +++ b/compiler/src/validation-errors.ts @@ -38,9 +38,9 @@ export class ValidationErrors { } /** Add some error information relative to an endpoint's request or response */ - addEndpointError (endpoint: string, part: 'request' | 'response', message: string): void { + addEndpointError (endpoint: string, part: 'request' | 'response', message: string): boolean { if (IGNORED_ERRORS.includes(message)) { - return + return true } let error = this.endpointErrors[endpoint] @@ -50,6 +50,7 @@ export class ValidationErrors { } error[part].push(message) + return false } /** Add a general error, unrelated to an endpoint */