-
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.
[sc-35836] Add initial oneOf schema code gen support
This uses shrubbery untagged unions to implement oneOf code gen. We could use tagged unions here but I'm not sure if doing so adds any meaningful information. Remaining notes and questions: - I don't fully understand `SchemaMap`s, so I think they may be handled incorrectly, what is there indended use, and should we try to use them here instead of inferType? If yes, is there a test case that would reveal an issue with not using them - Related to the above, should we extract/share code between `mkInlineOneOfSchema` and `mkInlineBodySchema`? - This does not implement openapi discriminators, which is where I imagine using tagged unions might become useful - This does not implement inline objects as choices for `oneOf` - Are there any other test cases we want for the initial implementation? - If we run into `anyOf` being used, it would probably be simple to have it just call out to the `oneOf` code (though hopefully no one ever uses `anyOf`...) Co-Authored-By: Tyler <[email protected]> Co-Authored-By: Janus <[email protected]>
- Loading branch information
1 parent
60ec4db
commit d3750b4
Showing
10 changed files
with
304 additions
and
19 deletions.
There are no files selected for viewing
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,3 @@ | ||
{ | ||
"haskell.serverExecutablePath": "${workspaceFolder}/.vim/haskell-language-server-wrapper", | ||
} |
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
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
31 changes: 31 additions & 0 deletions
31
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
|
||
module TestCases.Types.TopLevelOneOf | ||
( TopLevelOneOf(..) | ||
, topLevelOneOfSchema | ||
) where | ||
|
||
import qualified Data.Text as T | ||
import Fleece.Core ((#|)) | ||
import qualified Fleece.Core as FC | ||
import Prelude (($), Eq, Integer, Show) | ||
import qualified Shrubbery as Shrubbery | ||
import qualified TestCases.Types.AStringType as AStringType | ||
import qualified TestCases.Types.FieldDescriptions as FieldDescriptions | ||
import qualified TestCases.Types.MixedInJustAdditionalPropertiesSchemaInline as MixedInJustAdditionalPropertiesSchemaInline | ||
import qualified TestCases.Types.Num2SchemaStartingWithNumber as Num2SchemaStartingWithNumber | ||
|
||
newtype TopLevelOneOf = TopLevelOneOf (Shrubbery.Union '[T.Text, Integer, AStringType.AStringType, Num2SchemaStartingWithNumber.Num2SchemaStartingWithNumber, [FieldDescriptions.FieldDescriptions], [[MixedInJustAdditionalPropertiesSchemaInline.MixedInJustAdditionalPropertiesSchemaInline]]]) | ||
deriving (Show, Eq) | ||
|
||
topLevelOneOfSchema :: FC.Fleece schema => schema TopLevelOneOf | ||
topLevelOneOfSchema = | ||
FC.coerceSchema $ | ||
FC.unionNamed (FC.unqualifiedName "TopLevelOneOf") $ | ||
FC.unionMember FC.text | ||
#| FC.unionMember FC.integer | ||
#| FC.unionMember AStringType.aStringTypeSchema | ||
#| FC.unionMember Num2SchemaStartingWithNumber.num2SchemaStartingWithNumberSchema | ||
#| FC.unionMember (FC.list FieldDescriptions.fieldDescriptionsSchema) | ||
#| FC.unionMember (FC.list (FC.list MixedInJustAdditionalPropertiesSchemaInline.mixedInJustAdditionalPropertiesSchemaInlineSchema)) |
21 changes: 21 additions & 0 deletions
21
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
|
||
module TestCases.Types.TopLevelOneOfOneOption | ||
( TopLevelOneOfOneOption(..) | ||
, topLevelOneOfOneOptionSchema | ||
) where | ||
|
||
import qualified Data.Text as T | ||
import qualified Fleece.Core as FC | ||
import Prelude (($), Eq, Show) | ||
import qualified Shrubbery as Shrubbery | ||
|
||
newtype TopLevelOneOfOneOption = TopLevelOneOfOneOption (Shrubbery.Union '[T.Text]) | ||
deriving (Show, Eq) | ||
|
||
topLevelOneOfOneOptionSchema :: FC.Fleece schema => schema TopLevelOneOfOneOption | ||
topLevelOneOfOneOptionSchema = | ||
FC.coerceSchema $ | ||
FC.unionNamed (FC.unqualifiedName "TopLevelOneOfOneOption") $ | ||
FC.unionMember FC.text |
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
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
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
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.