From 2b46afe1ec23feeb40eb2981fc8681d829cad9d6 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Mon, 23 Jul 2018 18:11:45 +0200 Subject: [PATCH] OpenAPI: add required section for the non-nullable columns (#1148) --- CHANGELOG.md | 1 + src/PostgREST/OpenAPI.hs | 3 ++- test/Feature/StructureSpec.hs | 5 ++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d3df9478..22b2f8c91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - #1099, Add support for getting json/jsonb by array index - @steve-chavez - #1145, Add materialized view columns to OpenAPI output - @steve-chavez - #709, Allow embedding on views with subselects/CTE - @steve-chavez +- #1148, OpenAPI: add `required` section for the non-nullable columns - @laughedelic ### Fixed diff --git a/src/PostgREST/OpenAPI.hs b/src/PostgREST/OpenAPI.hs index 865b7da3a..99b76ae8a 100644 --- a/src/PostgREST/OpenAPI.hs +++ b/src/PostgREST/OpenAPI.hs @@ -42,7 +42,8 @@ makeTableDef pks (t, cs, _) = (tn, (mempty :: Schema) & description .~ tableDescription t & type_ .~ SwaggerObject - & properties .~ fromList (map (makeProperty pks) cs)) + & properties .~ fromList (map (makeProperty pks) cs) + & required .~ map colName (filter (not . colNullable) cs)) makeProperty :: [PrimaryKey] -> Column -> (Text, Referenced Schema) makeProperty pks c = (colName c, Inline s) diff --git a/test/Feature/StructureSpec.hs b/test/Feature/StructureSpec.hs index 435e0686f..8089086b5 100644 --- a/test/Feature/StructureSpec.hs +++ b/test/Feature/StructureSpec.hs @@ -113,7 +113,10 @@ spec = do "format": "integer", "type": "integer" } - } + }, + "required": [ + "id" + ] } |]