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 14:21:32 -05:00
committed by GitHub
parent a5e66a4448
commit 69c6a0aa36
4 changed files with 30 additions and 20 deletions
+4
View File
@@ -22,6 +22,10 @@ All notable changes to this project will be documented in this file. From versio
- Log error when `db-schemas` config contains schema `pg_catalog` or `information_schema` by @taimoorzaeem in #4359 - Log error when `db-schemas` config contains schema `pg_catalog` or `information_schema` by @taimoorzaeem in #4359
+ Now fails at startup. Prior to this, it failed with `PGRST205` on requests related to these schemas. + Now fails at startup. Prior to this, it failed with `PGRST205` on requests related to these schemas.
### Fixed
- Fix invalid OpenAPI 2.0 format for integer types (`smallint`, `integer`, `bigint`) by @arturbent0 in #4641
## [14.7] - 2026-03-20 ## [14.7] - 2026-03-20
### Fixed ### Fixed
+10 -4
View File
@@ -73,6 +73,12 @@ toSwaggerType colType = case T.takeEnd 2 colType of
"[]" -> Just SwaggerArray "[]" -> Just SwaggerArray
_ -> Just SwaggerString _ -> 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 :: Text -> Text
typeFromArray = T.dropEnd 2 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) & default_ .~ (JSON.decode . toUtf8Lazy . parseDefault (colType col) =<< colDefault col)
& description .~ d & description .~ d
& enum_ .~ e & enum_ .~ e
& format ?~ colType col & format .~ toSwaggerFormat (colType col)
& maxLength .~ (fromIntegral <$> colMaxLen col) & maxLength .~ (fromIntegral <$> colMaxLen col)
& type_ .~ toSwaggerType (colType col) & type_ .~ toSwaggerType (colType col)
& items .~ (SwaggerItemsObject <$> makePropertyItems (colType col)) & items .~ (SwaggerItemsObject <$> makePropertyItems (colType col))
@@ -160,7 +166,7 @@ makeProcProperty (RoutineParam n t _ _ _) = (n, Inline s)
s = (mempty :: Schema) s = (mempty :: Schema)
& type_ .~ toSwaggerType t & type_ .~ toSwaggerType t
& items .~ (SwaggerItemsObject <$> makePropertyItems t) & items .~ (SwaggerItemsObject <$> makePropertyItems t)
& format ?~ t & format .~ toSwaggerFormat t
makePreferParam :: [Text] -> Param makePreferParam :: [Text] -> Param
makePreferParam ts = makePreferParam ts =
@@ -192,14 +198,14 @@ makeProcGetParam (RoutineParam n t _ r v) =
baseSchema = (mempty :: ParamOtherSchema) baseSchema = (mempty :: ParamOtherSchema)
& in_ .~ ParamQuery & in_ .~ ParamQuery
schemaNotMulti = baseSchema schemaNotMulti = baseSchema
& format ?~ t & format .~ toSwaggerFormat t
& type_ ?~ toParamType (toSwaggerType t) & type_ ?~ toParamType (toSwaggerType t)
schemaMulti = baseSchema schemaMulti = baseSchema
& type_ ?~ fromMaybe SwaggerString (toSwaggerType t) & type_ ?~ fromMaybe SwaggerString (toSwaggerType t)
& items ?~ SwaggerItemsPrimitive (Just CollectionMulti) & items ?~ SwaggerItemsPrimitive (Just CollectionMulti)
((mempty :: ParamSchema x) ((mempty :: ParamSchema x)
& type_ .~ toSwaggerTypeFromArray t & type_ .~ toSwaggerTypeFromArray t
& format ?~ typeFromArray t) & format .~ toSwaggerFormat (typeFromArray t))
toParamType paramType = case paramType of toParamType paramType = case paramType of
-- Array uses {} in query params -- Array uses {} in query params
Just SwaggerArray -> SwaggerString Just SwaggerArray -> SwaggerString
+12 -12
View File
@@ -157,7 +157,7 @@ spec = describe "OpenAPI" $ do
"properties": { "properties": {
"id": { "id": {
"description": "child_entities id comment\n\nNote:\nThis is a Primary Key.<pk/>", "description": "child_entities id comment\n\nNote:\nThis is a Primary Key.<pk/>",
"format": "integer", "format": "int32",
"type": "integer" "type": "integer"
}, },
"name": { "name": {
@@ -167,7 +167,7 @@ spec = describe "OpenAPI" $ do
}, },
"parent_id": { "parent_id": {
"description": "Note:\nThis is a Foreign Key to `entities.id`.<fk table='entities' column='id'/>", "description": "Note:\nThis is a Foreign Key to `entities.id`.<fk table='entities' column='id'/>",
"format": "integer", "format": "int32",
"type": "integer" "type": "integer"
} }
}, },
@@ -192,7 +192,7 @@ spec = describe "OpenAPI" $ do
"properties": { "properties": {
"id": { "id": {
"description": "child_entities_view id comment\n\nNote:\nThis is a Primary Key.<pk/>", "description": "child_entities_view id comment\n\nNote:\nThis is a Primary Key.<pk/>",
"format": "integer", "format": "int32",
"type": "integer" "type": "integer"
}, },
"name": { "name": {
@@ -202,7 +202,7 @@ spec = describe "OpenAPI" $ do
}, },
"parent_id": { "parent_id": {
"description": "Note:\nThis is a Foreign Key to `entities.id`.<fk table='entities' column='id'/>", "description": "Note:\nThis is a Foreign Key to `entities.id`.<fk table='entities' column='id'/>",
"format": "integer", "format": "int32",
"type": "integer" "type": "integer"
} }
} }
@@ -232,7 +232,7 @@ spec = describe "OpenAPI" $ do
referralLink `shouldBe` Just referralLink `shouldBe` Just
[aesonQQ| [aesonQQ|
{ {
"format": "integer", "format": "int32",
"type": "integer", "type": "integer",
"description": "Note:\nThis is a Foreign Key to `second.id`.<fk table='second' column='id'/>" "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 referralLink `shouldBe` Just
[aesonQQ| [aesonQQ|
{ {
"format": "integer", "format": "int32",
"type": "integer", "type": "integer",
"description": "Note:\nThis is a Foreign Key to `pages.link`.<fk table='pages' column='link'/>" "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 referralLink `shouldBe` Just
[aesonQQ| [aesonQQ|
{ {
"format": "integer", "format": "int32",
"type": "integer", "type": "integer",
"description": "Note:\nThis is a Foreign Key to `clients.id`.<fk table='clients' column='id'/>" "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 types `shouldBe` Just
[aesonQQ| [aesonQQ|
{ {
"format": "smallint", "format": "int32",
"type": "integer" "type": "integer"
} }
|] |]
@@ -447,7 +447,7 @@ spec = describe "OpenAPI" $ do
types `shouldBe` Just types `shouldBe` Just
[aesonQQ| [aesonQQ|
{ {
"format": "integer", "format": "int32",
"type": "integer" "type": "integer"
} }
|] |]
@@ -462,7 +462,7 @@ spec = describe "OpenAPI" $ do
types `shouldBe` Just types `shouldBe` Just
[aesonQQ| [aesonQQ|
{ {
"format": "bigint", "format": "int64",
"type": "integer" "type": "integer"
} }
|] |]
@@ -850,7 +850,7 @@ spec = describe "OpenAPI" $ do
"type": "string" "type": "string"
}, },
{ {
"format": "integer", "format": "int32",
"in": "query", "in": "query",
"name": "integer", "name": "integer",
"required": false, "required": false,
@@ -992,7 +992,7 @@ spec = describe "OpenAPI" $ do
"items": {} "items": {}
}, },
"integer": { "integer": {
"format": "integer", "format": "int32",
"type": "integer" "type": "integer"
}, },
"json": { "json": {
@@ -281,7 +281,7 @@ spec =
"properties" : { "properties" : {
"id" : { "id" : {
"description" : "Note:\nThis is a Primary Key.<pk/>", "description" : "Note:\nThis is a Primary Key.<pk/>",
"format" : "integer", "format" : "int32",
"type" : "integer" "type" : "integer"
}, },
"name" : { "name" : {
@@ -310,7 +310,7 @@ spec =
"properties" : { "properties" : {
"id" : { "id" : {
"description" : "Note:\nThis is a Primary Key.<pk/>", "description" : "Note:\nThis is a Primary Key.<pk/>",
"format" : "integer", "format" : "int32",
"type" : "integer" "type" : "integer"
}, },
"name" : { "name" : {
@@ -339,7 +339,7 @@ spec =
"properties" : { "properties" : {
"id" : { "id" : {
"description" : "Note:\nThis is a Primary Key.<pk/>", "description" : "Note:\nThis is a Primary Key.<pk/>",
"format" : "integer", "format" : "int32",
"type" : "integer" "type" : "integer"
}, },
"name" : { "name" : {
@@ -368,7 +368,7 @@ spec =
"properties" : { "properties" : {
"id" : { "id" : {
"description" : "Note:\nThis is a Primary Key.<pk/>", "description" : "Note:\nThis is a Primary Key.<pk/>",
"format" : "integer", "format" : "int32",
"type" : "integer" "type" : "integer"
}, },
"another_value" : { "another_value" : {