Skip to content

Commit c01eecc

Browse files
mjgpy3joel-bach
authored andcommitted
Run formatter
1 parent 1116ca1 commit c01eecc

1 file changed

Lines changed: 36 additions & 38 deletions

File tree

  • openapi3-code-generator/src/OpenAPI/Generate

openapi3-code-generator/src/OpenAPI/Generate/Model.hs

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -420,44 +420,42 @@ defineOneOfSchema schemaName description allSchemas discriminator = do
420420
body =
421421
case discriminator of
422422
Just disc -> do
423-
let
424-
fnArgName = mkName "obj"
425-
discriminatorPropertyName = mkName "propertyName"
426-
nonFixedSchemas = zip ([1 .. ] :: [Integer]) $ do
427-
schema <- allSchemas
428-
guard $ E.isLeft $ extractSchemaWithFixedValue FixedValueStrategyExclude schema
429-
pure schema
430-
schemaLookupFromRef = Map.fromList $ do
431-
(n, schema) <- nonFixedSchemas
432-
case schema of
433-
OAT.Reference ref -> [(ref, (n, getSchemaNameFromReference ref))]
434-
OAT.Concrete _ -> []
435-
oneOfSchemaRefs = do
436-
(ref, (_, name')) <- Map.toList schemaLookupFromRef
437-
pure (name', ref)
438-
propertyNamesWithReferences = maybe oneOfSchemaRefs Map.toList $ OAS.discriminatorObjectMapping disc
439-
let
440-
mkMatchedCase (propName, fullRef) =
441-
case Map.lookup fullRef schemaLookupFromRef of
442-
Nothing -> []
443-
Just (n, caseName) -> do
444-
let
445-
suffix = if OAO.settingUseNumberedVariantConstructors settings then "Variant" <> T.pack (show n) else ""
446-
parseConstructor constructorName = [|($(varE constructorName) <$> Aeson.parseJSON $(varE paramName))|]
447-
[match (litP $ stringL $ T.unpack propName) (normalB [|$(parseConstructor $ haskellifyConstructor $ schemaName <> haskellifyPartialConstructor caseName <> suffix)|]) []]
448-
matchedCases = propertyNamesWithReferences >>= mkMatchedCase
449-
unmatchedCase = match (varP $ mkName "_unmatched") (normalB [|fail "No match for discriminator property"|]) []
450-
propertyCases = matchedCases <> [unmatchedCase]
451-
getDiscProp = [|$(varE fnArgName) Aeson..:? $(stringE $ T.unpack $ OAS.discriminatorObjectPropertyName disc)|]
452-
annotatedDiscriminatorPropertyName = [|$(varE discriminatorPropertyName) :: Text|]
453-
withObjectLamda = [|
454-
do
455-
result <- $getDiscProp
456-
case result of
457-
Nothing -> fail "Object lacks discriminator property"
458-
Just $(varP discriminatorPropertyName) ->
459-
$(caseE annotatedDiscriminatorPropertyName propertyCases)
460-
|]
423+
let fnArgName = mkName "obj"
424+
discriminatorPropertyName = mkName "propertyName"
425+
nonFixedSchemas = zip ([1 ..] :: [Integer]) $ do
426+
schema <- allSchemas
427+
guard $ E.isLeft $ extractSchemaWithFixedValue FixedValueStrategyExclude schema
428+
pure schema
429+
schemaLookupFromRef = Map.fromList $ do
430+
(n, schema) <- nonFixedSchemas
431+
case schema of
432+
OAT.Reference ref -> [(ref, (n, getSchemaNameFromReference ref))]
433+
OAT.Concrete _ -> []
434+
oneOfSchemaRefs = do
435+
(ref, (_, name')) <- Map.toList schemaLookupFromRef
436+
pure (name', ref)
437+
propertyNamesWithReferences = maybe oneOfSchemaRefs Map.toList $ OAS.discriminatorObjectMapping disc
438+
let mkMatchedCase (propName, fullRef) =
439+
case Map.lookup fullRef schemaLookupFromRef of
440+
Nothing -> []
441+
Just (n, caseName) -> do
442+
let suffix = if OAO.settingUseNumberedVariantConstructors settings then "Variant" <> T.pack (show n) else ""
443+
parseConstructor constructorName = [|($(varE constructorName) <$> Aeson.parseJSON $(varE paramName))|]
444+
[match (litP $ stringL $ T.unpack propName) (normalB [|$(parseConstructor $ haskellifyConstructor $ schemaName <> haskellifyPartialConstructor caseName <> suffix)|]) []]
445+
matchedCases = propertyNamesWithReferences >>= mkMatchedCase
446+
unmatchedCase = match (varP $ mkName "_unmatched") (normalB [|fail "No match for discriminator property"|]) []
447+
propertyCases = matchedCases <> [unmatchedCase]
448+
getDiscProp = [|$(varE fnArgName) Aeson..:? $(stringE $ T.unpack $ OAS.discriminatorObjectPropertyName disc)|]
449+
annotatedDiscriminatorPropertyName = [|$(varE discriminatorPropertyName) :: Text|]
450+
withObjectLamda =
451+
[|
452+
do
453+
result <- $getDiscProp
454+
case result of
455+
Nothing -> fail "Object lacks discriminator property"
456+
Just $(varP discriminatorPropertyName) ->
457+
$(caseE annotatedDiscriminatorPropertyName propertyCases)
458+
|]
461459
[|Aeson.withObject $(stringE $ T.unpack schemaName) $(lam1E (varP fnArgName) withObjectLamda) $(varE paramName)|]
462460
Nothing -> do
463461
constructorNames' <- sequence constructorNames

0 commit comments

Comments
 (0)