Skip to content

Commit

Permalink
Add paths with get requests for tables WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
laurenceisla committed Jan 23, 2024
1 parent 315e9fb commit 43092d3
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
66 changes: 66 additions & 0 deletions sql/openapi.sql
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,69 @@ $$
'externalValue', externalValue
);
$$;

create or replace function oas_path_item_object(
ref text default null,
summary text default null,
description text default null,
get jsonb default null,
put jsonb default null,
post jsonb default null,
delete jsonb default null,
options jsonb default null,
head jsonb default null,
patch jsonb default null,
trace jsonb default null,
servers jsonb default null,
parameters jsonb default null
)
returns jsonb language sql as
$$
select json_build_object(
'$ref', ref,
'summary', summary,
'description', description,
'get', get,
'put', put,
'post', post,
'delete', delete,
'options', options,
'head', head,
'patch', patch,
'trace', trace,
'servers', servers,
'parameters', parameters
)
$$;

create or replace function oas_operation_object(
tags text[] default null,
summary text default null,
description text default null,
externalDocs jsonb default null,
operationId text default null,
parameters jsonb default null,
requestBody jsonb default null,
responses jsonb default null,
callbacks jsonb default null,
deprecated boolean default null,
security jsonb default null,
servers jsonb default null
)
returns jsonb language sql as
$$
select json_build_object(
'tags', tags,
'summary', summary,
'description', description,
'externalDocs', externalDocs,
'operationId', operationId,
'parameters', parameters,
'requestBody', requestBody,
'responses', responses,
'callbacks', callbacks,
'deprecated', deprecated,
'security', security,
'servers', servers
)
$$;
32 changes: 32 additions & 0 deletions sql/paths.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- Functions to build the Paths Object of the OAS document

create or replace function oas_build_paths(
path_name text,
path_item_object jsonb,
schemas text[]
)
returns jsonb language sql as
$$
select json_build_object(
'/' || path_name, path_item_object
)
$$;

create or replace function oas_build_path_items_from_tables(schemas text[])
returns jsonb language sql as
$$
select jsonb_object_agg(x.path, x.oas_path_item)
from (
select '/' || table_name as path,
oas_path_item_object(
description := table_description,
get :=oas_operation_object(
parameters := jsonb_build_array(
oas_build_reference_to_parameters('')
)
)
) as oas_path_item
from postgrest_get_all_tables(schemas)
where table_schema = any(schemas)
) x;
$$;
8 changes: 8 additions & 0 deletions sql/utils.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ $$
'#/components/schemas/' || "schema"
);
$$;

create or replace function oas_build_reference_to_parameters(parameter text)
returns jsonb language sql immutable as
$$
select oas_reference_object(
'#/components/parameters/' || parameter
);
$$;

0 comments on commit 43092d3

Please sign in to comment.