Skip to content

hasura/autodocodec

 
 

Repository files navigation

Autodocodec

Autodocodec is short for "self(auto)- documenting encoder and decoder".

In short: You write a single instance, of the 'Codec' type-class, for your type, and you get:

See the golden test directory directory for example outputs.

Features

  • ✓ Correct-by-construction encoding and decoding, without generating code.
  • ✓ Generate automatically-correct documentation from code.
  • ✓ Support for recursive types.

State of this project

This project is ready to try out!

Fully featured example

data Example = Example
  { exampleTextField :: !Text,
    exampleIntField :: !Int
  }
  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.
    )
    via (Autodocodec Example)

instance HasCodec Example where
  codec =
    object "Example" $
      Example
        <$> requiredField "text" "documentation for the text field" .= exampleTextField
        <*> requiredField "int" "documentation for the int field" .= exampleIntField

Tests

While we don't provide any actual guarantees, we do have tests for the following properties that we would like to maintain:

About

self(auto)- documenting encoders and decoders

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Haskell 94.8%
  • Nix 5.2%