Skip to content

Instantly share code, notes, and snippets.

@mbbx6spp
Last active March 12, 2020 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbbx6spp/0cae338695b68e2aedaf088819a62a61 to your computer and use it in GitHub Desktop.
Save mbbx6spp/0cae338695b68e2aedaf088819a62a61 to your computer and use it in GitHub Desktop.
Outline of describing schema with algebraic data types for basic descriptions of data, in this case a Swagger "schema". Eventually we can evolve it in class to generating YAML/JSON Swagger from this data description and possible build swagger representations from Generic Reps
module Models.Swagger where
import Data.Map (Map)
import Data.Maybe (Maybe (..))
import Data.String.Regex (Regex)
import Data.Show (class Show, show)
data SwaggerFormatString
= DateFormat
| DateTimeFormat
| PasswordFormat
| ByteFormat
| BinaryFormat
| OtherStringFormat String
data SwaggerFormatNumber
= FloatFormat
| DoubleFormat
data SwaggerFormatInt
= Int32Format
| Int64Format
data SwaggerType
= SwaggerString { format :: Maybe SwaggerFormatString
, minLength :: Maybe Int
, maxLength :: Maybe Int
, pattern :: Maybe Regex
, enum :: Array String }
| SwaggerNumber { format :: Maybe SwaggerFormatNumber
, minimum :: Maybe Number
, maximum :: Maybe Number
, exclusiveMin :: Boolean
, exclusiveMax :: Boolean
, multipleOf :: Maybe Number }
| SwaggerInteger { format :: Maybe SwaggerFormatInt
, minimum :: Maybe Int
, maximum :: Maybe Int
, exclusiveMin :: Boolean
, exclusiveMax :: Boolean
, multipleOf :: Maybe Int }
| SwaggerOneOf (Array SwaggerType)
| SwaggerAllOf (Array SwaggerType)
| SwaggerAnyOf (Array SwaggerType)
| SwaggerArray { items :: SwaggerType
, minItems :: Maybe Int
, maxItems :: Maybe Int
, uniqueItems :: Boolean }
| SwaggerObject { fields :: Map String SwaggerType }
| SwaggerBoolean
| SwaggerNull
-- Smart constructors below
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment