openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[crystal-lang] Update dependencies to remedy build failure

Open usiegj00 opened this issue 1 year ago • 3 comments

This is an extremely straightforward change that bumps the version of Kemal and Crest in order to fix a build error after a shards update. The issue experienced is a failure for the generated client library to run due to an error in the dependent library http_proxy. This library is in a unusable state in version 0.8.1 due to a function prototype mismatch with its provided argument types. For review @wing328.

An OpenAPI-Generator user using the Crystal Language generator will experience a backtrace like this when using the current generator:

$ crystal build src/cli.cr --error-trace 
In src/cli.cr:50:6
 50 | main.execute ARGV
           ^------
Error: instantiating 'CLI#execute(Array(String))'

In lib/cling/src/cling/command.cr:182:16
 182 | Executor.handle self, results
                ^-----
Error: instantiating 'Cling::Executor.handle(Build::CLI, Array(Cling::Parser::Result))'

In lib/cling/src/cling/executor.cr:59:24
 59 | resolved_command.run executed.parsed_arguments, executed.parsed_options
                       ^--
Error: instantiating 'Cling::Command+#run(Cling::Arguments, Cling::Options)'

In src/commands/whoami.cr:13:20
 13 | puts api.api_v1_me_get.email
               ^------------
Error: instantiating 'OpenAPIClient::DefaultApi#api_v1_me_get()'

In lib/openapi_client/src/openapi_client/api/default_api.cr:349:38
 349 | data, _status_code, _headers = api_v1_me_get_with_http_info()
                                      ^---------------------------
Error: instantiating 'api_v1_me_get_with_http_info()'

