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

Update APIs #348

Merged
merged 4 commits into from
Oct 7, 2020
Merged

Update APIs #348

merged 4 commits into from
Oct 7, 2020

Conversation

wasabigeek
Copy link
Contributor

Found a few updates while working on #347

@dblock
Copy link
Collaborator

dblock commented Oct 3, 2020

Minor suggestion @wasabigeek - after you make a code change you realize that you want to fix something, or maybe add a changelog line. I usually git add . ; git commit --amend the previous commit and then git push origin branch -f, this keeps the change in a single commit. I know force pushes are discouraged, but in this case I think it's a better workflow.

@dblock
Copy link
Collaborator

dblock commented Oct 3, 2020

Looks like we have a bug in a spec generator that produces 'who_can_post': ... or something weird like that?

@wasabigeek
Copy link
Contributor Author

Will take a look in a bit!

@@ -12,7 +12,7 @@ RSpec.describe Slack::Web::Api::Endpoints::<%= group.gsub(".", "_").camelize %>
context '<%= group %>_<%= name %>' do
<% required_params.each do |arg_name, arg_v| %>
it 'requires <%= arg_name %>' do
<% params_except_required = required_params.reject{ |name, _| name == arg_name }.map{|var, opts| "#{var}: '#{opts['example']}'"}.join(', ') %>
<% params_except_required = required_params.reject{ |name, _| name == arg_name }.map{|var, opts| "#{var}: '#{opts['example'].gsub("'", '"')}'"}.join(', ') %>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ugh. This is to handle an arg like:

"args": {
    "prefs": {
      "required": true,
      "example": "{'who_can_post':'type:admin,user:U1234,subteam:S1234'}",
      "desc": "The prefs for this channel in a stringified JSON format."
    }
  },

Which gets rendered as (prefs: '{'who_can_post':'type:admin,user:U1234,subteam:S1234'}') in the spec, breaking the tests.

There doesn't seem to be a less intrusive way to fix this. I could write a custom spec, but that seemed like it would skip auto-generation entirely for that endpoint, so it would probably drift pretty quickly. Do you have any suggestions @dblock?

Copy link
Contributor Author

@wasabigeek wasabigeek Oct 4, 2020

Choose a reason for hiding this comment

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

Some possibilities:

  • do the substitution upstream in slack-api-ref, so it ends up like {\"who_can_post\": ...} instead
  • create an object for each json instead of rebuilding it into a hash, so we can encapsulate the sanitization logic and make it more readable (e.g. WebApiMethod.args could sanitize and return the string)

Copy link
Collaborator

Choose a reason for hiding this comment

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

This will generate false positives and will mangle examples in the future if they contain single quotes within the String itself. And we'll never catch it.

I think this should really be "#{opts['example']}", which will work for everything. Then Rubocop will get upset, so a rubocop -a will auto-correct " into ' where appropriate. You could also do that by checking whether the string contains any ' and using " if so instead of gsub.

Copy link
Contributor Author

@wasabigeek wasabigeek Oct 7, 2020

Choose a reason for hiding this comment

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

To clarify, the suggestion is to have a manual step to correct such cases?

Copy link
Collaborator

Choose a reason for hiding this comment

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

For rubocop? Thinking about it i don't love it. I'll merge and we can fix this later.

Copy link
Collaborator

Choose a reason for hiding this comment

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

#349, what do you think?

@dblock dblock merged commit 401a2b4 into slack-ruby:master Oct 7, 2020
@wasabigeek wasabigeek deleted the api-update branch October 11, 2020 03:03
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.

2 participants