module Hydra.Impl.Haskell.Sources.Ext.Pegasus.Pdl where

import Hydra.Impl.Haskell.Sources.Core
import Hydra.Impl.Haskell.Sources.Ext.Json.Model

import Hydra.All
import Hydra.Impl.Haskell.Dsl.Types as Types
import Hydra.Impl.Haskell.Dsl.Standard


pegasusPdlModule :: Module Meta
pegasusPdlModule :: Module Meta
pegasusPdlModule = forall m.
Namespace -> [Element m] -> [Module m] -> Maybe String -> Module m
Module Namespace
ns [Element Meta]
elements [Module Meta
jsonModelModule] forall a b. (a -> b) -> a -> b
$
    forall a. a -> Maybe a
Just (String
"A model for PDL (Pegasus Data Language) schemas. Based on the specification at:\n" forall a. [a] -> [a] -> [a]
++
      String
"  https://linkedin.github.io/rest.li/pdl_schema")
  where
    ns :: Namespace
ns = String -> Namespace
Namespace String
"hydra/ext/pegasus/pdl"
    def :: String -> Type m -> Element m
def = forall m. Namespace -> String -> Type m -> Element m
datatype Namespace
ns
    pdl :: String -> Type m
pdl = forall m. Namespace -> String -> Type m
nsref Namespace
ns
    json :: String -> Type m
json = forall m. Namespace -> String -> Type m
nsref forall a b. (a -> b) -> a -> b
$ forall m. Module m -> Namespace
moduleNamespace Module Meta
jsonModelModule

    elements :: [Element Meta]
