git.iko.soy/typeable/country-codes
on master help sign in
Add Generic, ToSchema and To/FromJSONKey instances
commita85df94fc3682fb5eaab8236b375dc855cda20a3 authorDmitry Olshansky <olshanskydr@gmail.com> dateSat 2 Apr 2022, 12:26 (5 years ago) parentf41fa75
3 files changed+22−69
country-codes.cabal+1 src/Data/CountryCodes/ISO31661.hs+16−9 stack.yaml+5−60
country-codes.cabal+1
@@ -32,6 +32,7 @@ library
3232 , aeson >= 0.5
3333 , deepseq >= 1.4
3434 , shakespeare == 2.0.*
35+ , openapi3
3536 ghc-options: -Wall
3637 other-modules: Data.CountryCodes.ISO31661
3738 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 #-}
24-- | This file is generated from the Wikipedia page
35-- <http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2>
46module Data.CountryCodes.ISO31661 (
@@ -14,11 +16,13 @@ module Data.CountryCodes.ISO31661 (
1416
1517import Control.Applicative (pure)
1618import 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
19+import Data.Aeson
20+import Data.Typeable
21+import Data.Text as T
22+import Data.OpenApi
23+import GHC.Generics
24+import Prelude (Show,Read,Eq,Ord,Bounded,Enum,error,($),(++),Maybe(..),(.),fail,seq)
25+import Text.Shakespeare.I18N
2226
2327data CountryCode =
2428 AD
@@ -278,7 +282,7 @@ data CountryCode =
278282 | XK
279283 | XC
280284 | WE
281− deriving (Show,Read,Eq,Ord,Bounded,Enum,Typeable)
285+ deriving (Show,Read,Eq,Ord,Bounded,Enum,Typeable, Generic, ToSchema)
282286
283287-- | Maybe get the CountryCode from the text code.
284288fromMText :: T.Text -> Maybe CountryCode
@@ -1583,13 +1587,16 @@ countryList = [("Afghanistan",AF)
15831587
15841588-- | to json: as a simple string
15851589instance ToJSON CountryCode where
1586− toJSON =toJSON . toText
1590+ toJSON = toJSON . toText
15871591
15881592-- | from json: as a simple string
15891593instance FromJSON CountryCode where
15901594 parseJSON (String s)
15911595 | 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
15931600
15941601-- | show user readable name, in English (ignoring locale for now)
15951602instance RenderMessage master CountryCode where
stack.yaml+5−60
@@ -1,64 +1,9 @@
1−# This file was automatically generated by 'stack init'
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/
1+resolver: lts-18.18
62
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
353packages:
364- .
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: []
475
48−# Control whether we use the GHC we find on the path
49−# system-ghc: true
50−#
51−# Require a specific version of stack, using version ranges
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
6+extra-deps:
7+- git: https://github.com/typeable/openapi3.git
8+ # nix-sha256: 1aqn5dia4aqwpmr3v0rcb8kzhknp5674hhay8h7p76206dx83ykg
9+ commit: bb1c64f8501535143c92907166fdc9f8df6d51b9