line / line-bot-sdk-ruby

LINE Messaging API SDK for Ruby
https://developers.line.biz/en/docs/messaging-api/overview/
Apache License 2.0
479 stars 128 forks source link

Generate clients from LINE OpenAPI #296

Closed zenizh closed 6 months ago

zenizh commented 1 year ago

I generated clients according to the definition of LINE OpenAPI using OpenAPI Generator. I also set up the workflow for GitHub Actions and other related tasks.

Policy of change

This PR uses the OpenAPI Generator to build clients. The OpenAPI Generator generates clients as gems, which means it generates as many gems as there are clients.

On the other hand, we want a single gem, line-bot-api. So we ignore the auto-generated files that we need as a gem with .gitignore.

This makes it work as a single gem by reading each client entry point from lib/line/client.rb.

I will also add a script called bin/generate-clients. This helps to generate clients in the local environment and is also used to generate clients on GitHub Actions.

Change details

The main files changed in this PR are:

File Overview
bin/generate-clients Script to generate clients
lib/clients List of generated clients
lib/line/client.rb Load the client list
.github/workflows/generate-clients.yml Generate client on GitHub Actions -> Set up PR
spec Minimal testing to ensure there are no dependency issues
src/main/resources/ruby-client/README.mustache Override the generated client README
.gitignore Define unnecessary files for generated clients
Gemfile Remove unnecessary dependencies
README.md Rewritten for this change
line-bot-spi.gemspec Organizing dependencies

How to review

Due to the large number of files in the difference, it is easier to review the PR source branch: https://github.com/zenizh/line-bot-sdk-ruby/tree/openapi


This pull request resolves #292, resolves #283, resolves #282, resolves #255, resolves #252, resolves #251, resolves #244, resolves #232, resolves #191.

zenizh commented 1 year ago

To maintain compatibility with previous versions, I have made the following commit. This allows methods from previous versions to be used without modification, while still displaying the warning message. https://github.com/line/line-bot-sdk-ruby/pull/296/commits/c8b141cc781cdb0679f51ccf10c54892ef57174c

tokuhirom commented 1 year ago

validate_signature method should be implemented in the latest version.

tokuhirom commented 1 year ago

I guess, generated codes in lib/clients/webhook doesn't support deserializing webhook's payload. req = LINE::Client::Webhook::CalbackRequest.new(JSON.parse(request_body)) won't parse Hash object to nested object. I mean, req is instance of LINE::Client::Webhook::CalbackRequest. But req.events[0] is just Hash, not an instance of the LINE::Client::Webhook::Event.

It's suprising.

zenizh commented 11 months ago

I added the following code:

tokuhirom commented 11 months ago

https://github.com/zenizh/line-bot-sdk-ruby/blob/openapi/lib/clients/channel-access-token/lib/line_client_channel_access_token/api/channel_access_token_api.rb#L237-L283

is bit strange.

This endpoint has two functionalities: 'Issue from channel ID and channel secret' and 'Issue from JWT assertion.'

For 'Issue from channel ID and channel secret,' you need to make the request with 'grant_type,' 'client_id,' and 'client_secret.'

For 'Issue from JWT assertion,' you need to make the request with 'grant_type,' 'client_assertion_type,' and 'client_assertion.'

The OpenAPI definition specifies that one of these requests is required: link to the OpenAPI definition.

However, in this PR, all the required parameters for both patterns are listed, and there are a few issues:

  1. It's defined as [String] in the RDoc, which means nil cannot be passed.
  2. Due to client-side validation like here, you are required to provide valid values for parameters even if you are not using them in one of the patterns."
zenizh commented 6 months ago

This pull request will be submitted as a new pull request, so it is closed for now.