elements = [

      forall {m}. String -> Type m -> Element m
def String
"Annotations" forall a b. (a -> b) -> a -> b
$
        String -> Type Meta -> Type Meta
doc String
"Annotations which can be applied to record fields, aliased union members, enum symbols, or named schemas" forall a b. (a -> b) -> a -> b
$
        forall m. [FieldType m] -> Type m
record [
          String
"doc"forall m. String -> Type m -> FieldType m
>: forall m. Type m -> Type m
optional forall m. Type m
string,
          String
"deprecated"forall m. String -> Type m -> FieldType m
>: forall m. Type m
boolean],

      forall {m}. String -> Type m -> Element m
def String
"EnumField" forall a b. (a -> b) -> a -> b
$
        forall m. [FieldType m] -> Type m
record [
          String
"name"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
pdl String
"EnumFieldName",
          String
"annotations"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
pdl String
"Annotations"],

      forall {m}. String -> Type m -> Element m
def String
"EnumFieldName"
        forall m. Type m
string,

      forall {m}. String -> Type m -> Element m
def String
"EnumSchema" forall a b. (a -> b) -> a -> b
$
        forall m. [FieldType m] -> Type m
record [
          String
"fields"forall m. String -> Type m -> FieldType m
>: forall m. Type m -> Type m
list forall a b. (a -> b) -> a -> b
$ forall {m}. String -> Type m
pdl String
"EnumField"],

      forall {m}. String -> Type m -> Element m
def String
"FieldName"
        forall m. Type m
string,

      forall {m}. String -> Type m -> Element m
def String
"NamedSchema" forall a b. (a -> b) -> a -> b
$
        forall m. [FieldType m] -> Type m
record [
          String
"qualifiedName"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
pdl String
"QualifiedName",
          String
"type"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
pdl String
"NamedSchema.Type",
          String
"annotations"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
pdl String
"Annotations"],

      forall {m}. String -> Type m -> Element m
def String
"NamedSchema.Type" forall a b. (a -> b) -> a -> b
$
        forall m. [FieldType m] -> Type m
union [
          String
"record"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
pdl String
"RecordSchema",
          String
"enum"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
pdl String
"EnumSchema",
          String
"typeref"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
pdl String
"Schema"],

      forall {m}. String -> Type m -> Element m
def String
"Name"
        forall m. Type m
string,

      forall {m}. String -> Type m -> Element m
def String
"Namespace"
        forall m. Type m
string,

      forall {m}. String -> Type m -> Element m
def String
"Package"
        forall m. Type m
string,

      forall {m}. String -> Type m -> Element m
def String
"PrimitiveType" forall a b. (a -> b) -> a -> b
$
        forall m. [String] -> Type m
enum [
          String
"boolean",
          String
"bytes",
          String
"double",
          String
"float",
          String
"int",
          String
"long",
          String
"string"],

      forall {m}. String -> Type m -> Element m
def String
"PropertyKey"
        forall m. Type m
string,

      forall {m}. String -> Type m -> Element m
def String
"Property" forall a b. (a -> b) -> a -> b
$
        forall m. [FieldType m] -> Type m
record [
          String
"key"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
pdl String
"PropertyKey",
          String
"value"forall m. String -> Type m -> FieldType m
>: forall m. Type m -> Type m
optional forall a b. (a -> b) -> a -> b
$ forall {m}. String -> Type m
json String
"Value"],

      forall {m}. String -> Type m -> Element m
def String
"QualifiedName" forall a b. (a -> b) -> a -> b
$
        forall m. [FieldType m] -> Type m
record [
          String
"name"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
pdl String
"Name",
          String
"namespace"forall m. String -> Type m -> FieldType m
>: forall m. Type m -> Type m
optional forall a b. (a -> b) -> a -> b
$ forall {m}. String -> Type m
pdl String
"Namespace"],

      forall {m}. String -> Type m -> Element m
def String
"RecordField" forall a b. (a -> b) -> a -> b
$
        forall m. [FieldType m] -> Type m
record [
          String
"name"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
pdl String
"FieldName",
          String
"value"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
pdl String
"Schema",
          String
"optional"forall m. String -> Type m -> FieldType m
>: forall m. Type m
boolean,
          -- Note: the default value for an enum-valued must be one of the enumerated string symbols
          String
"default"forall m. String -> Type m -> FieldType m
>: forall m. Type m -> Type m
optional forall a b. (a -> b) -> a -> b
$ forall {m}. String -> Type m
json String
"Value",
          String
"annotations"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
pdl String
"Annotations"],

      forall {m}. String -> Type m -> Element m
def String
"RecordSchema" forall a b. (a -> b) -> a -> b
$
        forall m. [FieldType m] -> Type m
record [
          String
"fields"forall m. String -> Type m -> FieldType m
>: forall m. Type m -> Type m
list forall a b. (a -> b) -> a -> b
$ forall {m}. String -> Type m
pdl String
"RecordField",
          -- Note: all included schemas must be record schemas
          String
"includes"forall m. String -> Type m -> FieldType m
>: forall m. Type m -> Type m
list forall a b. (a -> b) -> a -> b
$ forall {m}. String -> Type m
pdl String
"NamedSchema"],

      forall {m}. String -> Type m -> Element m
def String
"Schema" forall a b. (a -> b) -> a -> b
$
        forall m. [FieldType m] -> Type m
union [
          String
"array"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
pdl String
"Schema",
          String
"fixed"forall m. String -> Type m -> FieldType m
>: forall m. Type m
int32,
          String
"inline"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
pdl String
"NamedSchema",
          String
"map"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
pdl String
"Schema",
          String
"named"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
pdl String
"QualifiedName",
          String
"null"forall m. String -> Type m -> FieldType m
>: forall m. Type m
unit,
          String
"primitive"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
pdl String
"PrimitiveType",
          String
"union"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
pdl String
"UnionSchema"],

      forall {m}. String -> Type m -> Element m
def String
"SchemaFile" forall a b. (a -> b) -> a -> b
$
        forall m. [FieldType m] -> Type m
record [
          String
"namespace"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
pdl String
"Namespace",
          String
"package"forall m. String -> Type m -> FieldType m
>: forall m. Type m -> Type m
optional forall a b. (a -> b) -> a -> b
$ forall {m}. String -> Type m
pdl String
"Package",
          String
"imports"forall m. String -> Type m -> FieldType m
>: forall m. Type m -> Type m
list forall a b. (a -> b) -> a -> b
$ forall {m}. String -> Type m
pdl String
"QualifiedName",
          String
"schemas"forall m. String -> Type m -> FieldType m
>: forall m. Type m -> Type m
list forall a b. (a -> b) -> a -> b
$ forall {m}. String -> Type m
pdl String
"NamedSchema"],

      forall {m}. String -> Type m -> Element m
def String
"UnionMember" forall a b. (a -> b) -> a -> b
$
        forall m. [FieldType m] -> Type m
record [
          String
"alias"forall m. String -> Type m -> FieldType m
>: forall m. Type m -> Type m
optional forall a b. (a -> b) -> a -> b
$ forall {m}. String -> Type m
pdl String
"FieldName",
          String
"value"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
pdl String
"Schema",
          -- Note: annotations are only available for aliased members
          String
"annotations"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
pdl String
"Annotations"],

      -- Note: unions are not allowed as member types of other unions
      forall {m}. String -> Type m -> Element m
def String
"UnionSchema" forall a b. (a -> b) -> a -> b
$
        forall m. Type m -> Type m
list forall a b. (a -> b) -> a -> b
$ forall {m}. String -> Type m
pdl String
"UnionMember"]