@@ -3,6 +3,7 @@
3module OpenAPI.Checker.Subtree
3module OpenAPI.Checker.Subtree
4 ( Steppable (..)
4 ( Steppable (..)
5 , Step (..)
5 , Step (..)
@@ -69,7 +70,15 @@ class
69 -- | How to get from an @a@ node to a @b@ node
70 -- | How to get from an @a@ node to a @b@ node
70 data Step a b :: Type
71 data Step a b :: Type
75+instance Steppable TraceRoot OpenApi where
76+ data Step TraceRoot OpenApi
79+ deriving stock (Eq, Ord, Show)
72−type Trace = Paths Step OpenApi
81+type Trace = Paths Step TraceRoot
74type Traced' a b = Env (Trace a) b
83type Traced' a b = Env (Trace a) b
@@ -117,16 +126,15 @@ type CompatFormula' q f r = Compose CompatM (FormulaF q f r)
118type SemanticCompatFormula = CompatFormula' Behave AnIssue 'APILevel
127type SemanticCompatFormula = CompatFormula' Behave AnIssue 'APILevel
120−type StructuralCompatFormula = CompatFormula' UnitQuiver Proxy ()
129+type StructuralCompatFormula = CompatFormula' VoidQuiver Proxy ()
122−data UnitQuiver a b where
131+data VoidQuiver a b where
123− UnitQuiver :: UnitQuiver () ()
125−deriving stock instance Eq (UnitQuiver a b)
133+deriving stock instance Eq (VoidQuiver a b)
127−deriving stock instance Ord (UnitQuiver a b)
135+deriving stock instance Ord (VoidQuiver a b)
129−deriving stock instance Show (UnitQuiver a b)
137+deriving stock instance Show (VoidQuiver a b)
131class (Typeable t, Issuable (SubtreeLevel t)) => Subtree (t :: Type) where
139class (Typeable t, Issuable (SubtreeLevel t)) => Subtree (t :: Type) where
132 type CheckEnv t :: [Type]
140 type CheckEnv t :: [Type]
@@ -155,7 +163,7 @@ checkCompatibility
155 -> Behavior (SubtreeLevel t)
163 -> Behavior (SubtreeLevel t)
156 -> ProdCons (Traced t)
164 -> ProdCons (Traced t)
157 -> SemanticCompatFormula ()
165 -> SemanticCompatFormula ()
158−checkCompatibility e bhv = memo SemanticMemoKey $ \pc ->
166+checkCompatibility e bhv = memo bhv SemanticMemoKey $ \pc ->
159 case runCompatFormula $ checkSubstructure e pc of
167 case runCompatFormula $ checkSubstructure e pc of
160 Left _ -> checkSemanticCompatibility e bhv pc
168 Left _ -> checkSemanticCompatibility e bhv pc
161 Right () -> pure ()
169 Right () -> pure ()
@@ -165,7 +173,7 @@ checkSubstructure
165 => HList xs
173 => HList xs
166 -> ProdCons (Traced t)
174 -> ProdCons (Traced t)
167 -> StructuralCompatFormula ()
175 -> StructuralCompatFormula ()
168−checkSubstructure e = memo StructuralMemoKey $ checkStructuralCompatibility e
176+checkSubstructure e = memo Root StructuralMemoKey $ checkStructuralCompatibility e
170structuralMaybe
178structuralMaybe
171 :: (Subtree a, HasAll (CheckEnv a) xs)
179 :: (Subtree a, HasAll (CheckEnv a) xs)
@@ -260,7 +268,7 @@ issueAt :: Issuable l => Paths q r l -> Issue l -> CompatFormula' q AnIssue r a
260issueAt xs issue = Compose $ pure $ anError $ AnItem xs $ AnIssue issue
268issueAt xs issue = Compose $ pure $ anError $ AnItem xs $ AnIssue issue
262structuralIssue :: StructuralCompatFormula a
270structuralIssue :: StructuralCompatFormula a
263−structuralIssue = Compose $ pure $ anError $ AnItem (step UnitQuiver) Proxy
271+structuralIssue = Compose $ pure $ anError $ AnItem Root Proxy
266 :: Issuable l
274 :: Issuable l
@@ -283,11 +291,17 @@ fixpointKnot =
286− :: (Typeable (r :: k), Typeable q, Typeable f, Typeable k, Typeable a)
294+ :: (Typeable (l :: k), Typeable q, Typeable f, Typeable k, Typeable a)
287− => MemoKey
296+ -> MemoKey
288 -> (ProdCons (Traced a) -> CompatFormula' q f r ())
297 -> (ProdCons (Traced a) -> CompatFormula' q f r ())
289 -> (ProdCons (Traced a) -> CompatFormula' q f r ())
298 -> (ProdCons (Traced a) -> CompatFormula' q f r ())
299+memo bhv k f pc = Compose $ do
290−memo k f pc = Compose $ memoWithKnot fixpointKnot (getCompose $ f pc) (k, ask <$> pc)
300+ formula' <- memoWithKnot fixpointKnot (do
301+ formula <- getCompose $ f pc
302+ pure $ mapErrors (P.filter bhv) formula
304+ pure $ mapErrors (P.embed bhv) formula'
292data MemoKey = SemanticMemoKey | StructuralMemoKey
306data MemoKey = SemanticMemoKey | StructuralMemoKey
293 deriving stock (Eq, Ord)
307 deriving stock (Eq, Ord)