From e90b6e581a0af48594f1af36eea32cd9ef52ed35 Mon Sep 17 00:00:00 2001 From: Laurence Isla Date: Fri, 19 Jan 2024 11:46:32 -0500 Subject: [PATCH] Fix Reference Object funcion definition --- sql/components.sql | 64 +++++++++++++++++++++++----------------------- sql/openapi.sql | 11 +++++--- sql/postgrest.sql | 8 +++--- 3 files changed, 44 insertions(+), 39 deletions(-) diff --git a/sql/components.sql b/sql/components.sql index a3a545a..6d98098 100644 --- a/sql/components.sql +++ b/sql/components.sql @@ -292,9 +292,9 @@ select jsonb_build_object( description := 'Specify a required or optional behavior for the request', "schema" := oas_schema_object( allOf := jsonb_build_array( - oas_reference_object('header.preferHandling'), - oas_reference_object('header.preferTimezone'), - oas_reference_object('header.preferCount') + oas_reference_object('#/components/schemas/header.preferHandling'), + oas_reference_object('#/components/schemas/header.preferTimezone'), + oas_reference_object('#/components/schemas/header.preferCount') ) ), examples := jsonb_build_object( @@ -321,13 +321,13 @@ select jsonb_build_object( description := 'Specify a required or optional behavior for the request', "schema" := oas_schema_object( allOf := jsonb_build_array( - oas_reference_object('header.preferHandling'), - oas_reference_object('header.preferTimezone'), - oas_reference_object('header.preferReturn'), - oas_reference_object('header.preferCount'), - oas_reference_object('header.preferResolution'), - oas_reference_object('header.preferMissing'), - oas_reference_object('header.preferTx') + oas_reference_object('#/components/schemas/header.preferHandling'), + oas_reference_object('#/components/schemas/header.preferTimezone'), + oas_reference_object('#/components/schemas/header.preferReturn'), + oas_reference_object('#/components/schemas/header.preferCount'), + oas_reference_object('#/components/schemas/header.preferResolution'), + oas_reference_object('#/components/schemas/header.preferMissing'), + oas_reference_object('#/components/schemas/header.preferTx') ) ), examples := jsonb_build_object( @@ -358,12 +358,12 @@ select jsonb_build_object( description := 'Specify a required or optional behavior for the request', "schema" := oas_schema_object( allOf := jsonb_build_array( - oas_reference_object('header.preferHandling'), - oas_reference_object('header.preferTimezone'), - oas_reference_object('header.preferReturn'), - oas_reference_object('header.preferCount'), - oas_reference_object('header.preferTx'), - oas_reference_object('header.preferMaxAffected') + oas_reference_object('#/components/schemas/header.preferHandling'), + oas_reference_object('#/components/schemas/header.preferTimezone'), + oas_reference_object('#/components/schemas/header.preferReturn'), + oas_reference_object('#/components/schemas/header.preferCount'), + oas_reference_object('#/components/schemas/header.preferTx'), + oas_reference_object('#/components/schemas/header.preferMaxAffected') ) ), examples := jsonb_build_object( @@ -393,11 +393,11 @@ select jsonb_build_object( description := 'Specify a required or optional behavior for the request', "schema" := oas_schema_object( allOf := jsonb_build_array( - oas_reference_object('header.preferHandling'), - oas_reference_object('header.preferTimezone'), - oas_reference_object('header.preferReturn'), - oas_reference_object('header.preferCount'), - oas_reference_object('header.preferTx') + oas_reference_object('#/components/schemas/header.preferHandling'), + oas_reference_object('#/components/schemas/header.preferTimezone'), + oas_reference_object('#/components/schemas/header.preferReturn'), + oas_reference_object('#/components/schemas/header.preferCount'), + oas_reference_object('#/components/schemas/header.preferTx') ) ), examples := jsonb_build_object( @@ -426,12 +426,12 @@ select jsonb_build_object( description := 'Specify a required or optional behavior for the request', "schema" := oas_schema_object( allOf := jsonb_build_array( - oas_reference_object('header.preferHandling'), - oas_reference_object('header.preferTimezone'), - oas_reference_object('header.preferReturn'), - oas_reference_object('header.preferCount'), - oas_reference_object('header.preferTx'), - oas_reference_object('header.preferMaxAffected') + oas_reference_object('#/components/schemas/header.preferHandling'), + oas_reference_object('#/components/schemas/header.preferTimezone'), + oas_reference_object('#/components/schemas/header.preferReturn'), + oas_reference_object('#/components/schemas/header.preferCount'), + oas_reference_object('#/components/schemas/header.preferTx'), + oas_reference_object('#/components/schemas/header.preferMaxAffected') ) ), examples := jsonb_build_object( @@ -461,11 +461,11 @@ select jsonb_build_object( description := 'Specify a required or optional behavior for the request', "schema" := oas_schema_object( allOf := jsonb_build_array( - oas_reference_object('header.preferHandling'), - oas_reference_object('header.preferTimezone'), - oas_reference_object('header.preferCount'), - oas_reference_object('header.preferTx'), - oas_reference_object('header.preferParams') + oas_reference_object('#/components/schemas/header.preferHandling'), + oas_reference_object('#/components/schemas/header.preferTimezone'), + oas_reference_object('#/components/schemas/header.preferCount'), + oas_reference_object('#/components/schemas/header.preferTx'), + oas_reference_object('#/components/schemas/header.preferParams') ) ), examples := jsonb_build_object( diff --git a/sql/openapi.sql b/sql/openapi.sql index d8963d3..2402934 100644 --- a/sql/openapi.sql +++ b/sql/openapi.sql @@ -179,12 +179,17 @@ $$ ) $$; --- TODO: should be a Reference Object and not only for "components/schemas" -create or replace function oas_reference_object(ref text) +create or replace function oas_reference_object( + ref text, + summary text default null, + description text default null +) returns jsonb language sql as $$ select json_build_object( - '$ref', '#/components/schemas/' || ref + '$ref', ref, + 'summary', summary, + 'description', description ); $$; diff --git a/sql/postgrest.sql b/sql/postgrest.sql index 06d343d..3bb12d8 100644 --- a/sql/postgrest.sql +++ b/sql/postgrest.sql @@ -106,7 +106,7 @@ WITH jsonb_object_agg( info.column_name, case when info.is_composite then - oas_reference_object(info.data_type) + oas_reference_object('#/components/schemas/' || info.data_type) else oas_schema_object( description := info.description, @@ -120,7 +120,7 @@ WITH when not info.is_array then null when info.item_is_composite then - oas_reference_object(info.item_data_type) + oas_reference_object('#/components/schemas/' || info.item_data_type) else oas_schema_object( type := pgtype_to_oastype(info.item_data_type), @@ -396,7 +396,7 @@ WITH jsonb_object_agg( info.column_name, case when info.is_composite then - oas_reference_object(info.data_type) + oas_reference_object('#/components/schemas/' || info.data_type) else oas_schema_object( description := info.description, @@ -410,7 +410,7 @@ WITH when not info.is_array then null when info.item_is_composite then - oas_reference_object(info.item_data_type) + oas_reference_object('#/components/schemas/' || info.item_data_type) else oas_schema_object( type := pgtype_to_oastype(info.item_data_type),