@@ -1,4 +1,7 @@
1−{-# LANGUAGE DeriveDataTypeable, OverloadedStrings, NoImplicitPrelude, PatternGuards, FlexibleInstances, MultiParamTypeClasses #-}
1+{-# LANGUAGE DeriveDataTypeable, OverloadedStrings, NoImplicitPrelude
2+ , DeriveGeneric, DeriveAnyClass, PatternGuards, FlexibleInstances
3+ , MultiParamTypeClasses, StandaloneDeriving, CPP #-}
4+{-# OPTIONS_GHC -fconstraint-solver-iterations=10 #-}
25-- | This file is generated from the Wikipedia page
36-- <http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2>
47module Data.CountryCodes.ISO31661 (
@@ -14,13 +17,19 @@ module Data.CountryCodes.ISO31661 (
1417
1518import Control.Applicative (pure)
1619import Control.DeepSeq (NFData(..))
17−import Data.Aeson
18−import Data.Typeable
19−import qualified Data.Text as T
20−import Prelude (Show,Read,Eq,Ord,Bounded,Enum,error,($),(++),Maybe(..),(.),fail,seq)
21−import Text.Shakespeare.I18N
20+import Data.Aeson
21+import Data.Typeable
22+import Data.Text as T
23+import GHC.Generics
24+import Prelude (Show,Read,Eq,Ord,Bounded,Enum,error,($),(++),Maybe(..),(.),fail,seq)
25+import Text.Shakespeare.I18N
26+#ifdef BACKEND
27+import Data.OpenApi
28+import Test.QuickCheck.Arbitrary
29+import Test.QuickCheck.Arbitrary.Generic
30+#endif
2231
23−data CountryCode =
32+data CountryCode =
2433 AD
2534 | AE
2635 | AF
@@ -270,7 +279,19 @@ data CountryCode =
270279 | ZA
271280 | ZM
272281 | ZW
273− deriving (Show,Read,Eq,Ord,Bounded,Enum,Typeable)
282+ -- Added these non standard codes that occur in
283+ -- travolutionary database
284+ -- https://typeable.atlassian.net/browse/B2H-796
285+ | XA
286+ | AN
287+ | XK
288+ | XC
289+ | WE
290+ deriving (Show,Read,Eq,Ord,Bounded,Enum,Typeable, Generic
291+#ifdef BACKEND
292+ , ToSchema
293+#endif
294+ )
274295
275296-- | Maybe get the CountryCode from the text code.
276297fromMText :: T.Text -> Maybe CountryCode
@@ -523,6 +544,11 @@ fromMText "YT" = Just YT
523544fromMText "ZA" = Just ZA
524545fromMText "ZM" = Just ZM
525546fromMText "ZW" = Just ZW
547+fromMText "XA" = Just XA
548+fromMText "AN" = Just AN
549+fromMText "XK" = Just XK
550+fromMText "XC" = Just XC
551+fromMText "WE" = Just WE
526552fromMText _ = Nothing
527553
528554-- | Get the CountryCode from the text code. Errors if the code is unknown
@@ -782,6 +808,11 @@ toText YT = "YT"
782808toText ZA = "ZA"
783809toText ZM = "ZM"
784810toText ZW = "ZW"
811+toText XA = "XA"
812+toText AN = "AN"
813+toText XK = "XK"
814+toText XC = "XC"
815+toText WE = "WE"
785816
786817-- | Maybe get the code from the user readable name.
787818fromMName :: T.Text -> Maybe CountryCode
@@ -1034,6 +1065,11 @@ fromMName "Mayotte" = Just YT
10341065fromMName "South Africa" = Just ZA
10351066fromMName "Zambia" = Just ZM
10361067fromMName "Zimbabwe" = Just ZW
1068+fromMName "Canary Islands" = Just XA
1069+fromMName "Netherlands Antilles" = Just AN
1070+fromMName "Kosovo" = Just XK
1071+fromMName "Ceuta" = Just XC
1072+fromMName "West Bank" = Just WE
10371073fromMName _ = Nothing
10381074
10391075-- | Get the CountryCode from the user readable name. Errors if the name is unknown
@@ -1293,6 +1329,11 @@ toName YT = "Mayotte"
12931329toName ZA = "South Africa"
12941330toName ZM = "Zambia"
12951331toName ZW = "Zimbabwe"
1332+toName XA = "Canary Islands"
1333+toName AN = "Netherlands Antilles"
1334+toName XK = "Kosovo"
1335+toName XC = "Ceuta"
1336+toName WE = "West Bank"
12961337
12971338-- | list of names sorted by alphabetical order, with country code
12981339-- this is ready to be used in a yesod selectField, for example
@@ -1545,17 +1586,26 @@ countryList = [("Afghanistan",AF)
15451586 ,("Yemen",YE)
15461587 ,("Zambia",ZM)
15471588 ,("Zimbabwe",ZW)
1548− ,("Åland Islands",AX) ]
1589+ ,("Åland Islands",AX)
1590+ ,("Canary Islands", XA)
1591+ ,("Netherlands Antilles",AN)
1592+ ,("Kosovo",XK)
1593+ ,("Ceuta",XC)
1594+ ,("West Bank",WE)
1595+ ]
15491596
15501597-- | to json: as a simple string
15511598instance ToJSON CountryCode where
1552− toJSON =toJSON . toText
1599+ toJSON = toJSON . toText
15531600
15541601-- | from json: as a simple string
15551602instance FromJSON CountryCode where
15561603 parseJSON (String s)
15571604 | Just a <- fromMText s=pure a
1558− parseJSON _ =fail "CountryCode"
1605+ parseJSON _ = fail "CountryCode"
1606+
1607+deriving instance ToJSONKey CountryCode
1608+deriving instance FromJSONKey CountryCode
15591609
15601610-- | show user readable name, in English (ignoring locale for now)
15611611instance RenderMessage master CountryCode where
@@ -1564,3 +1614,9 @@ instance RenderMessage master CountryCode where
15641614-- | Allow the deep evaluation of CountryCode with `deepseq`
15651615instance NFData CountryCode where
15661616 rnf a = a `seq` ()
1617+
1618+#ifdef BACKEND
1619+instance Arbitrary CountryCode where
1620+ arbitrary = genericArbitrary
1621+ shrink = genericShrink
1622+#endif