Skip to content

Commit

Permalink
Apply typeNameModifier to fields within interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasjm committed Nov 14, 2023
1 parent 0d0f4b2 commit 0c62a92
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change log

## Unreleased

* Apply `typeNameModifier` to type names emitted on the RHS of fields within interfaces, for consistency.

## 0.6.0.0

Expand Down
6 changes: 3 additions & 3 deletions src/Data/Aeson/TypeScript/Formatting.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ formatTSDeclaration (FormattingOptions {..}) (TSInterfaceDeclaration interfaceNa
ls = T.intercalate "\n" $ [indentTo numIndentSpaces (T.pack (formatTSField member <> ";")) | member <- members]
modifiedInterfaceName = (\(li, name) -> li <> interfaceNameModifier name) . splitAt 1 $ interfaceName

formatTSField :: TSField -> String
formatTSField (TSField optional name typ maybeDoc) = makeDocPrefix maybeDoc <> [i|#{name}#{if optional then ("?" :: String) else ""}: #{typeNameModifier typ}|]

formatTSDeclaration _ (TSRawDeclaration text) = text

indentTo :: Int -> T.Text -> T.Text
Expand Down Expand Up @@ -89,9 +92,6 @@ validateFormattingOptions options@FormattingOptions{..} decls
-- Units (data U = U) contain two declarations, and thus are invalid
isPlainSumType ds = (not . any isInterface $ ds) && length ds == 1

formatTSField :: TSField -> String
formatTSField (TSField optional name typ maybeDoc) = makeDocPrefix maybeDoc <> [i|#{name}#{if optional then ("?" :: String) else ""}: #{typ}|]

makeDocPrefix :: Maybe String -> String
makeDocPrefix maybeDoc = case maybeDoc of
Nothing -> ""
Expand Down

0 comments on commit 0c62a92

Please sign in to comment.