diff --git a/CHANGELOG.md b/CHANGELOG.md index 22b2f8c91..93e63d576 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - #1113, Fix UPSERT failing when having a camel case PK column - @steve-chavez - #945, Fix slow start-up time on big schemas - @steve-chavez - #1129, Fix view embedding when table is capitalized - @steve-chavez +- #1149, OpenAPI: Change `GET` response type to array - @laughedelic ### Changed diff --git a/src/PostgREST/OpenAPI.hs b/src/PostgREST/OpenAPI.hs index 99b76ae8a..a199fd418 100644 --- a/src/PostgREST/OpenAPI.hs +++ b/src/PostgREST/OpenAPI.hs @@ -198,8 +198,11 @@ makePathItem (t, cs, _) = ("/" ++ unpack tn, p $ tableInsertable t) & at 206 ?~ "Partial Content" & at 200 ?~ Inline ((mempty :: Response) & description .~ "OK" - & schema ?~ (Ref $ Reference $ tableName t) + & schema ?~ Inline (mempty + & type_ .~ SwaggerArray + & items ?~ (SwaggerItemsObject $ Ref $ Reference $ tableName t) ) + ) postOp = tOp & parameters .~ map ref ["body." <> tn, "preferReturn"] & at 201 ?~ "Created" diff --git a/test/Feature/StructureSpec.hs b/test/Feature/StructureSpec.hs index 8089086b5..82acd8b4d 100644 --- a/test/Feature/StructureSpec.hs +++ b/test/Feature/StructureSpec.hs @@ -85,6 +85,27 @@ spec = do deleteResponse `shouldBe` Just "No Content" + it "includes an array type for GET responses" $ do + r <- simpleBody <$> get "/" + + let childGetSchema = r ^? key "paths" + . key "/child_entities" + . key "get" + . key "responses" + . key "200" + . key "schema" + + liftIO $ + childGetSchema `shouldBe` Just + [aesonQQ| + { + "items": { + "$ref": "#/definitions/child_entities" + }, + "type": "array" + } + |] + it "includes definitions to tables" $ do r <- simpleBody <$> get "/"