Skip to content

Commit

Permalink
Merge branch 'master' into openapi-optional-metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
WillSewell authored Jan 8, 2021
2 parents 1c64c35 + 38ddcb3 commit 84c06c2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dhall-nixpkgs/dhall-nixpkgs.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Build-Type: Simple
Executable dhall-to-nixpkgs
Main-Is: Main.hs
Build-Depends: base >= 4.11 && < 5
, aeson >= 1.0.0.0 && < 1.5
, aeson >= 1.0.0.0 && < 1.6
, data-fix
, dhall >= 1.32.0 && < 1.38
, foldl < 1.5
Expand Down
6 changes: 5 additions & 1 deletion dhall-openapi/openapi-to-dhall/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,15 @@ getAutoscaling ModelName{..}
| otherwise =
Nothing

isK8sNative :: ModelName -> Bool
isK8sNative ModelName{..} = Text.isPrefixOf "io.k8s." unModelName

preferStableResource :: DuplicateHandler
preferStableResource (_, names) = do
let issue112 = Ord.comparing getAutoscaling
let k8sOverCrd = Ord.comparing isK8sNative
let defaultComparison = Ord.comparing getVersion
let comparison = issue112 <> defaultComparison
let comparison = issue112 <> k8sOverCrd <> defaultComparison
return (List.maximumBy comparison names)

skipDuplicatesHandler :: DuplicateHandler
Expand Down
2 changes: 1 addition & 1 deletion dhall-openapi/src/Dhall/Kubernetes/Convert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ getImportsMap prefixMap duplicateNameHandler objectNames folder toInclude
namespacedToSimple
= Data.Map.fromList $ mapMaybe selectObject $ Data.Map.toList $ groupByObjectName objectNames

-- | Given a list of fully namespaced bjects, it will group them by the
-- | Given a list of fully namespaced objects, it will group them by the
-- object name
groupByObjectName :: [ModelName] -> Data.Map.Map Text [ModelName]
groupByObjectName modelNames = Data.Map.unionsWith (<>)
Expand Down
14 changes: 9 additions & 5 deletions dhall/ghc-src/Dhall/Import/HTTP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Control.Monad.Trans.State.Strict (StateT)
import Data.ByteString (ByteString)
import Data.CaseInsensitive (CI)
import Data.Dynamic (toDyn)
import Data.List.NonEmpty (NonEmpty(..))
import Dhall.Core
( Import (..)
, ImportHashed (..)
Expand All @@ -29,7 +30,6 @@ import Network.HTTP.Client

import qualified Control.Exception
import qualified Control.Monad.Trans.State.Strict as State
import qualified Data.List.NonEmpty as NonEmpty
import qualified Data.Text as Text
import qualified Data.Text.Encoding
import qualified Data.Text.Lazy
Expand Down Expand Up @@ -266,11 +266,15 @@ fetchFromHttpUrl childURL mheaders = do

Status {..} <- State.get

let Chained parentImport = NonEmpty.head _stack
case _stack of
-- We ignore the first import in the stack since that is the same import
-- as the `childUrl`
_ :| Chained parentImport : _ -> do
let parentImportType = importType (importHashed parentImport)

let parentImportType = importType (importHashed parentImport)

corsCompliant parentImportType childURL (HTTP.responseHeaders response)
corsCompliant parentImportType childURL (HTTP.responseHeaders response)
_ -> do
return ()

let bytes = HTTP.responseBody response

Expand Down
7 changes: 4 additions & 3 deletions dhall/src/Dhall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,15 @@ instance (Pretty s, Pretty a, Typeable s, Typeable a) => Show (InvalidDecoder s
show InvalidDecoder { .. } =
_ERROR <> ": Invalid Dhall.Decoder \n\
\ \n\
\Every Decoder must provide an extract function that succeeds if an expression \n\
\matches the expected type. You provided a Decoder that disobeys this contract \n\
\Every Decoder must provide an extract function that does not fail with a type \n\
\error if an expression matches the expected type. You provided a Decoder that \n\
\disobeys this contract \n\
\ \n\
\The Decoder provided has the expected dhall type: \n\
\ \n\
\" <> show txt0 <> "\n\
\ \n\
\and it couldn't extract a value from the well-typed expression: \n\
\and it threw a type error during extraction from the well-typed expression: \n\
\ \n\
\" <> show txt1 <> "\n\
\ \n"
Expand Down
7 changes: 4 additions & 3 deletions dhall/tests/Dhall/Test/Dhall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ shouldShowDetailedTypeError = testCase "detailed TypeError" $ do
let expectedMsg =
"\ESC[1;31mError\ESC[0m: Invalid Dhall.Decoder \n\
\ \n\
\Every Decoder must provide an extract function that succeeds if an expression \n\
\matches the expected type. You provided a Decoder that disobeys this contract \n\
\Every Decoder must provide an extract function that does not fail with a type \n\
\error if an expression matches the expected type. You provided a Decoder that \n\
\disobeys this contract \n\
\ \n\
\The Decoder provided has the expected dhall type: \n\
\ \n\
\↳ { bar : Natural, foo : Text }\n\
\ \n\
\and it couldn't extract a value from the well-typed expression: \n\
\and it threw a type error during extraction from the well-typed expression: \n\
\ \n\
\↳ { bar = 0, foo = \"foo\" }\n\
\ \n"
Expand Down

0 comments on commit 84c06c2

Please sign in to comment.