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

Fix JSON of Slack sample responses #17

Open
mre opened this issue Mar 7, 2017 · 8 comments
Open

Fix JSON of Slack sample responses #17

mre opened this issue Mar 7, 2017 · 8 comments

Comments

@mre
Copy link
Collaborator

mre commented Mar 7, 2017

The sample responses from the official Slack documentation are often invalid JSON.
For example, check files.upload (because of '...') or im.history (because of a trailing comma in the second message).

Given that slackhq/slack-api-docs is currently not receiving any updates, we should fix that on our side.

I was looking into possible solutions. Unfortunately I did not find any pure-Ruby solution yet. Do you know of any? JSON is tricky to fix automatically. The two most promising solutions I found are:

Both projects promise automatic fixing of JSON.
Since eslint/eslint is well-maintained and offers lots of fixes, I would go with that.

Heads up:

  • Javascript Runtime required.
  • eslint fixes files in-place. We would need to call it from the commandline.

Here is an example of how I would integrate it. I'm not really happy about the code but I couldn't come up with anything better either.

If you like the idea then I would go ahead and integrate it.
Otherwise I'm open for suggestions.

@mre
Copy link
Collaborator Author

mre commented Mar 8, 2017

Tested eslint and it would fix the trailing commas.

@mre
Copy link
Collaborator Author

mre commented Mar 8, 2017

Alternatively we could write a simple Ruby class which fixes only the errors that we encounter during parsing. Namely:

  • trailing commas
  • unquoted strings (e.g. '...')

Advantages:

  • Simple
  • Pure Ruby
  • Easy to integrate

Disadvantages:

  • will not cover other issues

@dblock
Copy link
Collaborator

dblock commented Mar 8, 2017

Really slack should fix those, I do suggest opening at least a ticket.

In the meantime since it's a hack I would use whatever.

@dblock
Copy link
Collaborator

dblock commented Mar 9, 2017

Btw, @mre work on your fork, don't create branches here and cleanup the merged ones? This way we keep this repo clean.

@mre
Copy link
Collaborator Author

mre commented Apr 27, 2017

Just wanted to add some feedback about my attempts to fix this issue. I've tried to fix the JSON syntax errors with eslint, but there are just too many different error cases. I also tried to add some simple heuristics (basically applying some regular expressions before running eslint), but as expected that made things even more fragile.
As of now I don't see an easy way to make this happen. If anybody else wants to give it a shot, I'd be more than happy to brainstorm on ideas. It would be really great to have this, as it would bring me one step closer towards a fully auto-generated Slack client for Rust.

@dblock
Copy link
Collaborator

dblock commented Apr 27, 2017

Maybe opening issues with Slack and asking them to provide working examples? Or providing alternate hand-written working examples here that overwrite the worst ones?

@mre
Copy link
Collaborator Author

mre commented Apr 28, 2017

Thanks @dblock,
I could add hand-written examples but I could not keep them up-to-date, so that's why I didn't do it.
I've added a comment to the issue referenced above. Let's see. 👍

@duffn
Copy link
Contributor

duffn commented Jun 11, 2022

There is a comment here from a Slack team member regarding fixing im.history slackhq/slack-api-docs#74 (comment) and the examples I checked from slackhq/slack-api-docs#73 are now valid JSON.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants