-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Adding code-gen support for OpenAPI discriminators using Tagged …
…Unions
- Loading branch information
Showing
20 changed files
with
756 additions
and
313 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
json-fleece-openapi3/examples/test-cases/TestCases/Types/Bar.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
|
||
module TestCases.Types.Bar | ||
( Bar(..) | ||
, barSchema | ||
) where | ||
|
||
import Fleece.Core ((#+)) | ||
import qualified Fleece.Core as FC | ||
import Prelude (($), Eq, Maybe, Show) | ||
import qualified TestCases.Types.Bar.BarName as BarName | ||
import qualified TestCases.Types.Bar.Type as Type | ||
|
||
data Bar = Bar | ||
{ barName :: Maybe BarName.BarName | ||
, type_ :: Maybe Type.Type | ||
} | ||
deriving (Eq, Show) | ||
|
||
barSchema :: FC.Fleece schema => schema Bar | ||
barSchema = | ||
FC.object $ | ||
FC.constructor Bar | ||
#+ FC.optional "barName" barName BarName.barNameSchema | ||
#+ FC.optional "type" type_ Type.typeSchema |
17 changes: 17 additions & 0 deletions
17
json-fleece-openapi3/examples/test-cases/TestCases/Types/Bar/BarName.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
|
||
module TestCases.Types.Bar.BarName | ||
( BarName(..) | ||
, barNameSchema | ||
) where | ||
|
||
import qualified Data.Text as T | ||
import qualified Fleece.Core as FC | ||
import Prelude (Eq, Show) | ||
|
||
newtype BarName = BarName T.Text | ||
deriving (Show, Eq) | ||
|
||
barNameSchema :: FC.Fleece schema => schema BarName | ||
barNameSchema = | ||
FC.coerceSchema FC.text |
17 changes: 17 additions & 0 deletions
17
json-fleece-openapi3/examples/test-cases/TestCases/Types/Bar/Type.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
|
||
module TestCases.Types.Bar.Type | ||
( Type(..) | ||
, typeSchema | ||
) where | ||
|
||
import qualified Data.Text as T | ||
import qualified Fleece.Core as FC | ||
import Prelude (Eq, Show) | ||
|
||
newtype Type = Type T.Text | ||
deriving (Show, Eq) | ||
|
||
typeSchema :: FC.Fleece schema => schema Type | ||
typeSchema = | ||
FC.coerceSchema FC.text |
25 changes: 25 additions & 0 deletions
25
json-fleece-openapi3/examples/test-cases/TestCases/Types/Baz.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
|
||
module TestCases.Types.Baz | ||
( Baz(..) | ||
, bazSchema | ||
) where | ||
|
||
import Fleece.Core ((#+)) | ||
import qualified Fleece.Core as FC | ||
import Prelude (($), Eq, Maybe, Show) | ||
import qualified TestCases.Types.Baz.BazName as BazName | ||
import qualified TestCases.Types.Baz.Type as Type | ||
|
||
data Baz = Baz | ||
{ bazName :: Maybe BazName.BazName | ||
, type_ :: Maybe Type.Type | ||
} | ||
deriving (Eq, Show) | ||
|
||
bazSchema :: FC.Fleece schema => schema Baz | ||
bazSchema = | ||
FC.object $ | ||
FC.constructor Baz | ||
#+ FC.optional "bazName" bazName BazName.bazNameSchema | ||
#+ FC.optional "type" type_ Type.typeSchema |
17 changes: 17 additions & 0 deletions
17
json-fleece-openapi3/examples/test-cases/TestCases/Types/Baz/BazName.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
|
||
module TestCases.Types.Baz.BazName | ||
( BazName(..) | ||
, bazNameSchema | ||
) where | ||
|
||
import qualified Data.Text as T | ||
import qualified Fleece.Core as FC | ||
import Prelude (Eq, Show) | ||
|
||
newtype BazName = BazName T.Text | ||
deriving (Show, Eq) | ||
|
||
bazNameSchema :: FC.Fleece schema => schema BazName | ||
bazNameSchema = | ||
FC.coerceSchema FC.text |
17 changes: 17 additions & 0 deletions
17
json-fleece-openapi3/examples/test-cases/TestCases/Types/Baz/Type.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
|
||
module TestCases.Types.Baz.Type | ||
( Type(..) | ||
, typeSchema | ||
) where | ||
|
||
import qualified Data.Text as T | ||
import qualified Fleece.Core as FC | ||
import Prelude (Eq, Show) | ||
|
||
newtype Type = Type T.Text | ||
deriving (Show, Eq) | ||
|
||
typeSchema :: FC.Fleece schema => schema Type | ||
typeSchema = | ||
FC.coerceSchema FC.text |
25 changes: 25 additions & 0 deletions
25
json-fleece-openapi3/examples/test-cases/TestCases/Types/Foo.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
|
||
module TestCases.Types.Foo | ||
( Foo(..) | ||
, fooSchema | ||
) where | ||
|
||
import Fleece.Core ((#+)) | ||
import qualified Fleece.Core as FC | ||
import Prelude (($), Eq, Maybe, Show) | ||
import qualified TestCases.Types.Foo.FooName as FooName | ||
import qualified TestCases.Types.Foo.Type as Type | ||
|
||
data Foo = Foo | ||
{ fooName :: Maybe FooName.FooName | ||
, type_ :: Maybe Type.Type | ||
} | ||
deriving (Eq, Show) | ||
|
||
fooSchema :: FC.Fleece schema => schema Foo | ||
fooSchema = | ||
FC.object $ | ||
FC.constructor Foo | ||
#+ FC.optional "fooName" fooName FooName.fooNameSchema | ||
#+ FC.optional "type" type_ Type.typeSchema |
17 changes: 17 additions & 0 deletions
17
json-fleece-openapi3/examples/test-cases/TestCases/Types/Foo/FooName.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
|
||
module TestCases.Types.Foo.FooName | ||
( FooName(..) | ||
, fooNameSchema | ||
) where | ||
|
||
import qualified Data.Text as T | ||
import qualified Fleece.Core as FC | ||
import Prelude (Eq, Show) | ||
|
||
newtype FooName = FooName T.Text | ||
deriving (Show, Eq) | ||
|
||
fooNameSchema :: FC.Fleece schema => schema FooName | ||
fooNameSchema = | ||
FC.coerceSchema FC.text |
17 changes: 17 additions & 0 deletions
17
json-fleece-openapi3/examples/test-cases/TestCases/Types/Foo/Type.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
|
||
module TestCases.Types.Foo.Type | ||
( Type(..) | ||
, typeSchema | ||
) where | ||
|
||
import qualified Data.Text as T | ||
import qualified Fleece.Core as FC | ||
import Prelude (Eq, Show) | ||
|
||
newtype Type = Type T.Text | ||
deriving (Show, Eq) | ||
|
||
typeSchema :: FC.Fleece schema => schema Type | ||
typeSchema = | ||
FC.coerceSchema FC.text |
34 changes: 34 additions & 0 deletions
34
json-fleece-openapi3/examples/test-cases/TestCases/Types/OneOfWithDiscriminator.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE ExplicitNamespaces #-} | ||
{-# LANGUAGE TypeOperators #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
module TestCases.Types.OneOfWithDiscriminator | ||
( OneOfWithDiscriminator(..) | ||
, oneOfWithDiscriminatorSchema | ||
) where | ||
|
||
import Fleece.Core ((#@)) | ||
import qualified Fleece.Core as FC | ||
import Prelude (($), Eq, Show) | ||
import Shrubbery (type (@=)) | ||
import qualified Shrubbery as Shrubbery | ||
import qualified TestCases.Types.Bar as Bar | ||
import qualified TestCases.Types.Baz as Baz | ||
import qualified TestCases.Types.Foo as Foo | ||
|
||
newtype OneOfWithDiscriminator = OneOfWithDiscriminator (Shrubbery.TaggedUnion | ||
'[ "bar" @= Bar.Bar | ||
, "baz" @= Baz.Baz | ||
, "foo" @= Foo.Foo | ||
]) | ||
deriving (Show, Eq) | ||
|
||
oneOfWithDiscriminatorSchema :: FC.Fleece schema => schema OneOfWithDiscriminator | ||
oneOfWithDiscriminatorSchema = | ||
FC.coerceSchema $ | ||
FC.taggedUnionNamed (FC.qualifiedName "TestCases.Types.OneOfWithDiscriminator" "OneOfWithDiscriminator") "type" $ | ||
FC.taggedUnionMember @"bar" Bar.barSchema | ||
#@ FC.taggedUnionMember @"baz" Baz.bazSchema | ||
#@ FC.taggedUnionMember @"foo" Foo.fooSchema |
2 changes: 1 addition & 1 deletion
2
json-fleece-openapi3/examples/test-cases/TestCases/Types/OneOfWithNullable.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
json-fleece-openapi3/examples/test-cases/TestCases/Types/ReferenceOneOfInsideOneOf.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
json-fleece-openapi3/examples/test-cases/TestCases/Types/TopLevelOneOf.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
json-fleece-openapi3/examples/test-cases/TestCases/Types/TopLevelOneOfOneOption.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.