Skip to content
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

Servant docs curl #1401

Merged
merged 16 commits into from
Aug 19, 2021
Merged

Conversation

dfithian
Copy link
Contributor

@dfithian dfithian commented Mar 12, 2021

Optionally generate sample cURL requests from the Servant description. There's a breaking change which requires manual changes of headers to supply a sample value.

I have updated greet.hs and greet.md with the changes.

@dfithian
Copy link
Contributor Author

I'm sorry but I don't understand how this build failed: https://travis-ci.org/github/haskell-servant/servant/jobs/762651210

Everything says it exited with exit code 0, but the overall process failed somehow?

@dfithian
Copy link
Contributor Author

Okay it looks like it failed compiling servant-quickcheck (I figured out I had to expand the portion of the log under "building with tests and benchmarks".

Screen Shot 2021-03-15 at 2 40 09 PM

But if I'm not mistaken this is from a different package and it's only compiled as part of cookbook-testing.

@akhesaCaro
Copy link
Contributor

akhesaCaro commented Mar 16, 2021

Hi Dan,

Thanks for your contribution.

The CI is actually in an unstable state. We need to fix it before you being able to pass all checks on it (we are moving out from Travis). (see this)

This one will also need to be merged because of the dependency loop between servant-quickcheck and servant.

I will keep you in touch.

@dfithian
Copy link
Contributor Author

@akhesaCaro just wondering, any feedback I should address?

@dfithian
Copy link
Contributor Author

Hi @akhesaCaro sorry to keep pinging you, but I'm just wondering if you've seen this?

@akhesaCaro
Copy link
Contributor

I am sorry @dfithian , I haven't had the time to study your PR yet.

@hkailahi
Copy link

hkailahi commented Apr 8, 2021

Awesome, very excited for this!

@gdeest gdeest force-pushed the servant-docs-curl branch from 9346d42 to d0a2cc2 Compare April 10, 2021 13:44
@gdeest gdeest force-pushed the servant-docs-curl branch from d0a2cc2 to c00fe3b Compare April 10, 2021 13:52
@dfithian
Copy link
Contributor Author

Hi! The activity on this PR is a little dead. Any things I should do to make it acceptable to merge?

@dfithian
Copy link
Contributor Author

dfithian commented Jun 1, 2021

@gdeest @akhesaCaro what needs to be done to get this PR in?
@haskell-servant/maintainers

@alpmestan
Copy link
Contributor

alpmestan commented Jun 16, 2021

Lovely idea. This seems to be a breaking change, so will require a major bump, but it does look fine to me. Perhaps @akhesaCaro will have some feedback when she gets a chance to look into this.

@dfithian
Copy link
Contributor Author

I don't really understand why there hasn't even been a review. If you don't want a change, or you have feedback, all you have to do is comment. Saying "this change isn't welcome" is fine with me, if that's actually the feeling. If there's something to be done to actually make it acceptable, it would be great to get that feedback.

@dfithian
Copy link
Contributor Author

@akhesaCaro would love to get your thoughts.

@alpmestan
Copy link
Contributor

@dfithian The reason you haven't got a review is the simplest possible, we've all been quite busy I'm afraid. I know this isn't ideal from a contributor's perspective, but for the past 6 years now, the biggest challenge has been to have enough people around to deal with the various (and welcome!) bug reports and contributions at a reasonable pace. In fact I'm one of the original authors but had to take a break from the project at some point because I couldn't handle the activity anymore, in addition to my personal & professional life, after having spent hundreds of evenings over the years on dealing with various servant related things (bugs, reviews, patches, helping out users). I only recently started coming back to the project.

I don't mean to complain by saying this, most definitely not. I'm just trying to find a way to say that your contributions are most definitely welcome, and that the delay in giving them the right amount of focus and care is not due to the patch or you, but simply (and perhaps disappointingly, for you) the bandwidth of the people who are currently volunteering their time to help keep things running around here.

More help would definitely be welcome, of course. I'll nonetheless try to find a bit of time (tonight?) to do a careful review of your patch, depending on how much time my kids give me. :-)

Copy link
Contributor

@alpmestan alpmestan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just have a small question.

mkHeaderStr (hdrName, hdrVal) =
" -H '" ++ cs (CI.original hdrName) ++ ": " ++
cs hdrVal ++ "' \\"
mkReqBodyStr (_, _, body) = " -d " ++ cs body ++ " \\"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this correctly escape the request body in case it contains "s?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great point. Same with the headers. However I think it's up to the implementor to escape those quotes in the ToSample instance. Do you agree?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, well proper escaping will take place for whatever content types are relevant for the request/response bodies (e.g "s are escaped in sample JSON bodies), so I would be inclined to say that the escaping would be fine. But since you're more familiar with this patch than myself for obvious reasons, I was essentially asking for your confirmation. It simply occurred to me that your patch was introducing bash escaping to the mix.

And indeed the same question stands for headers.

(I don't think relying on each sample doing things right is the best way out of this question though.)

Copy link
Contributor Author

@dfithian dfithian Jul 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why the body would be different in this case than in the case where an actual request was being sent, meaning that I expect that quotes would be escaped correctly.

I tested this out, and in fact it doesn't quite do the correct thing; with a (pretty) JSON body, it did something like this:

  -d {
      "foo": "bar"
  } \

So I think we should actually wrap it in single quotes - then we won't have to worry about escaping " anyway. I think I was fooled by the Greet example because it was a JSON string.

Edit: And we don't have to worry about the headers - I checked, and they already are wrapped in single quotes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be good now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we wrap everything up in single quote, are we sure things will go smoothly in the presence of single quotes inside e.g the request body?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. If there are single quotes inside a JSON request body, they'll show up in the snippet unescaped.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, is there something we can do to guarantee that people will be able to copy/paste any curl commands produced by this code and have it work? This is really the last blocker for me, for this PR, which is otherwise ready to land. Sorry to be a bit of a PITA here, but I'm just thinking about the scenario where in a professional setting people start generating docs with this but other folks in the company would complain about commands not working, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I could use double quotes and escape double quotes in the block. I'm always wary of doing these things by hand but I'll give it a try

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, done, and greet.md updated.

@dfithian
Copy link
Contributor Author

I totally understand that maintainers are busy! I was just hoping for some update saying "yes, we think this is a good/bad change" - that way I could either close it if it was bad or know that someone was thinking about it if it was good. However, a review is even better! Thanks so much!

@alpmestan
Copy link
Contributor

@dfithian I did voice my enthusiasm back some time ago =) I really meant it. Auto-generated curl commands is a lovely thing to have, I tend to enjoy seeing those in the docs of HTTP APIs that I use.

Anyway I'm happy that everything's fine now and that your patch is on its way to master, once the escaping business is settled.

Copy link
Contributor

@alpmestan alpmestan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot! This is ready to land AFAICT. CI running now, if it passes I'll merge.

@alpmestan alpmestan merged commit 47bd252 into haskell-servant:master Aug 19, 2021
@dfithian dfithian deleted the servant-docs-curl branch August 19, 2021 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants