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
Update OpenAPI (SQL COMMENT to description, constraints, cleaning up) #885
Conversation
You know I'm really not an OpenAPI expert. I think wherever you want the comments to appear in the output is probably a great start. Perhaps other people can chime in here. Just doing the hard part of obtaining those comments and putting them somewhere is wonderful, and it will be easier to tweak later on as people have suggestions as they use it. Having some repetition seems OK. The output can be pretty huge anyway, and I'd rather have API consumers notice the comments than overlook them. I do like the idea of allowing a schema comment to override the generic API description placeholder. Also regarding your side note, feel free to try removing unused instances and cleaning up the code. My philosophy is that if the existing tests keep passing then we should be good. Thanks for jumping in and working on this! I know people have wanted it for a while. Once you add some tests and a changelog entry we can look into getting this merged. Anybody with opinions please add a comment. |
…tablename.{get,post,put,delete}.description with Table description
I learned from previous work that when the openapi test times out it is actually failing because of malformed openapi output. Not sure why it does't just return an error. In the past I copied the output into an online validator to get a useful error message. |
I know the test suite isn't very helpful when it fails for OpenAPI validation. Let's see if we can work together to figure out the problem. I checked out your branch, built it, and ran postgrest against the database schema created by our test suite. I was able to get more information about the validation failure by copying the openapi output into http://bigstickcarpet.com/swagger-parser/www/index.html :
Does this error help? |
Oh, that seems easy to fix, |
That discussion would affect another major version anyway, and we still may keep the openapi description but use content negotiation (the Accept request header) to show it rather than show it by default. Also extracting sql comments into our in-memory data structure will be useful no matter how we output the api description so carry on! |
I tried using the tool you linked but I had no chance with it, when I click "Validate it!", a pretty-print of the description shows up in a box that shakes for a second and nothing else happens/shows up, where did you get those error messages? On another note, I've been slowly reading the OpenAPI spec, it seems most of the repetition can be abstracted away using global definitions. I'll probably make the output less "precise" but smaller by removing the enums/patterns generated with columns/operators Also: I was interested in using Vendor Extensions for FK/PK/constraints but they're not supported by hackage's swagger2 :( |
How the output looks after the removal of all duplication: https://gist.github.com/ldesgoui/faecf9fec35e150f67be1cb7843c1f7e |
Misclick, sorry 😦 |
The new output looks really nice, I can actually read it directly rather than the old avalanche of text. Great work! Did you manage to figure out the validator I was using? Looks like the tests are failing on the most recent commit except this time they are giving a real error message rather than just hanging. |
I did, yes, the output is valid now. The tests fail because they need to be updated to reflect changes |
Hey, I'm done with this PR, here's a recap:
|
src/PostgREST/OpenAPI.hs
Outdated
colDescription c | ||
s = | ||
(mempty :: Schema) | ||
& default_ .~ (decode . TL.encodeUtf8 . TL.fromStrict =<< colDefault c) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to use the more generic toS
to convert the string types? Something like
default_ .~ (decode . toS =<< colDefault c)
Not sure if it can infer the types, but thought I'd ask.
Thanks for all your work to research this and finish it! |
My pleasure, postgrest is pure joy to use in projects :) |
"type": "string" | ||
}, | ||
"parent_id": { | ||
"description": "Note:\nThis is a Foreign Key to `entities.id`.<fk table='entities' column='id'/>", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ldesgoui I've always wondered.. Where does the <fk>
and <pk>
tags come from?
If I remember correctly, those are basically a hack to insert metadata
about what we generate, they don't "exist" and don't get through markdown
generation. Probably should have looked for a better way
…On Thu, Aug 27, 2020, 15:58 Steve Chavez ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In test/Feature/StructureSpec.hs
<#885 (comment)>:
> + {
+ "type": "object",
+ "description": "child_entities comment",
+ "properties": {
+ "id": {
+ "description": "child_entities id comment\n\nNote:\nThis is a Primary Key.<pk/>",
+ "format": "integer",
+ "type": "integer"
+ },
+ "name": {
+ "description": "child_entities name comment",
+ "format": "text",
+ "type": "string"
+ },
+ "parent_id": {
+ "description": "Note:\nThis is a Foreign Key to `entities.id`.<fk table='entities' column='id'/>",
@ldesgoui <https://github.com/ldesgoui> I've always wondered.. Where does
the <fk> and <pk> tags come from?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#885 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAS3VZQCMPAKW43OFN3GWXTSCZQ7VANCNFSM4DN3XBIQ>
.
|
@ldesgoui I see, thanks for the quick reply! According to OAI/OpenAPI-Specification#587, another way of specifying the pk/fk would be with OpenAPI extensions. |
Greetings,
This PR addresses the idea raised in #222.
I launched the PR to ask feedback: what do you feel deserves change in the current OpenAPI generation ?
To do before completion:
Most of this seems trivial and should be accomplished soon :)
Side note:
I've updated the ToJSON instances but I don't think they're used anywhere, maybe they could get removed? (EDIT: removed now)
What about fluffing up the hard-coded OpenAPI options a little more while I'm at it ? They're not the most welcoming in the world and could definitely redirect developers to postgrest.com documentation
Links:
Postgres SQL Comments
PostgraphQL's introspection query