diff --git a/README.md b/README.md index 24572ad..9d11b29 100644 --- a/README.md +++ b/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 + +int: # required + # documentation for the int field + # 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: