fix: use int32/int64 formats for integer types

Fixed integer type mapping in OpenAPI 2.0: replaced the invalid integer format with int32/int64 and added the toSwaggerFormat function to map PostgreSQL types to valid OpenAPI 2.0 formats:

smallint -> int32
integer -> int32
bigint -> int64
This commit is contained in:
Artur Bento de Carvalho
2026-04-03 16:36:55 -05:00
committed by Steve Chavez
parent 250747aadc
commit 0d4d1dca51
4 changed files with 30 additions and 20 deletions
+4
View File
@@ -8,6 +8,10 @@ All notable changes to this project will be documented in this file. From versio
- Log a `HINT` when the LISTEN channel stops working due to a PostgreSQL bug by @laurenceisla in #4581
### Fixed
- Fix invalid OpenAPI 2.0 format for integer types (`smallint`, `integer`, `bigint`) by @arturbent0 in #4641
## [14.7] - 2026-03-20
### Fixed
+10 -4
View File
@@ -73,6 +73,12 @@ toSwaggerType colType = case T.takeEnd 2 colType of
"[]" -> Just SwaggerArray
_ -> Just SwaggerString
toSwaggerFormat :: Text -> Maybe Text
toSwaggerFormat "smallint" = Just "int32"
toSwaggerFormat "integer" = Just "int32"
toSwaggerFormat "bigint" = Just "int64"
toSwaggerFormat colType = Just colType
typeFromArray :: Text -> Text
typeFromArray = T.dropEnd 2
@@ -141,7 +147,7 @@ makeProperty tbl rels col = (colName col, Inline s)
& default_ .~ (JSON.decode . toUtf8Lazy . parseDefault (colType col) =<< colDefault col)
& description .~ d
& enum_ .~ e
& format ?~ colType col
& format .~ toSwaggerFormat (colType col)
& maxLength .~ (fromIntegral <$> colMaxLen col)
& type_ .~ toSwaggerType (colType col)
& items .~ (SwaggerItemsObject <$> makePropertyItems (colType col))
@@ -160,7 +166,7 @@ makeProcProperty (RoutineParam n t _ _ _) = (n, Inline s)
s = (mempty :: Schema)
& type_ .~ toSwaggerType t
& items .~ (SwaggerItemsObject <$> makePropertyItems t)
& format ?~ t
& format .~ toSwaggerFormat t
makePreferParam :: [Text] -> Param
makePreferParam ts =
@@ -192,14 +198,14 @@ makeProcGetParam (RoutineParam n t _ r v) =
baseSchema = (mempty :: ParamOtherSchema)
& in_ .~ ParamQuery
schemaNotMulti = baseSchema
& format ?~ t
& format .~ toSwaggerFormat t
& type_ ?~ toParamType (toSwaggerType t)
schemaMulti = baseSchema
& type_ ?~ fromMaybe SwaggerString (toSwaggerType t)
& items ?~ SwaggerItemsPrimitive (Just CollectionMulti)
((mempty :: ParamSchema x)
& type_ .~ toSwaggerTypeFromArray t
& format ?~ typeFromArray t)
& format .~ toSwaggerFormat (typeFromArray t))
toParamType paramType = case paramType of
-- Array uses {} in query params
Just SwaggerArray -> SwaggerString
+12 -12
View File
@@ -157,7 +157,7 @@ spec = describe "OpenAPI" $ do
"properties": {
"id": {
"description": "child_entities id comment\n\nNote:\nThis is a Primary Key.<pk/>",
"format": "integer",
"format": "int32",
"type": "integer"
},
"name": {
@@ -167,7 +167,7 @@ spec = describe "OpenAPI" $ do
},
"parent_id": {
"description": "Note:\nThis is a Foreign Key to `entities.id`.<fk table='entities' column='id'/>",
"format": "integer",
"format": "int32",
"type": "integer"
}
},
@@ -192,7 +192,7 @@ spec = describe "OpenAPI" $ do
"properties": {
"id": {
"description": "child_entities_view id comment\n\nNote:\nThis is a Primary Key.<pk/>",
"format": "integer",
"format": "int32",
"type": "integer"
},
"name": {
@@ -202,7 +202,7 @@ spec = describe "OpenAPI" $ do
},
"parent_id": {
"description": "Note:\nThis is a Foreign Key to `entities.id`.<fk table='entities' column='id'/>",
"format": "integer",
"format": "int32",
"type": "integer"
}
}
@@ -232,7 +232,7 @@ spec = describe "OpenAPI" $ do
referralLink `shouldBe` Just
[aesonQQ|
{
"format": "integer",
"format": "int32",
"type": "integer",
"description": "Note:\nThis is a Foreign Key to `second.id`.<fk table='second' column='id'/>"
}
@@ -337,7 +337,7 @@ spec = describe "OpenAPI" $ do
referralLink `shouldBe` Just
[aesonQQ|
{
"format": "integer",
"format": "int32",
"type": "integer",
"description": "Note:\nThis is a Foreign Key to `pages.link`.<fk table='pages' column='link'/>"
}
@@ -354,7 +354,7 @@ spec = describe "OpenAPI" $ do
referralLink `shouldBe` Just
[aesonQQ|
{
"format": "integer",
"format": "int32",
"type": "integer",
"description": "Note:\nThis is a Foreign Key to `clients.id`.<fk table='clients' column='id'/>"
}
@@ -432,7 +432,7 @@ spec = describe "OpenAPI" $ do
types `shouldBe` Just
[aesonQQ|
{
"format": "smallint",
"format": "int32",
"type": "integer"
}
|]
@@ -447,7 +447,7 @@ spec = describe "OpenAPI" $ do
types `shouldBe` Just
[aesonQQ|
{
"format": "integer",
"format": "int32",
"type": "integer"
}
|]
@@ -462,7 +462,7 @@ spec = describe "OpenAPI" $ do
types `shouldBe` Just
[aesonQQ|
{
"format": "bigint",
"format": "int64",
"type": "integer"
}
|]
@@ -850,7 +850,7 @@ spec = describe "OpenAPI" $ do
"type": "string"
},
{
"format": "integer",
"format": "int32",
"in": "query",
"name": "integer",
"required": false,
@@ -992,7 +992,7 @@ spec = describe "OpenAPI" $ do
"items": {}
},
"integer": {
"format": "integer",
"format": "int32",
"type": "integer"
},
"json": {
@@ -281,7 +281,7 @@ spec =
"properties" : {
"id" : {
"description" : "Note:\nThis is a Primary Key.<pk/>",
"format" : "integer",
"format" : "int32",
"type" : "integer"
},
"name" : {
@@ -310,7 +310,7 @@ spec =
"properties" : {
"id" : {
"description" : "Note:\nThis is a Primary Key.<pk/>",
"format" : "integer",
"format" : "int32",
"type" : "integer"
},
"name" : {
@@ -339,7 +339,7 @@ spec =
"properties" : {
"id" : {
"description" : "Note:\nThis is a Primary Key.<pk/>",
"format" : "integer",
"format" : "int32",
"type" : "integer"
},
"name" : {
@@ -368,7 +368,7 @@ spec =
"properties" : {
"id" : {
"description" : "Note:\nThis is a Primary Key.<pk/>",
"format" : "integer",
"format" : "int32",
"type" : "integer"
},
"another_value" : {