Skip to content

[crystal-lang] Update dependencies to remedy build failure#18755

Merged
wing328 merged 2 commits intoOpenAPITools:masterfrom
usiegj00:crystal-update-shards
May 26, 2024
Merged

[crystal-lang] Update dependencies to remedy build failure#18755
wing328 merged 2 commits intoOpenAPITools:masterfrom
usiegj00:crystal-update-shards

Conversation

@usiegj00
Copy link
Contributor

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

  • Read the contribution guidelines.
  • 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.
  • 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.
  • 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)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@wing328
Copy link
Member

wing328 commented May 24, 2024

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
Copy link
Member

wing328 commented May 24, 2024

cc @cyangle

@usiegj00 usiegj00 force-pushed the crystal-update-shards branch from a541d96 to bb404a9 Compare May 24, 2024 09:24
@usiegj00
Copy link
Contributor Author

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

@wing328
Copy link
Member

wing328 commented May 26, 2024

tested locally and the result is good.

will file another PR to update the tests accordingly

@wing328 wing328 merged commit e6f3729 into OpenAPITools:master May 26, 2024
@wing328 wing328 added this to the 7.7.0 milestone May 26, 2024
@wing328
Copy link
Member

wing328 commented May 26, 2024

merged follow-up PR (#18766) to update the tests

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants