mirror of
https://github.com/NorfairKing/autodocodec.git
synced 2024-11-30 03:22:52 +03:00
nonempty list instance
This commit is contained in:
parent
5a26606d59
commit
4de5e5f844
@ -56,6 +56,7 @@ spec = do
|
||||
jsonSchemaSpec @(Either Bool Text) "either-bool-text"
|
||||
jsonSchemaSpec @(Either (Either Bool Scientific) Text) "either-either-bool-scientific-text"
|
||||
jsonSchemaSpec @[Text] "list-text"
|
||||
jsonSchemaSpec @(NonEmpty Text) "nonempty-text"
|
||||
jsonSchemaSpec @Example "example"
|
||||
jsonSchemaSpec @Recursive "recursive"
|
||||
jsonSchemaSpec @Via "via"
|
||||
|
@ -17,6 +17,7 @@ import Data.GenValidity.Aeson ()
|
||||
import Data.GenValidity.Scientific ()
|
||||
import Data.GenValidity.Text ()
|
||||
import Data.Int
|
||||
import Data.List.NonEmpty (NonEmpty)
|
||||
import Data.Scientific
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text.Lazy as LT
|
||||
@ -51,6 +52,7 @@ spec = do
|
||||
aesonCodecSpec @(Either Bool Text)
|
||||
aesonCodecSpec @(Either (Either Bool Scientific) Text)
|
||||
aesonCodecSpec @[Text]
|
||||
aesonCodecSpec @(NonEmpty Text)
|
||||
aesonCodecSpec @Fruit
|
||||
aesonCodecSpec @Example
|
||||
aesonCodecSpec @Recursive
|
||||
|
@ -18,6 +18,7 @@ import Data.GenValidity.Containers ()
|
||||
import Data.GenValidity.Scientific ()
|
||||
import Data.GenValidity.Text ()
|
||||
import Data.Int
|
||||
import Data.List.NonEmpty (NonEmpty)
|
||||
import Data.Maybe
|
||||
import Data.OpenApi (Components (..), OpenApi (..))
|
||||
import qualified Data.OpenApi as OpenAPI
|
||||
@ -57,6 +58,7 @@ spec = do
|
||||
openAPISchemaSpec @(Either Bool Text) "either-bool-text"
|
||||
openAPISchemaSpec @(Either (Either Bool Scientific) Text) "either-either-bool-scientific-text"
|
||||
openAPISchemaSpec @[Text] "list-text"
|
||||
openAPISchemaSpec @(NonEmpty Text) "nonempty-text"
|
||||
openAPISchemaSpec @Fruit "fruit"
|
||||
openAPISchemaSpec @Example "example"
|
||||
openAPISchemaSpec @Recursive "recursive"
|
||||
|
@ -14,6 +14,7 @@ import Data.GenValidity.Aeson ()
|
||||
import Data.GenValidity.Scientific ()
|
||||
import Data.GenValidity.Text ()
|
||||
import Data.Int
|
||||
import Data.List.NonEmpty (NonEmpty)
|
||||
import Data.Scientific
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text.Lazy as LT
|
||||
@ -47,6 +48,7 @@ spec = do
|
||||
showCodecSpec @(Either Bool Text) "either-bool-text"
|
||||
showCodecSpec @(Either (Either Bool Scientific) Text) "either-either-bool-scientific-text"
|
||||
showCodecSpec @[Text] "list-text"
|
||||
showCodecSpec @(NonEmpty Text) "nonempty-text"
|
||||
showCodecSpec @Fruit "fruit"
|
||||
showCodecSpec @Example "example"
|
||||
showCodecSpec @Recursive "recursive"
|
||||
|
@ -18,6 +18,7 @@ import Data.GenValidity.Containers ()
|
||||
import Data.GenValidity.Scientific ()
|
||||
import Data.GenValidity.Text ()
|
||||
import Data.Int
|
||||
import Data.List.NonEmpty (NonEmpty)
|
||||
import Data.Maybe
|
||||
import Data.Scientific
|
||||
import Data.Swagger (Swagger (..))
|
||||
@ -57,6 +58,7 @@ spec = do
|
||||
swaggerSchemaSpec @(Either Bool Text) "either-bool-text"
|
||||
swaggerSchemaSpec @(Either (Either Bool Scientific) Text) "either-either-bool-scientific-text"
|
||||
swaggerSchemaSpec @[Text] "list-text"
|
||||
swaggerSchemaSpec @(NonEmpty Text) "nonempty-text"
|
||||
swaggerSchemaSpec @Fruit "fruit"
|
||||
swaggerSchemaSpec @Example "example"
|
||||
swaggerSchemaSpec @Recursive "recursive"
|
||||
|
@ -15,6 +15,7 @@ import Data.GenValidity.Aeson ()
|
||||
import Data.GenValidity.Scientific ()
|
||||
import Data.GenValidity.Text ()
|
||||
import Data.Int
|
||||
import Data.List.NonEmpty (NonEmpty)
|
||||
import Data.Scientific
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text.Lazy as LT
|
||||
@ -48,6 +49,7 @@ spec = do
|
||||
yamlSchemaSpec @(Either Bool Text) "either-bool-text"
|
||||
yamlSchemaSpec @(Either (Either Bool Scientific) Text) "either-either-bool-scientific-text"
|
||||
yamlSchemaSpec @[Text] "list-text"
|
||||
yamlSchemaSpec @(NonEmpty Text) "nonempty-text"
|
||||
yamlSchemaSpec @Fruit "fruit"
|
||||
yamlSchemaSpec @Example "example"
|
||||
yamlSchemaSpec @Recursive "recursive"
|
||||
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
{
|
||||
"components": {
|
||||
"schemas": {
|
||||
"(NonEmpty Text)": {
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
}
|
||||
},
|
||||
"openapi": "3.0.0",
|
||||
"info": {
|
||||
"version": "",
|
||||
"title": ""
|
||||
},
|
||||
"paths": {}
|
||||
}
|
@ -0,0 +1 @@
|
||||
MapCodec _ _ (MapCodec _ _ (ArrayOfCodec Nothing (StringCodec Nothing)))
|
@ -0,0 +1,15 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"version": "",
|
||||
"title": ""
|
||||
},
|
||||
"definitions": {
|
||||
"(NonEmpty Text)": {
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
- [33m<string>[m
|
@ -9,6 +9,8 @@ module Autodocodec.Class where
|
||||
import Autodocodec.Codec
|
||||
import qualified Data.Aeson as JSON
|
||||
import Data.Int
|
||||
import Data.List.NonEmpty (NonEmpty (..))
|
||||
import qualified Data.List.NonEmpty as NE
|
||||
import Data.Scientific
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text.Lazy as LT
|
||||
@ -100,6 +102,13 @@ instance (HasCodec l, HasCodec r) => HasCodec (Either l r) where
|
||||
instance HasCodec a => HasCodec [a] where
|
||||
codec = listCodecForStringCompatibility
|
||||
|
||||
instance HasCodec a => HasCodec (NonEmpty a) where
|
||||
codec = bimapCodec parseNonEmptyList NE.toList codec
|
||||
where
|
||||
parseNonEmptyList l = case NE.nonEmpty l of
|
||||
Nothing -> Left "Expected a nonempty list, but got an empty list."
|
||||
Just ne -> Right ne
|
||||
|
||||
-- | A required field
|
||||
--
|
||||
-- During decoding, the field must be in the object.
|
||||
|
Loading…
Reference in New Issue
Block a user