From 4ca661da3ddd7fba39686bbb35c494e152b04336 Mon Sep 17 00:00:00 2001 From: Jonathan Siegel <248302+usiegj00@users.noreply.github.com> Date: Sat, 25 May 2024 08:57:06 +0900 Subject: [PATCH 1/2] 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. --- .../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 3e4dc1668554..1a00af1b1160 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.nil? || @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 087b17ba8272..0f65b5403847 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.nil? || @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}" From 9b4b189bbb6f3b7adb344b6ae1151a554e936f90 Mon Sep 17 00:00:00 2001 From: Jonathan Siegel <248302+usiegj00@users.noreply.github.com> Date: Sat, 25 May 2024 09:10:02 +0900 Subject: [PATCH 2/2] 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 1a00af1b1160..52678bd87821 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.try &.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 0f65b5403847..73a53433dec0 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.try &.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}"