-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutils.sql
58 lines (52 loc) · 1.81 KB
/
utils.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
-- Functions that help in building the OpenAPI spec inside PostgreSQL
create or replace function postgrest_pgtype_to_oastype(type text)
returns text language sql immutable as
$$
select case when type like any(array['character', 'character varying', 'text']) then 'string'
when type like any(array['double precision', 'numeric', 'real']) then 'number'
when type like any(array['bigint', 'integer', 'smallint']) then 'integer'
when type like 'boolean' then 'boolean'
when type like '%[]' then 'array'
when type like any(array['json', 'jsonb', 'record']) then 'object'
else 'string' end;
$$;
create or replace function postgrest_unfold_comment(comm text) returns text[]
language sql immutable as
$$
select array[
substr(comm, 0, break_position),
trim(leading from substr(comm, break_position), '
') -- trims newlines and empty spaces
]
from (select strpos(comm, '
') as break_position)_;
$$;
create or replace function oas_build_reference_to_schemas("schema" text)
returns jsonb language sql immutable as
$$
select oas_reference_object(
'#/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
);
$$;
create or replace function oas_build_reference_to_request_bodies(req_body text)
returns jsonb language sql immutable as
$$
select oas_reference_object(
ref := '#/components/requestBodies/' || req_body
);
$$;
create or replace function oas_build_reference_to_responses(response text, descrip text default null)
returns jsonb language sql immutable as
$$
select oas_reference_object(
ref := '#/components/responses/' || response,
description := descrip
);
$$;