In lib/openapi_client/src/openapi_client/api/default_api.cr:382:48
 382 | data, status_code, headers = @api_client.call_api(:GET,
                                                ^-------
Error: instantiating 'OpenAPIClient::ApiClient#call_api(Symbol, String, Symbol, String, Nil, Array(String), Hash(String, String), Hash(String, String), Hash(Symbol, File | String))'

In lib/openapi_client/src/openapi_client/api_client.cr:160:26
 160 | response = request.execute
                          ^------
Error: instantiating 'Crest::Request#execute()'

In lib/crest/src/crest/request.cr:174:20
 174 | @http_client.set_proxy(@proxy)
                    ^--------
Error: instantiating 'HTTP::Client#set_proxy((HTTP::Proxy::Client | Nil))'

In lib/http_proxy/src/ext/http/client.cr:11:21
 11 | @io = proxy.open(
                  ^---
Error: no overload matches 'HTTP::Proxy::Client#open', host: String, port: Int32, tls: (OpenSSL::SSL::Context::Client | Nil), dns_timeout: (Time::Span | Nil), connect_timeout: (Time::Span | Nil), read_timeout: (Time::Span | Nil)

Overloads are:
 - HTTP::Proxy::Client#open(host, port, tls = nil, *, dns_timeout : ::Float64 | ::Nil, connect_timeout : ::Float64 | ::Nil, read_timeout : ::Float64 | ::Nil)
Couldn't find overloads for these types:
 - HTTP::Proxy::Client#open(host : String, port : Int32, tls : Nil, dns_timeout : Time::Span, connect_timeout : Time::Span, read_timeout : Time::Span)
 - HTTP::Proxy::Client#open(host : String, port : Int32, tls : Nil, dns_timeout : Time::Span, connect_timeout : Time::Span, read_timeout : Nil)
 - HTTP::Proxy::Client#open(host : String, port : Int32, tls : Nil, dns_timeout : Time::Span, connect_timeout : Nil, read_timeout : Time::Span)
 - HTTP::Proxy::Client#open(host : String, port : Int32, tls : Nil, dns_timeout : Time::Span, connect_timeout : Nil, read_timeout : Nil)
 - HTTP::Proxy::Client#open(host : String, port : Int32, tls : Nil, dns_timeout : Nil, connect_timeout : Time::Span, read_timeout : Time::Span)
 - HTTP::Proxy::Client#open(host : String, port : Int32, tls : Nil, dns_timeout : Nil, connect_timeout : Time::Span, read_timeout : Nil)
 - HTTP::Proxy::Client#open(host : String, port : Int32, tls : Nil, dns_timeout : Nil, connect_timeout : Nil, read_timeout : Time::Span)
 - HTTP::Proxy::Client#open(host : String, port : Int32, tls : OpenSSL::SSL::Context::Client, dns_timeout : Time::Span, connect_timeout : Time::Span, read_timeout : Time::Span)
 - HTTP::Proxy::Client#open(host : String, port : Int32, tls : OpenSSL::SSL::Context::Client, dns_timeout : Time::Span, connect_timeout : Time::Span, read_timeout : Nil)
 - HTTP::Proxy::Client#open(host : String, port : Int32, tls : OpenSSL::SSL::Context::Client, dns_timeout : Time::Span, connect_timeout : Nil, read_timeout : Time::Span)
 - HTTP::Proxy::Client#open(host : String, port : Int32, tls : OpenSSL::SSL::Context::Client, dns_timeout : Time::Span, connect_timeout : Nil, read_timeout : Nil)
 - HTTP::Proxy::Client#open(host : String, port : Int32, tls : OpenSSL::SSL::Context::Client, dns_timeout : Nil, connect_timeout : Time::Span, read_timeout : Time::Span)
 - HTTP::Proxy::Client#open(host : String, port : Int32, tls : OpenSSL::SSL::Context::Client, dns_timeout : Nil, connect_timeout : Time::Span, read_timeout : Nil)
 - HTTP::Proxy::Client#open(host : String, port : Int32, tls : OpenSSL::SSL::Context::Client, dns_timeout : Nil, connect_timeout : Nil, read_timeout : Time::Span)

The root cause is the definition of time variables as Float64 in http_proxy's client.cr version 0.8.1.

module HTTP
  # :nodoc:
  module Proxy
    # Represents a proxy client with all its attributes.
    # Provides convenient access and modification of them.
    class Client
      getter host : String
      getter port : Int32
      property username : String?
      property password : String?
      property headers : HTTP::Headers

      getter tls : OpenSSL::SSL::Context::Client?

      @dns_timeout : Float64?
      @connect_timeout : Float64?
      @read_timeout : Float64?

This conflicts with the same library's prototype which has implied type of Time::Span instead of Float64 client.cr.

module HTTP
  class Client
    getter proxy : Bool = false

    def set_proxy(proxy : HTTP::Proxy::Client?)
      return unless proxy
  
      begin
        @io = proxy.open(
          host: @host,
          port: @port,
          tls: @tls,
          dns_timeout: @dns_timeout,
          connect_timeout: @connect_timeout,
          read_timeout: @read_timeout
        )

PR checklist

  • [X] Read the contribution guidelines.
  • [X] Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • [X] Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    (For Windows users, please run the script in Git BASH) Commit all changed files. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • [X] File the PR against the correct branch: master (upcoming 7.6.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • [X] If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

usiegj00 avatar May 24 '24 07:05 usiegj00

Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors.

Let me know if you need help fixing it.

Ref: https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-can-i-update-commits-that-are-not-linked-to-my-github-account

wing328 avatar May 24 '24 09:05 wing328

cc @cyangle

wing328 avatar May 24 '24 09:05 wing328

Thank you! I've amended the commits to show my minor contributions.

usiegj00 avatar May 24 '24 09:05 usiegj00

tested locally and the result is good.

will file another PR to update the tests accordingly

wing328 avatar May 26 '24 03:05 wing328

merged follow-up PR (https://github.com/OpenAPITools/openapi-generator/pull/18766) to update the tests

wing328 avatar May 26 '24 03:05 wing328