fix: Detect default values for String types in OpenAPI output (#1928)

This commit is contained in:
laurenceisla
2021-08-27 21:59:54 -05:00
committed by GitHub
parent ed98ac9d7e
commit ed5072f4b1
5 changed files with 80 additions and 1 deletions
+12 -1
View File
@@ -65,8 +65,19 @@ toSwaggerType "bigint" = SwaggerInteger
toSwaggerType "numeric" = SwaggerNumber
toSwaggerType "real" = SwaggerNumber
toSwaggerType "double precision" = SwaggerNumber
toSwaggerType "ARRAY" = SwaggerArray
toSwaggerType _ = SwaggerString
parseDefault :: Text -> Text -> Text
parseDefault colType colDefault =
case toSwaggerType colType of
SwaggerString -> wrapInQuotations $ case T.stripSuffix ("::" <> colType) colDefault of
Just def -> T.dropAround (=='\'') def
Nothing -> colDefault
_ -> colDefault
where
wrapInQuotations text = "\"" <> text <> "\""
makeTableDef :: [Relationship] -> [PrimaryKey] -> (Table, [Column], [Text]) -> (Text, Schema)
makeTableDef rels pks (t, cs, _) =
let tn = tableName t in
@@ -107,7 +118,7 @@ makeProperty rels pks c = (colName c, Inline s)
colDescription c
s =
(mempty :: Schema)
& default_ .~ (JSON.decode . toS =<< colDefault c)
& default_ .~ (JSON.decode . toS . parseDefault (colType c) =<< colDefault c)
& description .~ d
& enum_ .~ e
& format ?~ colType c