mirror of
https://github.com/scarf-sh/tie.git
synced 2024-11-22 10:31:56 +03:00
Don't forget the haskell field lookup for composite names
This commit is contained in:
parent
e877363252
commit
b765a2461d
@ -627,9 +627,12 @@ normalizeObjectType ::
|
||||
normalizeObjectType assignObjectFieldTypeName assignAdditionaPropertiesTypeName objectType@ObjectType {..} = do
|
||||
(properties, newTypes) <- runWriterT $
|
||||
flip HashMap.traverseWithKey properties $ \fieldName fieldType -> do
|
||||
let
|
||||
haskellFieldName =
|
||||
HashMap.lookupDefault fieldName fieldName haskellFieldNames
|
||||
WriterT $
|
||||
normalizeNamedType
|
||||
(assignObjectFieldTypeName fieldName)
|
||||
(assignObjectFieldTypeName haskellFieldName)
|
||||
fieldType
|
||||
(additionalProperties, newTypes') <- runWriterT $
|
||||
case additionalProperties of
|
||||
|
@ -50,4 +50,14 @@ components:
|
||||
x-tie-haskell-type: Scarf.Hashids.Hashid Int32
|
||||
test2:
|
||||
type: string
|
||||
x-tie-haskell-name: abcdef
|
||||
x-tie-haskell-name: abcdef
|
||||
'$test3':
|
||||
type: array
|
||||
x-tie-haskell-name: test3
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
value:
|
||||
type: string
|
||||
|
@ -619,8 +619,34 @@ import qualified Scarf.Hashids
|
||||
|
||||
|
||||
|
||||
data TestTest3 = TestTest3
|
||||
{
|
||||
name :: (Data.Maybe.Maybe (Data.Text.Text)),
|
||||
value :: (Data.Maybe.Maybe (Data.Text.Text))
|
||||
}
|
||||
deriving (Show)
|
||||
|
||||
instance Data.Aeson.ToJSON TestTest3 where
|
||||
toJSON TestTest3 {..} = Data.Aeson.object
|
||||
([
|
||||
]
|
||||
++ [ "name" Data.Aeson..= name | Just name <- [name] ]
|
||||
++ [ "value" Data.Aeson..= value | Just value <- [value] ])
|
||||
|
||||
toEncoding TestTest3 {..} = Data.Aeson.Encoding.pairs
|
||||
( maybe mempty (Data.Aeson.Encoding.pair "name" . Data.Aeson.toEncoding) name <>
|
||||
maybe mempty (Data.Aeson.Encoding.pair "value" . Data.Aeson.toEncoding) value
|
||||
)
|
||||
|
||||
instance Data.Aeson.FromJSON TestTest3 where
|
||||
parseJSON = Data.Aeson.withObject "TestTest3" $ \o ->
|
||||
TestTest3
|
||||
<$> o Data.Aeson..:? "name"
|
||||
<*> o Data.Aeson..:? "value"
|
||||
|
||||
data Test = Test
|
||||
{
|
||||
test3 :: (Data.Maybe.Maybe ([ TestTest3 ])),
|
||||
test1 :: (Data.Maybe.Maybe (Scarf.Hashids.Hashid Int32)),
|
||||
abcdef :: (Data.Maybe.Maybe (Data.Text.Text))
|
||||
}
|
||||
@ -630,18 +656,21 @@ instance Data.Aeson.ToJSON Test where
|
||||
toJSON Test {..} = Data.Aeson.object
|
||||
([
|
||||
]
|
||||
++ [ "$test3" Data.Aeson..= test3 | Just test3 <- [test3] ]
|
||||
++ [ "test1" Data.Aeson..= test1 | Just test1 <- [test1] ]
|
||||
++ [ "test2" Data.Aeson..= abcdef | Just abcdef <- [abcdef] ])
|
||||
|
||||
toEncoding Test {..} = Data.Aeson.Encoding.pairs
|
||||
( maybe mempty (Data.Aeson.Encoding.pair "test1" . Data.Aeson.toEncoding) test1 <>
|
||||
( maybe mempty (Data.Aeson.Encoding.pair "$test3" . Data.Aeson.toEncoding) test3 <>
|
||||
maybe mempty (Data.Aeson.Encoding.pair "test1" . Data.Aeson.toEncoding) test1 <>
|
||||
maybe mempty (Data.Aeson.Encoding.pair "test2" . Data.Aeson.toEncoding) abcdef
|
||||
)
|
||||
|
||||
instance Data.Aeson.FromJSON Test where
|
||||
parseJSON = Data.Aeson.withObject "Test" $ \o ->
|
||||
Test
|
||||
<$> o Data.Aeson..:? "test1"
|
||||
<$> o Data.Aeson..:? "$test3"
|
||||
<*> o Data.Aeson..:? "test1"
|
||||
<*> o Data.Aeson..:? "test2"
|
||||
---------------------
|
||||
test.cabal
|
||||
|
Loading…
Reference in New Issue
Block a user