Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upOpen API ignores pg type comment #1377
Comments
|
The reason seems to be postgrest/src/PostgREST/OpenAPI.hs Lines 40 to 51 in 713b214 having a predefined list of supported types, where everything else is treated as a string. And also postgrest/src/PostgREST/OpenAPI.hs Lines 97 to 102 in 713b214 which doesn't support objects. If the function is immutable, it would be accessible via a GET request, which would probably need to be modeled somehow in Swagger to match query strings like I'd assume what's in your comment should simply be infered from the type. No need for a comment with type definitions. Regarding your title: I initially thought you meant a Postgres PROCEDURE introduced in v11. Took me a while to figure out you meant your FUNCTION argument type total_user_acquisition_search_type didn't get added correctly. I have never written a line of Haskell in my life, so I probably can't help you though. |
|
Thanks this is what I finally done ;)
Stephen ZAMBAUX
0680114469
[image: Mailtrack]
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
Sender
notified by
Mailtrack
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
27/08/19
à 15:39:38
Le mar. 27 août 2019 à 15:36, Steve Chávez <notifications@github.com> a
écrit :
… Thanks for the help here @nerfpops <https://github.com/nerfpops>. You're
right in that we default to a string for unknown pg types.
@fstn <https://github.com/fstn> I see you want to document the function
arguments. As a workaround, perhaps you could COMMENT on the function
instead?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1377?email_source=notifications&email_token=AAWNAGLINIPDWJUDWPUJUF3QGV64HA5CNFSM4ILPTKYKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5I36KA#issuecomment-525451048>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAWNAGOW5SFRZDN226LMIQDQGV64HANCNFSM4ILPTKYA>
.
|
|
Hi @steve-chavez, thank you so much for all the work you put into this project. I see that you renamed the issue, but shouldn't postgrest ideally spit out a schema matching the function signature, even with composite types? |
|
I thought this would be a simple starter issue for learning Haskell, but it seems to not be that easy after all. I'm trying to figure out how to add type comments in openapi, but to do so, I'm imagining something like the following will have to be done... Currently, these values are preloaded: postgrest/src/PostgREST/DbStructure.hs Lines 58 to 66 in 713b214 wouldn't it make sense to preload all the types as well, with their comments? PgType would need to contain all the required information for a type, and no longer just a QualifiedIdentifier postgrest/src/PostgREST/Types.hs Line 88 in 713b214 My noob skills in Haskell is going to show it's ugly face here, but to enable us to print comments, and also the type information, PgType would need to look something like this: data PgTypeDescription = PgTypeDescription {
ptdSchema :: Text
, ptdName :: Text
, ptdDescription :: Maybe Text
} deriving (Eq, Show, Ord)
-- Base type name in Postgres (text/jsonb/uuid/...)
data PgBaseType = Text deriving (Eq, Show, Ord)
data PgType
= Scalar PgTypeDescription PgBaseType
| Composite PgTypeDescription [PgType]
deriving (Eq, Show, Ord)With When preloading types, it must be each and every type in the database, since you can reference any type outside the public schema. Would this be a viable approach? Edit: On second thought, I'll probably get in trouble with circular references, if I add data PgTypeDescription = PgTypeDescription {
ptdSchema :: Text
, ptdName :: Text
, ptdDescription :: Maybe Text
} deriving (Eq, Show, Ord)
data PgType
= Scalar PgTypeDescription
| Composite PgTypeDescription
deriving (Eq, Show, Ord) |
|
@nerfpops Seems like a solid approach. You'd need to query pg_type first and then convert to Haskell types. A type can be created on a particular schema. At first I was thinking we should only get the exposed db-schema types. But getting all of the db types seems fine. As a first step it'd be better to focus on getting only the types comments. A nice mapping between the pg type and haskell type could get cumbersome as you mentioned. This could be refined later. |
I declared my procedure as:
When I check the generated open api, I get:
I should have my real search user_acquisition_search_type and the comment I applied on it into the openapi json file instead of nothing.