зеркало из https://github.com/microsoft/kiota.git
Merge pull request #2108 from microsoft/feature/ruby-no-response-handler
- moves response handler in ruby
This commit is contained in:
Коммит
7edf187a83
|
@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Fixed a bug where a missing baseURL would make search fail. [#2095](https://github.com/microsoft/kiota/issues/2095)
|
||||
- Fixed a bug in Ruby where the request adapter URL would be overwritten by the client defaults. [#1647](https://github.com/microsoft/kiota/issues/1647)
|
||||
- Replaced concurrent-ruby by Fibers in Ruby libraries to implement proper asynchronous execution of requests.
|
||||
- Replaced response_handler parameter by a request option in Ruby. [#1860](https://github.com/microsoft/kiota/issues/1860)
|
||||
|
||||
## [0.9.0] - 2022-12-19
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ require_relative "microsoft_kiota_abstractions/api_client_builder"
|
|||
require_relative "microsoft_kiota_abstractions/request_adapter"
|
||||
require_relative "microsoft_kiota_abstractions/request_option"
|
||||
require_relative "microsoft_kiota_abstractions/request_information"
|
||||
require_relative "microsoft_kiota_abstractions/response_handler"
|
||||
require_relative "microsoft_kiota_abstractions/version"
|
||||
require_relative "microsoft_kiota_abstractions/serialization/parsable"
|
||||
require_relative "microsoft_kiota_abstractions/serialization/iso_duration"
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
require_relative 'request_information'
|
||||
require_relative 'response_handler'
|
||||
|
||||
module MicrosoftKiotaAbstractions
|
||||
module RequestAdapter
|
||||
|
||||
def send_async(request_info, factory, errors_mapping, response_handler)
|
||||
def send_async(request_info, factory, errors_mapping)
|
||||
raise NotImplementedError.new
|
||||
end
|
||||
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
module MicrosoftKiotaAbstractions
|
||||
module ResponseHandler
|
||||
|
||||
def handle_response_async(response)
|
||||
raise NotImplementedError.new
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module MicrosoftKiotaAbstractions
|
||||
VERSION = "0.9.0"
|
||||
VERSION = "0.10.0"
|
||||
end
|
||||
|
|
|
@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
|
|||
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
||||
spec.require_paths = ['lib']
|
||||
|
||||
spec.add_runtime_dependency 'microsoft_kiota_abstractions', '~> 0.9.0', '>= 0.9.0'
|
||||
spec.add_runtime_dependency 'microsoft_kiota_abstractions', '~> 0.10.0', '>= 0.10.0'
|
||||
spec.add_runtime_dependency 'oauth2', '~> 2.0'
|
||||
spec.add_development_dependency 'rake', '~> 13.0'
|
||||
spec.add_development_dependency 'rspec', '~> 3.0'
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'microsoft_kiota_faraday/version'
|
||||
require_relative 'microsoft_kiota_faraday/middleware/response_handler_option'
|
||||
require_relative 'microsoft_kiota_faraday/middleware/parameters_name_decoding_option'
|
||||
require_relative 'microsoft_kiota_faraday/middleware/parameters_name_decoding_handler'
|
||||
require_relative 'microsoft_kiota_faraday/kiota_client_factory'
|
||||
|
|
|
@ -2,6 +2,7 @@ require 'microsoft_kiota_abstractions'
|
|||
require 'faraday'
|
||||
require 'net/http'
|
||||
require_relative 'kiota_client_factory'
|
||||
require_relative 'middleware/response_handler_option'
|
||||
|
||||
module MicrosoftKiotaFaraday
|
||||
class FaradayRequestAdapter
|
||||
|
@ -43,7 +44,7 @@ module MicrosoftKiotaFaraday
|
|||
@serialization_writer_factory
|
||||
end
|
||||
|
||||
def send_async(request_info, factory, errors_mapping, response_handler)
|
||||
def send_async(request_info, factory, errors_mapping)
|
||||
raise StandardError, 'request_info cannot be null' unless request_info
|
||||
raise StandardError, 'factory cannot be null' unless factory
|
||||
|
||||
|
@ -52,16 +53,19 @@ module MicrosoftKiotaFaraday
|
|||
request = self.get_request_from_request_info(request_info)
|
||||
response = @client.run_request(request.http_method, request.path, request.body, request.headers)
|
||||
|
||||
if response_handler
|
||||
response_handler.handle_response_async(response).resume;
|
||||
else
|
||||
self.throw_if_failed_reponse(response, errors_mapping)
|
||||
root_node = self.get_root_parse_node(response)
|
||||
root_node.get_object_value(factory)
|
||||
end
|
||||
response_handler = self.get_response_handler(request_info)
|
||||
response_handler.call(response).resume unless response_handler.nil?
|
||||
self.throw_if_failed_reponse(response, errors_mapping)
|
||||
root_node = self.get_root_parse_node(response)
|
||||
root_node.get_object_value(factory)
|
||||
end
|
||||
end
|
||||
|
||||
def get_response_handler(request_info)
|
||||
option = request_info.get_request_option(MicrosoftKiotaFaraday::Middleware::ResponseHandlerOption::RESPONSE_HANDLER_KEY) unless request_info.nil?
|
||||
return option.async_callback unless !option || option.nil?
|
||||
end
|
||||
|
||||
def get_root_parse_node(response)
|
||||
raise StandardError, 'response cannot be null' unless response
|
||||
response_content_type = self.get_response_content_type(response);
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
require 'microsoft_kiota_abstractions'
|
||||
module MicrosoftKiotaFaraday
|
||||
module Middleware
|
||||
class ResponseHandlerOption
|
||||
RESPONSE_HANDLER_KEY = "responseHandler"
|
||||
# a lambda that takes the native response type and returns a Fiber with a MicrosoftKiotaAbstractions::Parsable
|
||||
attr_accessor :async_callback
|
||||
def get_key()
|
||||
RESPONSE_HANDLER_KEY
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module MicrosoftKiotaFaraday
|
||||
VERSION = '0.6.0'
|
||||
VERSION = '0.7.0'
|
||||
end
|
||||
|
|
|
@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|||
spec.bindir = 'bin'
|
||||
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
||||
spec.require_paths = ['lib']
|
||||
spec.add_runtime_dependency 'microsoft_kiota_abstractions', '~> 0.9.0', '>= 0.9.0'
|
||||
spec.add_runtime_dependency 'microsoft_kiota_abstractions', '~> 0.10.0', '>= 0.10.0'
|
||||
spec.add_runtime_dependency 'faraday', '~> 2.7', '>= 2.7.2'
|
||||
spec.add_development_dependency 'rake', '~> 13.0'
|
||||
spec.add_development_dependency 'rspec', '~> 3.0'
|
||||
|
|
|
@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
|
|||
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
||||
spec.require_paths = ['lib']
|
||||
|
||||
spec.add_runtime_dependency 'microsoft_kiota_abstractions', '~> 0.9.0', '>= 0.9.0'
|
||||
spec.add_runtime_dependency 'microsoft_kiota_abstractions', '~> 0.10.0', '>= 0.10.0'
|
||||
spec.add_runtime_dependency 'uuidtools'
|
||||
spec.add_development_dependency 'rake', '~> 13.0'
|
||||
spec.add_development_dependency 'rspec', '~> 3.0'
|
||||
|
|
|
@ -71,6 +71,7 @@ public class RubyRefiner : CommonLanguageRefiner, ILanguageRefiner
|
|||
"ParseNode",
|
||||
addUsings: true
|
||||
);
|
||||
RemoveHandlerFromRequestBuilder(generatedCode);
|
||||
}, cancellationToken);
|
||||
}
|
||||
private static void CorrectMethodType(CodeMethod currentMethod) {
|
||||
|
|
|
@ -77,7 +77,7 @@ public class CodeMethodWriter : BaseElementWriter<CodeMethod, RubyConventionServ
|
|||
var writeDiscriminatorValueRead = parentClass.DiscriminatorInformation.ShouldWriteParseNodeCheck && !parentClass.DiscriminatorInformation.ShouldWriteDiscriminatorForIntersectionType;
|
||||
if(writeDiscriminatorValueRead) {
|
||||
writer.WriteLine($"{NodeVarName} = {parseNodeParameter.Name.ToSnakeCase()}.get_child_node(\"{parentClass.DiscriminatorInformation.DiscriminatorPropertyName}\")");
|
||||
writer.StartBlock($"unless ({NodeVarName}.nil?) do");
|
||||
writer.StartBlock($"unless {NodeVarName}.nil? then");
|
||||
writer.WriteLine($"{DiscriminatorMappingVarName} = {NodeVarName}.get_string_value");
|
||||
writer.StartBlock($"case {DiscriminatorMappingVarName}");
|
||||
foreach(var mappedType in parentClass.DiscriminatorInformation.DiscriminatorMappings.OrderBy(static x => x.Key)) {
|
||||
|
@ -230,7 +230,7 @@ public class CodeMethodWriter : BaseElementWriter<CodeMethod, RubyConventionServ
|
|||
.Select(static x => x.Name.ToSnakeCase());
|
||||
if(requestInfoParameters.Any()) {
|
||||
writer.IncreaseIndent();
|
||||
writer.WriteLine(requestInfoParameters.Aggregate((x,y) => $"{x}, {y}"));
|
||||
writer.WriteLine(requestInfoParameters.Aggregate(static (x,y) => $"{x}, {y}"));
|
||||
writer.DecreaseIndent();
|
||||
}
|
||||
writer.WriteLine(")");
|
||||
|
@ -244,7 +244,7 @@ public class CodeMethodWriter : BaseElementWriter<CodeMethod, RubyConventionServ
|
|||
writer.WriteLine($"{errorMappingVarName}[\"{errorMapping.Key.ToUpperInvariant()}\"] = {getDeserializationLambda(errorMapping.Value as CodeType)}");
|
||||
}
|
||||
}
|
||||
writer.WriteLine($"return @request_adapter.{genericTypeForSendMethod}(request_info, {returnType}, {errorMappingVarName}, response_handler)");
|
||||
writer.WriteLine($"return @request_adapter.{genericTypeForSendMethod}(request_info, {returnType}, {errorMappingVarName})");
|
||||
}
|
||||
|
||||
private void WriteRequestGeneratorBody(CodeMethod codeElement, RequestParams requestParams, CodeClass parentClass, LanguageWriter writer) {
|
||||
|
|
|
@ -268,7 +268,7 @@ public class CodeMethodWriterTests : IDisposable {
|
|||
writer.Write(factoryMethod);
|
||||
var result = tw.ToString();
|
||||
Assert.Contains("mapping_value_node = parse_node.get_child_node(\"@odata.type\")", result);
|
||||
Assert.Contains("unless (mapping_value_node.nil?) do", result);
|
||||
Assert.Contains("unless mapping_value_node.nil? then", result);
|
||||
Assert.Contains("mapping_value = mapping_value_node.get_string_value", result);
|
||||
Assert.Contains("case mapping_value", result);
|
||||
Assert.Contains("when \"ns.childmodel\"", result);
|
||||
|
|
Загрузка…
Ссылка в новой задаче