@@ -4,11 +4,15 @@ defmodule Apix.Schema.Extensions.TypeGraph do
44 alias Apix.Schema.Ast
55 alias Apix.Schema.Context
66
7+ alias Apix.Schema.Warning
8+
79 alias Apix.Schema.Extensions.TypeGraph.Graph
810
911 alias Apix.Schema.Extensions.TypeGraph.Errors.FullyRecursiveAstError
1012 alias Apix.Schema.Extensions.TypeGraph.Errors.UndefinedReferenceAstError
1113
14+ alias Apix.Schema.Extensions.TypeGraph.Warnings.ReducibleAstWarning
15+
1216 @ manifest % Extension {
1317 module: __MODULE__
1418 }
@@ -367,6 +371,11 @@ defmodule Apix.Schema.Extensions.TypeGraph do
367371 """
368372 @ spec validate! ( ) :: :ok | no_return ( )
369373 def validate! do
374+ validate_undefined_reference! ( )
375+ validate_fully_recursive! ( )
376+ end
377+
378+ defp validate_undefined_reference! do
370379 Graph . vertices ( )
371380 |> Enum . each ( fn hash ->
372381 { ^ hash , context_or_ast } = Graph . vertex ( hash )
@@ -375,7 +384,9 @@ defmodule Apix.Schema.Extensions.TypeGraph do
375384 raise UndefinedReferenceAstError , context_or_ast
376385 end
377386 end )
387+ end
378388
389+ defp validate_fully_recursive! do
379390 Graph . cyclic_strong_components_by ( & ( & 1 == :references ) )
380391 |> Enum . each ( fn [ hash | _ ] = component ->
381392 component
@@ -409,6 +420,17 @@ defmodule Apix.Schema.Extensions.TypeGraph do
409420 end )
410421 end
411422
423+ defp validate_reducible! ( context ) do
424+ ast = context . ast
425+ reduced_ast = Context . normalize_ast! ( context )
426+
427+ unless Ast . equals? ( ast , reduced_ast ) do
428+ [ ast: ast , reduced_ast: reduced_ast ]
429+ |> ReducibleAstWarning . exception ( )
430+ |> Warning . print ( )
431+ end
432+ end
433+
412434 @ doc group: "Internal"
413435 @ doc """
414436 Builds the sub/super-type relations in the graph.
@@ -592,6 +614,7 @@ defmodule Apix.Schema.Extensions.TypeGraph do
592614 @ impl Extension
593615 def validate_ast! ( context ) do
594616 track! ( context )
617+ validate_reducible! ( context )
595618 on_compilation! ( )
596619
597620 context
0 commit comments