mirror of
https://github.com/NorfairKing/autodocodec.git
synced 2024-10-03 18:37:08 +03:00
Adapt example in README to make it compile
This commit is contained in:
parent
72033e001b
commit
032898f5d6
36
README.md
36
README.md
@ -29,6 +29,20 @@ This project is ready to try out!
|
||||
## Fully featured example
|
||||
|
||||
``` haskell
|
||||
{-# LANGUAGE DeriveGeneric #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE DerivingVia #-}
|
||||
{-# LANGUAGE TypeApplications #-}
|
||||
module Main (main) where
|
||||
|
||||
|
||||
import Autodocodec
|
||||
import Autodocodec.Yaml
|
||||
import GHC.Generics
|
||||
import Data.Aeson (FromJSON, ToJSON)
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
|
||||
data Example = Example
|
||||
{ exampleTextField :: !Text,
|
||||
exampleIntField :: !Int
|
||||
@ -36,9 +50,7 @@ data Example = Example
|
||||
deriving stock (Show, Eq, Generic)
|
||||
deriving
|
||||
( FromJSON, -- <- FromJSON instance for free.
|
||||
ToJSON, -- <- ToJSON instance for free.
|
||||
Swagger.ToSchema, -- <- Swagger schema for free.
|
||||
OpenAPI.ToSchema -- <- OpenAPI schema for free.
|
||||
ToJSON -- <- ToJSON instance for free.
|
||||
)
|
||||
via (Autodocodec Example)
|
||||
|
||||
@ -48,8 +60,26 @@ instance HasCodec Example where
|
||||
Example
|
||||
<$> requiredField "text" "documentation for the text field" .= exampleTextField
|
||||
<*> requiredField "int" "documentation for the int field" .= exampleIntField
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
let schema = T.unpack $ renderColouredSchemaViaCodec @Example
|
||||
putStrLn schema
|
||||
```
|
||||
|
||||
This will output a nice coloured yaml-schema:
|
||||
|
||||
```
|
||||
# Example
|
||||
text: # required
|
||||
# documentation for the text field
|
||||
<string>
|
||||
int: # required
|
||||
# documentation for the int field
|
||||
<number> # between -9223372036854775808 and 9223372036854775807
|
||||
```
|
||||
|
||||
|
||||
## Tests
|
||||
|
||||
While we don't provide any actual guarantees, we do have tests for the following properties that we would like to maintain:
|
||||
|
Loading…
Reference in New Issue
Block a user