From 77365c34fa8980e64cb5ae7bf0fda0d1bfeafae8 Mon Sep 17 00:00:00 2001 From: Jonathan Siegel <248302+usiegj00@users.noreply.github.com> Date: Sun, 26 May 2024 12:44:07 +0900 Subject: [PATCH] [crystal-lang] Resolve type check compile error in ApiError (#18759) * Even with .nil? typecheck, compiler still fails due to .empty? call on nillable type. This appears a poor implementation issue by crystal-lang, but this explicit try avoids the issue for now. * Made call more succinct. --- .../src/main/resources/crystal/api_error.mustache | 2 +- samples/client/petstore/crystal/src/petstore/api_error.cr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/crystal/api_error.mustache b/modules/openapi-generator/src/main/resources/crystal/api_error.mustache index 3e4dc166855..52678bd8782 100644 --- a/modules/openapi-generator/src/main/resources/crystal/api_error.mustache +++ b/modules/openapi-generator/src/main/resources/crystal/api_error.mustache @@ -21,7 +21,7 @@ module {{moduleName}} msg = "" msg = msg + "\nHTTP status code: #{code}" if @code msg = msg + "\nResponse headers: #{response_headers}" if @response_headers - if @message.nil? || @message.empty? + if @message.try &.empty? msg = msg + "\nError message: the server returns an error but the HTTP response body is empty." else msg = msg + "\nResponse body: #{@message}" diff --git a/samples/client/petstore/crystal/src/petstore/api_error.cr b/samples/client/petstore/crystal/src/petstore/api_error.cr index 087b17ba827..73a53433dec 100644 --- a/samples/client/petstore/crystal/src/petstore/api_error.cr +++ b/samples/client/petstore/crystal/src/petstore/api_error.cr @@ -29,7 +29,7 @@ module Petstore msg = "" msg = msg + "\nHTTP status code: #{code}" if @code msg = msg + "\nResponse headers: #{response_headers}" if @response_headers - if @message.nil? || @message.empty? + if @message.try &.empty? msg = msg + "\nError message: the server returns an error but the HTTP response body is empty." else msg = msg + "\nResponse body: #{@message}"