@@ -45,14 +45,10 @@ const privateNamespaces = ['_internal', 'profiling']
4545 * Any inconsistency is logged as an error.
4646 *
4747 * Missing validations:
48- * - verify uniqueness of property names in the inheritance chain
4948 * - verify that request parents don't define properties (would they be path/request/body properties?)
5049 * - verify that unions can be distinguished in a JSON stream (otherwise they should be inheritance trees)
5150 */
5251export default async function validateModel ( apiModel : model . Model , restSpec : Map < string , JsonSpec > , errors : ValidationErrors ) : Promise < model . Model > {
53- // Fail hard if the FAIL_HARD env var is defined
54- const failHard = process . env . FAIL_HARD != null
55-
5652 const initialTypeCount = apiModel . types . length
5753
5854 // Returns the fully-qualified name of a type name
@@ -87,13 +83,20 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma
8783 function modelError ( msg : string ) : void {
8884 const fullMsg = ( context . length === 0 ) ? msg : context . join ( ' / ' ) + ' - ' + msg
8985
86+ let ignored = false
9087 if ( currentEndpoint != null ) {
91- errors . addEndpointError ( currentEndpoint , currentPart , fullMsg )
88+ ignored = errors . addEndpointError ( currentEndpoint , currentPart , fullMsg )
89+ if ( ! ignored ) {
90+ console . error ( currentEndpoint , currentPart , fullMsg )
91+ }
9292 } else {
9393 errors . addGeneralError ( fullMsg )
94+ console . error ( fullMsg )
9495 }
9596
96- errorCount ++
97+ if ( ! ignored ) {
98+ errorCount ++
99+ }
97100 }
98101
99102 // ----- Type definition management
@@ -206,8 +209,8 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma
206209 const danglingTypesCount = initialTypeCount - apiModel . types . length
207210 console . info ( `Model validation: ${ typesSeen . size } types visited, ${ danglingTypesCount } dangling types.` )
208211
209- if ( errorCount > 0 && failHard ) {
210- throw new Error ( 'Model is inconsistent. Check logs for details ' )
212+ if ( errorCount > 0 ) {
213+ throw new Error ( 'Model is inconsistent.' )
211214 }
212215
213216 return apiModel
0 commit comments