diff --git a/gen/src/Gen/Text.hs b/gen/src/Gen/Text.hs index e8061d22c71..20df0dbf52d 100644 --- a/gen/src/Gen/Text.hs +++ b/gen/src/Gen/Text.hs @@ -6,7 +6,7 @@ module Gen.Text renameOperation, renameServiceFunction, renameService, - renameBranch, + renameEnumValue, renameReserved, lowerHead, upperHead, @@ -54,8 +54,8 @@ renameService = . stripPrefix "Service" . stripSuffix "SDK" -renameBranch :: Text -> (Text, Text) -renameBranch = first go . join (,) +renameEnumValue :: Text -> (Text, Text) +renameEnumValue v = (go v, v) where go = Text.map (\c -> if Char.isAlphaNum c then c else '_') . upperHead @@ -129,16 +129,16 @@ toCamelCase = toCamelCase' . Text.split (not . Char.isAlphaNum) . Text.dropWhile lowerHead :: Text -> Text lowerHead text | Text.all (\c -> Char.isUpper c || Char.isDigit c) text = - Text.toLower text + Text.toLower text | otherwise = - fromMaybe (mapHead Char.toLower text) - . msum - $ map - (\acronym -> mappend (Text.toLower acronym) <$> Text.stripPrefix acronym text) - [ "KMS", - "DB", - "MFA" - ] + fromMaybe (mapHead Char.toLower text) + . msum + $ map + (\acronym -> mappend (Text.toLower acronym) <$> Text.stripPrefix acronym text) + [ "KMS", + "DB", + "MFA" + ] upperHead :: Text -> Text upperHead = mapHead Char.toUpper diff --git a/gen/src/Gen/Types/Service.hs b/gen/src/Gen/Types/Service.hs index e4ff4e3310e..206cb7d0f1b 100644 --- a/gen/src/Gen/Types/Service.hs +++ b/gen/src/Gen/Types/Service.hs @@ -322,7 +322,7 @@ instance FromJSON (ShapeF ()) where parseJSON = Aeson.withObject "shape" $ \o -> do i <- Aeson.parseJSON (Aeson.Object o) t <- o .: "type" - m <- o .:? "enum" + enum <- o .:? "enum" ts <- o .:? "timestampFormat" case t of @@ -338,9 +338,10 @@ instance FromJSON (ShapeF ()) where "boolean" -> pure (Lit i Bool) "timestamp" -> pure (Lit i (Time ts)) "json" -> pure (Lit i Json) - "string" -> pure (maybe (Lit i Text) f m) - where - f = Enum i . HashMap.fromList . map (first mkId . renameBranch) + "string" -> pure $ case enum of + Nothing -> Lit i Text + Just values -> + Enum i . HashMap.fromList $ map (first mkId . renameEnumValue) values _ -> fail $ "Unknown Shape type: " ++ Text.unpack t data Operation f a b = Operation