ogma-language-jsonspec 1.6.0 → 1.7.0
raw patch · 3 files changed
+74/−38 lines, 3 filesdep ~aesondep ~ogma-specdep ~text
Dependency ranges changed: aeson, ogma-spec, text
Files
- CHANGELOG.md +7/−0
- ogma-language-jsonspec.cabal +5/−5
- src/Language/JSONSpec/Parser.hs +62/−33
CHANGELOG.md view
@@ -1,5 +1,12 @@ # Revision history for ogma-language-jsonspec +## [1.7.0] - 2025-03-21++* Version bump 1.7.0 (#269).+* Bump upper version constraint on aeson, text (#225).+* Remove extraneous EOL character (#224).+* Extend JSONSpec with additional data associated with results (#219).+ ## [1.6.0] - 2025-01-21 * Version bump 1.6.0 (#208).
ogma-language-jsonspec.cabal view
@@ -15,7 +15,7 @@ -- ANY OTHER APPLICATIONS RESULTING FROM USE OF THE SUBJECT SOFTWARE. FURTHER, -- GOVERNMENT AGENCY DISCLAIMS ALL WARRANTIES AND LIABILITIES REGARDING -- THIRD-PARTY SOFTWARE, IF PRESENT IN THE ORIGINAL SOFTWARE, AND DISTRIBUTES--- IT "AS IS." +-- IT "AS IS." -- -- Waiver and Indemnity: RECIPIENT AGREES TO WAIVE ANY AND ALL CLAIMS AGAINST -- THE UNITED STATES GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS, AS WELL AS@@ -32,7 +32,7 @@ build-type: Simple name: ogma-language-jsonspec-version: 1.6.0+version: 1.7.0 homepage: https://github.com/nasa/ogma bug-reports: https://github.com/nasa/ogma/issues license: OtherLicense@@ -70,14 +70,14 @@ build-depends: base >= 4.11.0.0 && < 5- , aeson >= 2.0.0.0 && < 2.2+ , aeson >= 2.0.0.0 && < 2.3 , jsonpath >= 0.3 && < 0.4- , text >= 1.2.3.1 && < 2.1+ , text >= 1.2.3.1 && < 2.2 , megaparsec >= 8.0.0 && < 9.10 , mtl >= 2.2.2 && < 2.4 , bytestring >= 0.10.8.2 && < 0.13 - , ogma-spec >= 1.6.0 && < 1.7+ , ogma-spec >= 1.7.0 && < 1.8 hs-source-dirs: src
src/Language/JSONSpec/Parser.hs view
@@ -53,32 +53,36 @@ import Data.OgmaSpec data JSONFormat = JSONFormat- { specInternalVars :: Maybe String- , specInternalVarId :: String- , specInternalVarExpr :: String- , specInternalVarType :: Maybe String- , specExternalVars :: Maybe String- , specExternalVarId :: String- , specExternalVarType :: Maybe String- , specRequirements :: String- , specRequirementId :: String- , specRequirementDesc :: Maybe String- , specRequirementExpr :: String+ { specInternalVars :: Maybe String+ , specInternalVarId :: String+ , specInternalVarExpr :: String+ , specInternalVarType :: Maybe String+ , specExternalVars :: Maybe String+ , specExternalVarId :: String+ , specExternalVarType :: Maybe String+ , specRequirements :: String+ , specRequirementId :: String+ , specRequirementDesc :: Maybe String+ , specRequirementExpr :: String+ , specRequirementResultType :: Maybe String+ , specRequirementResultExpr :: Maybe String } deriving (Read) data JSONFormatInternal = JSONFormatInternal- { jfiInternalVars :: Maybe [JSONPathElement]- , jfiInternalVarId :: [JSONPathElement]- , jfiInternalVarExpr :: [JSONPathElement]- , jfiInternalVarType :: Maybe [JSONPathElement]- , jfiExternalVars :: Maybe [JSONPathElement]- , jfiExternalVarId :: [JSONPathElement]- , jfiExternalVarType :: Maybe [JSONPathElement]- , jfiRequirements :: [JSONPathElement]- , jfiRequirementId :: [JSONPathElement]- , jfiRequirementDesc :: Maybe [JSONPathElement]- , jfiRequirementExpr :: [JSONPathElement]+ { jfiInternalVars :: Maybe [JSONPathElement]+ , jfiInternalVarId :: [JSONPathElement]+ , jfiInternalVarExpr :: [JSONPathElement]+ , jfiInternalVarType :: Maybe [JSONPathElement]+ , jfiExternalVars :: Maybe [JSONPathElement]+ , jfiExternalVarId :: [JSONPathElement]+ , jfiExternalVarType :: Maybe [JSONPathElement]+ , jfiRequirements :: [JSONPathElement]+ , jfiRequirementId :: [JSONPathElement]+ , jfiRequirementDesc :: Maybe [JSONPathElement]+ , jfiRequirementExpr :: [JSONPathElement]+ , jfiRequirementResultType :: Maybe [JSONPathElement]+ , jfiRequirementResultExpr :: Maybe [JSONPathElement] } parseJSONFormat :: JSONFormat -> Either String JSONFormatInternal@@ -94,18 +98,22 @@ jfi10 <- showErrors $ parseJSONPath $ pack $ specRequirementId jsonFormat jfi11 <- showErrorsM $ fmap (parseJSONPath . pack) $ specRequirementDesc jsonFormat jfi12 <- showErrors $ parseJSONPath $ pack $ specRequirementExpr jsonFormat+ jfi13 <- showErrorsM $ fmap (parseJSONPath . pack) $ specRequirementResultType jsonFormat+ jfi14 <- showErrorsM $ fmap (parseJSONPath . pack) $ specRequirementResultExpr jsonFormat return $ JSONFormatInternal- { jfiInternalVars = jfi2- , jfiInternalVarId = jfi3- , jfiInternalVarExpr = jfi4- , jfiInternalVarType = jfi5- , jfiExternalVars = jfi6- , jfiExternalVarId = jfi7- , jfiExternalVarType = jfi8- , jfiRequirements = jfi9- , jfiRequirementId = jfi10- , jfiRequirementDesc = jfi11- , jfiRequirementExpr = jfi12+ { jfiInternalVars = jfi2+ , jfiInternalVarId = jfi3+ , jfiInternalVarExpr = jfi4+ , jfiInternalVarType = jfi5+ , jfiExternalVars = jfi6+ , jfiExternalVarId = jfi7+ , jfiExternalVarType = jfi8+ , jfiRequirements = jfi9+ , jfiRequirementId = jfi10+ , jfiRequirementDesc = jfi11+ , jfiRequirementExpr = jfi12+ , jfiRequirementResultType = jfi13+ , jfiRequirementResultExpr = jfi14 } parseJSONSpec :: (String -> IO (Either String a)) -> JSONFormat -> Value -> IO (Either String (Spec a))@@ -168,10 +176,26 @@ let msg = "Requirement description" reqDesc <- except $ maybe (Right "") (\e -> valueToString msg =<< (listToEither msg (executeJSONPath e value))) (jfiRequirementDesc jsonFormatInternal) + let msg = "Requirement result type"+ ty :: Maybe (Either String String)+ ty = (\e -> valueToString msg =<< (listToEither msg (executeJSONPath e value))) <$> (jfiRequirementResultType jsonFormatInternal)+ reqResType <- except $ maybeEither ty++ let msg = "Requirement result expression"+ resultExpr :: Maybe (Either String String)+ resultExpr = (\e -> valueToString msg =<< (listToEither msg (executeJSONPath e value))) <$> (jfiRequirementResultExpr jsonFormatInternal)++ reqResExpr <- except $ maybeEither resultExpr+ reqResExpr' <- ExceptT $ case reqResExpr of+ Nothing -> return $ Right Nothing+ Just x -> fmap Just <$> parseExpr x+ return $ Requirement { requirementName = reqId , requirementExpr = reqExpr' , requirementDescription = reqDesc+ , requirementResultType = reqResType+ , requirementResultExpr = reqResExpr' } requirements <- mapM requirementDef values@@ -203,3 +227,8 @@ -- | Wrap an 'Either' value in an @ExceptT m@ monad. except :: Monad m => Either e a -> ExceptT e m a except = ExceptT . return++-- | Swap the order in a Maybe and an Either monad.+maybeEither :: Maybe (Either a b) -> Either a (Maybe b)+maybeEither Nothing = Right Nothing+maybeEither (Just e) = fmap Just e