git.iko.soy/typeable/country-codes
on master help sign in
Add Generic, ToSchema and To/FromJSONKey instances
a85df94Dmitry Olshansky
country-codes.cabal+1
@@ -32,6 +32,7 @@ library
32 , aeson >= 0.5
32 , aeson >= 0.5
33 , deepseq >= 1.4
33 , deepseq >= 1.4
34 , shakespeare == 2.0.*
34 , shakespeare == 2.0.*
35+ , openapi3
35 ghc-options: -Wall
36 ghc-options: -Wall
36 other-modules: Data.CountryCodes.ISO31661
37 other-modules: Data.CountryCodes.ISO31661
37 exposed-modules: Data.CountryCodes
38 exposed-modules: Data.CountryCodes
src/Data/CountryCodes/ISO31661.hs+16−9
@@ -1,4 +1,6 @@
1−{-# LANGUAGE DeriveDataTypeable, OverloadedStrings, NoImplicitPrelude, PatternGuards, FlexibleInstances, MultiParamTypeClasses #-}
1+{-# LANGUAGE DeriveDataTypeable, OverloadedStrings, NoImplicitPrelude
2+ , DeriveGeneric, DeriveAnyClass, PatternGuards, FlexibleInstances
3+ , MultiParamTypeClasses, StandaloneDeriving #-}
2-- | This file is generated from the Wikipedia page
4-- | This file is generated from the Wikipedia page
3-- <http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2>
5-- <http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2>
4module Data.CountryCodes.ISO31661 (
6module Data.CountryCodes.ISO31661 (
@@ -14,11 +16,13 @@ module Data.CountryCodes.ISO31661 (
14
16
15import Control.Applicative (pure)
17import Control.Applicative (pure)
16import Control.DeepSeq (NFData(..))
18import Control.DeepSeq (NFData(..))
17−import Data.Aeson
19+import Data.Aeson
18−import Data.Typeable
20+import Data.Typeable
19−import qualified Data.Text as T
21+import Data.Text as T
22+import Data.OpenApi
23+import GHC.Generics
20−import Prelude (Show,Read,Eq,Ord,Bounded,Enum,error,($),(++),Maybe(..),(.),fail,seq)
24+import Prelude (Show,Read,Eq,Ord,Bounded,Enum,error,($),(++),Maybe(..),(.),fail,seq)
21−import Text.Shakespeare.I18N
25+import Text.Shakespeare.I18N
22
26
23data CountryCode =
27data CountryCode =
24 AD
28 AD
@@ -278,7 +282,7 @@ data CountryCode =
278 | XK
282 | XK
279 | XC
283 | XC
280 | WE
284 | WE
281− deriving (Show,Read,Eq,Ord,Bounded,Enum,Typeable)
285+ deriving (Show,Read,Eq,Ord,Bounded,Enum,Typeable, Generic, ToSchema)
282
286
283-- | Maybe get the CountryCode from the text code.
287-- | Maybe get the CountryCode from the text code.
284fromMText :: T.Text -> Maybe CountryCode
288fromMText :: T.Text -> Maybe CountryCode
@@ -1583,13 +1587,16 @@ countryList = [("Afghanistan",AF)
1583
1587
1584-- | to json: as a simple string
1588-- | to json: as a simple string
1585instance ToJSON CountryCode where
1589instance ToJSON CountryCode where
1586− toJSON =toJSON . toText
1590+ toJSON = toJSON . toText
1587
1591
1588-- | from json: as a simple string
1592-- | from json: as a simple string
1589instance FromJSON CountryCode where
1593instance FromJSON CountryCode where
1590 parseJSON (String s)
1594 parseJSON (String s)
1591 | Just a <- fromMText s=pure a
1595 | Just a <- fromMText s=pure a
1592− parseJSON _ =fail "CountryCode"
1596+ parseJSON _ = fail "CountryCode"
1597+
1598+deriving instance ToJSONKey CountryCode
1599+deriving instance FromJSONKey CountryCode
1593
1600
1594-- | show user readable name, in English (ignoring locale for now)
1601-- | show user readable name, in English (ignoring locale for now)
1595instance RenderMessage master CountryCode where
1602instance RenderMessage master CountryCode where
stack.yaml+5−60
@@ -1,64 +1,9 @@
1−# This file was automatically generated by 'stack init'
1+resolver: lts-18.18
2−#
3−# Some commonly used options have been documented as comments in this file.
4−# For advanced use and comprehensive documentation of the format, please see:
5−# https://docs.haskellstack.org/en/stable/yaml_configuration/
6
2
7−# Resolver to choose a 'specific' stackage snapshot or a compiler version.
8−# A snapshot resolver dictates the compiler version and the set of packages
9−# to be used for project dependencies. For example:
10−#
11−# resolver: lts-3.5
12−# resolver: nightly-2015-09-21
13−# resolver: ghc-7.10.2
14−#
15−# The location of a snapshot can be provided as a file or url. Stack assumes
16−# a snapshot provided as a file might change, whereas a url resource does not.
17−#
18−# resolver: ./custom-snapshot.yaml
19−# resolver: https://example.com/snapshots/2018-01-01.yaml
20−resolver: lts-13.7
21−
22−# User packages to be built.
23−# Various formats can be used as shown in the example below.
24−#
25−# packages:
26−# - some-directory
27−# - https://example.com/foo/bar/baz-0.0.2.tar.gz
28−# - location:
29−# git: https://github.com/commercialhaskell/stack.git
30−# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
31−# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
32−# subdirs:
33−# - auto-update
34−# - wai
35packages:
3packages:
36- .
4- .
37−# Dependency packages to be pulled from upstream that are not in the resolver
38−# using the same syntax as the packages field.
39−# (e.g., acme-missiles-0.3)
40−# extra-deps: []
41−
42−# Override default flag values for local packages and extra-deps
43−# flags: {}
44−
45−# Extra package databases containing global packages
46−# extra-package-dbs: []
47
5
48−# Control whether we use the GHC we find on the path
6+extra-deps:
49−# system-ghc: true
7+- git: https://github.com/typeable/openapi3.git
50−#
8+ # nix-sha256: 1aqn5dia4aqwpmr3v0rcb8kzhknp5674hhay8h7p76206dx83ykg
51−# Require a specific version of stack, using version ranges
9+ commit: bb1c64f8501535143c92907166fdc9f8df6d51b9
52−# require-stack-version: -any # Default
53−# require-stack-version: ">=1.9"
54−#
55−# Override the architecture used by stack, especially useful on Windows
56−# arch: i386
57−# arch: x86_64
58−#
59−# Extra directories used by stack for building
60−# extra-include-dirs: [/path/to/dir]
61−# extra-lib-dirs: [/path/to/dir]
62−#
63−# Allow a newer minor version of GHC than the snapshot specifies
64−# compiler-check: newer-minor