-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OpenAPI spec as input #2792
Comments
Some issues with the openAPI spec:
|
Disregarding problem 3 and 4 for now. Also the openapi spec. I think we can solve 1 and 2 using the Say I want to only allow -- pgrst.query_grammar is the config prefix
-- '*' is the default "allow all"
-- ' ' empty is "disallow all"
select set_config('pgrst.query_grammar.op', ' ', true);
-- op.eq is the allowlist for columns
select set_config('pgrst.query_grammar.op.eq', array_agg(c.table_name || '.' || c.column_name)::text, true)
from information_schema.table_constraints tc
join information_schema.constraint_column_usage as ccu using (constraint_schema, constraint_name)
join information_schema.columns as c
on c.table_schema = tc.constraint_schema and tc.table_name = c.table_name and ccu.column_name = c.column_name
where constraint_type = 'PRIMARY KEY' and c.table_schema = 'test';
select current_setting('pgrst.query_grammar.op.eq') as eq_allowed;
eq_allowed | {items.id,items2.id,items3.id,clients.id,compound_pk.k1,compound_pk.k2,.. A similar config can be used for select set_config('pgrst.query_grammar.order', 'table.col ', true); I think that's so far the best interface for solving 1 and 2. It provides a lot of flexibility and removes smartness from the config format. It can be wrapped in a function too. create or replace function pgrst_query_grammar()
returns void as $$
select set_config('pgrst.query_grammar.op', '', true);
select set_config('pgrst.query_grammar.op.eq', array_agg(c.table_name || '.' || c.column_name)::text, true)
--...
$$ language sql; |
Closing and following up on #2805 |
Problem
Database as Single Source of Truth has its limitations for an API.
We have tried hard to encode these concerns in the database itself:
pgrst.accept
setting to RPC #1582 (comment).While 3 and 4 have viable solutions(4 being specially clever and sound), these still feel like concerns that shouldn't be in the database. We just need a way to add metadata.
Solution
Accept an OpenAPI spec as input. It can be a file or also live in the database as a function(
db-openapi-input
). The user can take our generated OpenAPI as a blueprint and modify it to its needs.Let's say we have an
employees
table, our generated OpenAPI can be:(using YAML as it's simpler)
(Note: using openapi extensions)
To solve each case:
parameters
from the spec.order
. e.g.enum: [id, name]
x-pg-table
.x-pgrst-rep
in the spec. A specificx-pg-function
can be used per resource and per media type. It can also be DRYed up by using$ref
.For cases where there's a big OpenAPI, we can optionally store the spec contents in a table so it's easier to edit. This table can finally produce the openapi spec using a json_agg.
The text was updated successfully, but these errors were encountered: