From d83796d31d67005d96b81295e3181a2ce032475a Mon Sep 17 00:00:00 2001 From: andreatp Date: Fri, 21 Aug 2026 15:26:24 +0100 Subject: [PATCH 1/7] feat: Switch to monorepo --- .github/copilot-instructions.md | 2 +- .github/dependabot.yml | 23 +- ...n.yml => kiota-ruby-branch-protection.yml} | 4 +- .github/workflows/release.yml | 48 +- .github/workflows/ruby.yml | 19 +- .gitignore | 32 +- .release-please-manifest.json | 5 +- Gemfile | 11 +- README.md | 44 +- Rakefile | 45 +- .../abstractions/CHANGELOG.md | 0 components/abstractions/Gemfile | 6 + components/abstractions/Rakefile | 8 + .../lib}/microsoft_kiota_abstractions.rb | 0 .../api_client_builder.rb | 0 .../microsoft_kiota_abstractions/api_error.rb | 0 .../authentication/access_token_provider.rb | 0 .../authentication/allowed_hosts_validator.rb | 0 .../anonymous_authentication_provider.rb | 0 .../authentication/authentication_provider.rb | 0 ...se_bearer_token_authentication_provider.rb | 0 .../base_request_builder.rb | 0 .../http_method.rb | 0 .../request_adapter.rb | 0 .../request_configuration.rb | 0 .../request_headers.rb | 0 .../request_information.rb | 0 .../request_option.rb | 0 .../serialization/additional_data_holder.rb | 0 .../serialization/composed_type_wrapper.rb | 0 .../serialization/iso_duration.rb | 0 .../serialization/parsable.rb | 0 .../serialization/parse_node.rb | 0 .../serialization/parse_node_factory.rb | 0 .../parse_node_factory_registry.rb | 0 .../serialization/parse_node_helper.rb | 0 .../serialization/serialization_writer.rb | 0 .../serialization_writer_factory.rb | 0 .../serialization_writer_factory_registry.rb | 0 .../microsoft_kiota_abstractions/version.rb | 2 +- .../microsoft_kiota_abstractions.gemspec | 8 +- .../spec}/access_token_provider_mock.rb | 0 .../microsoft_kiota_abstractions_spec.rb | 0 .../spec}/parse_node_factory_mock.rb | 0 .../spec}/parse_node_factory_registry_spec.rb | 0 .../spec}/parse_node_helper_spec.rb | 0 .../spec}/query_parameters_mock.rb | 0 .../spec}/request_headers_spec.rb | 0 .../spec}/request_information_spec.rb | 0 .../abstractions/spec}/request_option_mock.rb | 0 .../serialization_writer_factory_mock.rb | 0 ...ialization_writer_factory_registry_spec.rb | 0 .../abstractions/spec}/spec_helper.rb | 0 components/authentication/oauth/CHANGELOG.md | 52 ++ components/authentication/oauth/Gemfile | 7 + components/authentication/oauth/Rakefile | 9 + .../microsoft_kiota_authentication_oauth.rb | 14 + .../contexts/authorization_code_context.rb | 87 +++ .../contexts/client_credential_context.rb | 57 ++ .../contexts/oauth_context.rb | 30 + .../contexts/oauth_custom_flow.rb | 27 + .../contexts/on_behalf_of_context.rb | 72 ++ .../extensions/oauth2_ext.rb | 22 + .../oauth_access_token_provider.rb | 91 +++ .../oauth_authentication_provider.rb | 10 + .../version.rb | 5 + ...crosoft_kiota_authentication_oauth.gemspec | 38 ++ ...crosoft_kiota_authentication_oauth_spec.rb | 43 ++ .../authentication/oauth/spec/spec_helper.rb | 20 + components/http/.rspec | 3 + components/http/CHANGELOG.md | 69 ++ components/http/Gemfile | 7 + components/http/Rakefile | 10 + .../http/lib/microsoft_kiota_faraday.rb | 13 + .../faraday_request_adapter.rb | 168 +++++ .../kiota_client_factory.rb | 37 + .../parameters_name_decoding_handler.rb | 29 + .../parameters_name_decoding_option.rb | 19 + .../middleware/response_handler_option.rb | 14 + .../middleware/user_agent_handler.rb | 24 + .../middleware/user_agent_option.rb | 20 + .../lib/microsoft_kiota_faraday/version.rb | 5 + .../http/microsoft_kiota_faraday.gemspec | 36 + .../http/spec/authentication_provider.rb | 5 + .../http/spec/microsoft_kiota_faraday.rb | 18 + .../faraday_request_adapter_spec.rb | 56 ++ .../parameters_name_decoding_handler_spec.rb | 46 ++ components/http/spec/spec_helper.rb | 17 + .../http/spec/user_agent_handler_spec.rb | 44 ++ components/serialization/json/CHANGELOG.md | 57 ++ components/serialization/json/Gemfile | 7 + components/serialization/json/Rakefile | 8 + .../lib/microsoft_kiota_serialization_json.rb | 10 + .../json_parse_node.rb | 134 ++++ .../json_parse_node_factory.rb | 23 + .../json_serialization_writer.rb | 229 +++++++ .../json_serialization_writer_factory.rb | 21 + .../version.rb | 5 + ...microsoft_kiota_serialization_json.gemspec | 39 ++ .../json/spec/files/body_type.rb | 6 + .../json/spec/files/email_address.rb | 98 +++ .../serialization/json/spec/files/entity.rb | 78 +++ .../serialization/json/spec/files/files.rb | 12 + .../json/spec/files/item_body.rb | 98 +++ .../serialization/json/spec/files/message.rb | 643 ++++++++++++++++++ .../json/spec/files/messages_response.rb | 98 +++ .../json/spec/files/outlook_item.rb | 122 ++++ .../json/spec/files/recipient.rb | 78 +++ ...serialization_writer_composed_type_spec.rb | 272 ++++++++ ...microsoft_kiota_serialization_json_spec.rb | 72 ++ .../serialization/json/spec/sample.json | 73 ++ .../serialization/json/spec/spec_helper.rb | 16 + release-please-config.json | 45 +- 113 files changed, 3659 insertions(+), 66 deletions(-) rename .github/policies/{kiota-abstractions-ruby-branch-protection.yml => kiota-ruby-branch-protection.yml} (93%) rename CHANGELOG.md => components/abstractions/CHANGELOG.md (100%) create mode 100644 components/abstractions/Gemfile create mode 100644 components/abstractions/Rakefile rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/api_client_builder.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/api_error.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/authentication/access_token_provider.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/authentication/allowed_hosts_validator.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/authentication/anonymous_authentication_provider.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/authentication/authentication_provider.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/authentication/base_bearer_token_authentication_provider.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/base_request_builder.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/http_method.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/request_adapter.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/request_configuration.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/request_headers.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/request_information.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/request_option.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/serialization/additional_data_holder.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/serialization/composed_type_wrapper.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/serialization/iso_duration.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/serialization/parsable.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/serialization/parse_node.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/serialization/parse_node_factory.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/serialization/parse_node_factory_registry.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/serialization/parse_node_helper.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/serialization/serialization_writer.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/serialization/serialization_writer_factory.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/serialization/serialization_writer_factory_registry.rb (100%) rename {lib => components/abstractions/lib}/microsoft_kiota_abstractions/version.rb (76%) rename microsoft_kiota_abstractions.gemspec => components/abstractions/microsoft_kiota_abstractions.gemspec (81%) rename {spec => components/abstractions/spec}/access_token_provider_mock.rb (100%) rename {spec => components/abstractions/spec}/microsoft_kiota_abstractions_spec.rb (100%) rename {spec => components/abstractions/spec}/parse_node_factory_mock.rb (100%) rename {spec => components/abstractions/spec}/parse_node_factory_registry_spec.rb (100%) rename {spec => components/abstractions/spec}/parse_node_helper_spec.rb (100%) rename {spec => components/abstractions/spec}/query_parameters_mock.rb (100%) rename {spec => components/abstractions/spec}/request_headers_spec.rb (100%) rename {spec => components/abstractions/spec}/request_information_spec.rb (100%) rename {spec => components/abstractions/spec}/request_option_mock.rb (100%) rename {spec => components/abstractions/spec}/serialization_writer_factory_mock.rb (100%) rename {spec => components/abstractions/spec}/serialization_writer_factory_registry_spec.rb (100%) rename {spec => components/abstractions/spec}/spec_helper.rb (100%) create mode 100644 components/authentication/oauth/CHANGELOG.md create mode 100644 components/authentication/oauth/Gemfile create mode 100644 components/authentication/oauth/Rakefile create mode 100644 components/authentication/oauth/lib/microsoft_kiota_authentication_oauth.rb create mode 100644 components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_context.rb create mode 100644 components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb create mode 100644 components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/oauth_context.rb create mode 100644 components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/oauth_custom_flow.rb create mode 100644 components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/on_behalf_of_context.rb create mode 100644 components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/extensions/oauth2_ext.rb create mode 100644 components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/oauth_access_token_provider.rb create mode 100644 components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/oauth_authentication_provider.rb create mode 100644 components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/version.rb create mode 100644 components/authentication/oauth/microsoft_kiota_authentication_oauth.gemspec create mode 100644 components/authentication/oauth/spec/microsoft_kiota_authentication_oauth_spec.rb create mode 100644 components/authentication/oauth/spec/spec_helper.rb create mode 100644 components/http/.rspec create mode 100644 components/http/CHANGELOG.md create mode 100644 components/http/Gemfile create mode 100644 components/http/Rakefile create mode 100644 components/http/lib/microsoft_kiota_faraday.rb create mode 100644 components/http/lib/microsoft_kiota_faraday/faraday_request_adapter.rb create mode 100644 components/http/lib/microsoft_kiota_faraday/kiota_client_factory.rb create mode 100644 components/http/lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_handler.rb create mode 100644 components/http/lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_option.rb create mode 100644 components/http/lib/microsoft_kiota_faraday/middleware/response_handler_option.rb create mode 100644 components/http/lib/microsoft_kiota_faraday/middleware/user_agent_handler.rb create mode 100644 components/http/lib/microsoft_kiota_faraday/middleware/user_agent_option.rb create mode 100644 components/http/lib/microsoft_kiota_faraday/version.rb create mode 100644 components/http/microsoft_kiota_faraday.gemspec create mode 100644 components/http/spec/authentication_provider.rb create mode 100644 components/http/spec/microsoft_kiota_faraday.rb create mode 100644 components/http/spec/microsoft_kiota_faraday/faraday_request_adapter_spec.rb create mode 100644 components/http/spec/parameters_name_decoding_handler_spec.rb create mode 100644 components/http/spec/spec_helper.rb create mode 100644 components/http/spec/user_agent_handler_spec.rb create mode 100644 components/serialization/json/CHANGELOG.md create mode 100644 components/serialization/json/Gemfile create mode 100644 components/serialization/json/Rakefile create mode 100644 components/serialization/json/lib/microsoft_kiota_serialization_json.rb create mode 100644 components/serialization/json/lib/microsoft_kiota_serialization_json/json_parse_node.rb create mode 100644 components/serialization/json/lib/microsoft_kiota_serialization_json/json_parse_node_factory.rb create mode 100644 components/serialization/json/lib/microsoft_kiota_serialization_json/json_serialization_writer.rb create mode 100644 components/serialization/json/lib/microsoft_kiota_serialization_json/json_serialization_writer_factory.rb create mode 100644 components/serialization/json/lib/microsoft_kiota_serialization_json/version.rb create mode 100644 components/serialization/json/microsoft_kiota_serialization_json.gemspec create mode 100644 components/serialization/json/spec/files/body_type.rb create mode 100644 components/serialization/json/spec/files/email_address.rb create mode 100644 components/serialization/json/spec/files/entity.rb create mode 100644 components/serialization/json/spec/files/files.rb create mode 100644 components/serialization/json/spec/files/item_body.rb create mode 100644 components/serialization/json/spec/files/message.rb create mode 100644 components/serialization/json/spec/files/messages_response.rb create mode 100644 components/serialization/json/spec/files/outlook_item.rb create mode 100644 components/serialization/json/spec/files/recipient.rb create mode 100644 components/serialization/json/spec/json_serialization_writer_composed_type_spec.rb create mode 100644 components/serialization/json/spec/microsoft_kiota_serialization_json_spec.rb create mode 100644 components/serialization/json/spec/sample.json create mode 100644 components/serialization/json/spec/spec_helper.rb diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 2399ba9..c7dc716 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -1,4 +1,4 @@ -# Copilot Instructions for Kiota Abstractions Ruby +# Copilot Instructions for Kiota Ruby ## Commit Messages diff --git a/.github/dependabot.yml b/.github/dependabot.yml index fcdf0dc..b9ba800 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -12,7 +12,28 @@ updates: cooldown: default-days: 7 - package-ecosystem: bundler - directory: / + directory: /components/abstractions + schedule: + interval: daily + open-pull-requests-limit: 10 + cooldown: + default-days: 7 +- package-ecosystem: bundler + directory: /components/serialization/json + schedule: + interval: daily + open-pull-requests-limit: 10 + cooldown: + default-days: 7 +- package-ecosystem: bundler + directory: /components/http + schedule: + interval: daily + open-pull-requests-limit: 10 + cooldown: + default-days: 7 +- package-ecosystem: bundler + directory: /components/authentication/oauth schedule: interval: daily open-pull-requests-limit: 10 diff --git a/.github/policies/kiota-abstractions-ruby-branch-protection.yml b/.github/policies/kiota-ruby-branch-protection.yml similarity index 93% rename from .github/policies/kiota-abstractions-ruby-branch-protection.yml rename to .github/policies/kiota-ruby-branch-protection.yml index 5b217a2..aa1df5c 100644 --- a/.github/policies/kiota-abstractions-ruby-branch-protection.yml +++ b/.github/policies/kiota-ruby-branch-protection.yml @@ -1,8 +1,8 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -name: kiota-abstractions-ruby-branch-protection -description: Branch protection policy for the kiota-abstractions-ruby repository +name: kiota-ruby-branch-protection +description: Branch protection policy for the kiota-ruby repository resource: repository configuration: branchProtectionRules: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0bde8a6..e54f050 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,7 +9,7 @@ permissions: contents: read jobs: - deploy_prod: + publish-abstractions: environment: name: production_feeds runs-on: ubuntu-latest @@ -23,8 +23,50 @@ jobs: bundler-cache: true bundler: 'latest' cache-version: 1 - - run: bundle exec rake - - name: Publish to RubyGems + working-directory: components/abstractions + - name: Run tests + working-directory: components/abstractions + run: bundle exec rake + - name: Publish microsoft_kiota_abstractions to RubyGems + working-directory: components/abstractions + run: | + mkdir -p $HOME/.gem + touch $HOME/.gem/credentials + chmod 0600 $HOME/.gem/credentials + printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials + gem build *.gemspec + gem push *.gem + env: + GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}" + + publish-downstream: + needs: publish-abstractions + environment: + name: production_feeds + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + component: + - { name: serialization-json, dir: components/serialization/json } + - { name: http, dir: components/http } + - { name: authentication-oauth, dir: components/authentication/oauth } + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ github.ref }} + - uses: ruby/setup-ruby@95ef2b042f9d7a56d8268cba8559e2842e2ad01b # v1.321.0 + with: + ruby-version: '3.4' + bundler-cache: true + bundler: 'latest' + cache-version: 1 + working-directory: ${{ matrix.component.dir }} + - name: Run tests + working-directory: ${{ matrix.component.dir }} + run: bundle exec rake + - name: Publish ${{ matrix.component.name }} to RubyGems + working-directory: ${{ matrix.component.dir }} run: | mkdir -p $HOME/.gem touch $HOME/.gem/credentials diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 86459b6..b6de75e 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -13,25 +13,24 @@ jobs: matrix: os: [ubuntu-latest, macos-latest] ruby-version: ['3.3', '3.4', '4.0', head, jruby, jruby-head, truffleruby, truffleruby-head] + component: + - { name: abstractions, dir: components/abstractions } + - { name: serialization-json, dir: components/serialization/json } + - { name: http, dir: components/http } + - { name: authentication-oauth, dir: components/authentication/oauth } runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: ruby/setup-ruby@95ef2b042f9d7a56d8268cba8559e2842e2ad01b # v1.321.0 with: ruby-version: ${{ matrix.ruby-version }} - bundler-cache: true # runs 'bundle install' and caches installed gems automatically + bundler-cache: true bundler: 'latest' cache-version: 2 - - name: Run tests + working-directory: ${{ matrix.component.dir }} + - name: Run tests for ${{ matrix.component.name }} + working-directory: ${{ matrix.component.dir }} run: bundle exec rake - - name: Upload artifacts for ruby version 3 and ubuntu - if: ${{ matrix.os == 'ubuntu-latest' && matrix.ruby-version == '3.4'}} - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 - with: - name: drop - path: | - ./Gemfile.lock - ./README.md # The check-ruby-version-matrix returns success if all matrix jobs in build are successful; otherwise, it returns a failure. # Use this as a PR status check for GitHub Policy Service instead of individual matrix entry checks. diff --git a/.gitignore b/.gitignore index 57ba118..1f25878 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,14 @@ *.gem *.rbc -/.config -/coverage/ -/InstalledFiles -/pkg/ -/spec/reports/ -/spec/examples.txt -/test/tmp/ -/test/version_tmp/ -/tmp/ +.config +coverage/ +InstalledFiles +pkg/ +spec/reports/ +spec/examples.txt +test/tmp/ +test/version_tmp/ +tmp/ # Used by dotenv library to load environment variables. # .env @@ -33,15 +33,15 @@ build-iPhoneSimulator/ # vendor/Pods/ ## Documentation cache and generated files: -/.yardoc/ -/_yardoc/ -/doc/ -/rdoc/ +.yardoc/ +_yardoc/ +doc/ +rdoc/ ## Environment normalization: -/.bundle/ -/vendor/bundle -/lib/bundler/man/ +.bundle/ +vendor/bundle +lib/bundler/man/ # for a library or gem, you might want to ignore these files since the code is # intended to run in multiple environments; otherwise, check them in: diff --git a/.release-please-manifest.json b/.release-please-manifest.json index bc7e4aa..ab5b69f 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,6 @@ { - ".": "0.16.0" + "components/abstractions": "0.17.0", + "components/serialization/json": "0.17.0", + "components/http": "0.17.0", + "components/authentication/oauth": "0.17.0" } diff --git a/Gemfile b/Gemfile index c6f618d..0213798 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,11 @@ # frozen_string_literal: true -source 'https://rubygems.org' +source "https://rubygems.org" -# Specify your gem's dependencies in microsoft_kiota_abstractions.gemspec -gemspec +gem "microsoft_kiota_abstractions", path: "components/abstractions" +gem "microsoft_kiota_serialization_json", path: "components/serialization/json" +gem "microsoft_kiota_faraday", path: "components/http" +gem "microsoft_kiota_authentication_oauth", path: "components/authentication/oauth" + +gem "rake", "~> 13.0" +gem "rspec", "~> 3.0" diff --git a/README.md b/README.md index 53a906e..a774b39 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,46 @@ -# Kiota Abstractions Library for Ruby +# Kiota SDK for Ruby -![Ruby](https://github.com/microsoft/kiota-abstractions-ruby/actions/workflows/ruby.yml/badge.svg) +![Ruby](https://github.com/microsoft/kiota-ruby/actions/workflows/ruby.yml/badge.svg) -The Kiota abstractions Library for go is the go library defining the basic constructs Kiota projects need once an SDK has been generated from an OpenAPI definition. +This repository contains the Ruby libraries for [Kiota](https://github.com/microsoft/kiota)-generated API clients. -A [Kiota](https://github.com/microsoft/kiota) generated project will need a reference to the abstraction package to build and run. +## Components -Read more about Kiota [here](https://github.com/microsoft/kiota/blob/main/README.md). +| Gem | Description | RubyGems | +|-----|-------------|----------| +| [microsoft_kiota_abstractions](components/abstractions/) | Core abstractions for Kiota-generated clients | [![Gem Version](https://badge.fury.io/rb/microsoft_kiota_abstractions.svg)](https://rubygems.org/gems/microsoft_kiota_abstractions) | +| [microsoft_kiota_serialization_json](components/serialization/json/) | JSON serialization implementation | [![Gem Version](https://badge.fury.io/rb/microsoft_kiota_serialization_json.svg)](https://rubygems.org/gems/microsoft_kiota_serialization_json) | +| [microsoft_kiota_faraday](components/http/) | HTTP client implementation with Faraday | [![Gem Version](https://badge.fury.io/rb/microsoft_kiota_faraday.svg)](https://rubygems.org/gems/microsoft_kiota_faraday) | +| [microsoft_kiota_authentication_oauth](components/authentication/oauth/) | OAuth authentication provider | [![Gem Version](https://badge.fury.io/rb/microsoft_kiota_authentication_oauth.svg)](https://rubygems.org/gems/microsoft_kiota_authentication_oauth) | -## Using the abstractions library +## Installation -Add this line to your application's Gemfile: +Add the gems you need to your application's Gemfile: ```ruby -gem "microsoft_kiota_abstractions", "0.12.0" +gem "microsoft_kiota_abstractions" +gem "microsoft_kiota_serialization_json" +gem "microsoft_kiota_faraday" +gem "microsoft_kiota_authentication_oauth" ``` -And then execute: +## Development ```shell +git clone https://github.com/microsoft/kiota-ruby.git +cd kiota-ruby bundle install +rake spec ``` -Or install it yourself as: +To run tests for a specific component: - ```shell -gem install microsoft_kiota_abstractions --version "0.12.0" - ``` +```shell +rake abstractions:spec +rake serialization-json:spec +rake http:spec +rake authentication-oauth:spec +``` ## Contributing @@ -44,8 +58,8 @@ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additio ## Trademarks -This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft -trademarks or logos is subject to and must follow +This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft +trademarks or logos is subject to and must follow [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies. diff --git a/Rakefile b/Rakefile index b6ae734..c0aea8a 100644 --- a/Rakefile +++ b/Rakefile @@ -1,8 +1,47 @@ # frozen_string_literal: true -require "bundler/gem_tasks" -require "rspec/core/rake_task" +COMPONENTS = { + "abstractions" => "components/abstractions", + "serialization-json" => "components/serialization/json", + "http" => "components/http", + "authentication-oauth" => "components/authentication/oauth", +}.freeze -RSpec::Core::RakeTask.new(:spec) +def run_in_component(dir, command) + Dir.chdir(dir) do + sh "bundle install --quiet" unless ENV["CI"] + sh command + end +end + +COMPONENTS.each do |name, path| + namespace name do + desc "Run specs for #{name}" + task :spec do + run_in_component(path, "bundle exec rake spec") + end + + desc "Build gem for #{name}" + task :build do + run_in_component(path, "bundle exec rake build") + end + end +end + +desc "Run all component specs" +task :spec do + COMPONENTS.each do |name, path| + puts "\n=== Running specs for #{name} ===" + run_in_component(path, "bundle exec rake spec") + end +end + +desc "Build all gems" +task :build do + COMPONENTS.each do |name, path| + puts "\n=== Building #{name} ===" + run_in_component(path, "bundle exec rake build") + end +end task default: :spec diff --git a/CHANGELOG.md b/components/abstractions/CHANGELOG.md similarity index 100% rename from CHANGELOG.md rename to components/abstractions/CHANGELOG.md diff --git a/components/abstractions/Gemfile b/components/abstractions/Gemfile new file mode 100644 index 0000000..c6f618d --- /dev/null +++ b/components/abstractions/Gemfile @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +source 'https://rubygems.org' + +# Specify your gem's dependencies in microsoft_kiota_abstractions.gemspec +gemspec diff --git a/components/abstractions/Rakefile b/components/abstractions/Rakefile new file mode 100644 index 0000000..b6ae734 --- /dev/null +++ b/components/abstractions/Rakefile @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +require "bundler/gem_tasks" +require "rspec/core/rake_task" + +RSpec::Core::RakeTask.new(:spec) + +task default: :spec diff --git a/lib/microsoft_kiota_abstractions.rb b/components/abstractions/lib/microsoft_kiota_abstractions.rb similarity index 100% rename from lib/microsoft_kiota_abstractions.rb rename to components/abstractions/lib/microsoft_kiota_abstractions.rb diff --git a/lib/microsoft_kiota_abstractions/api_client_builder.rb b/components/abstractions/lib/microsoft_kiota_abstractions/api_client_builder.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/api_client_builder.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/api_client_builder.rb diff --git a/lib/microsoft_kiota_abstractions/api_error.rb b/components/abstractions/lib/microsoft_kiota_abstractions/api_error.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/api_error.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/api_error.rb diff --git a/lib/microsoft_kiota_abstractions/authentication/access_token_provider.rb b/components/abstractions/lib/microsoft_kiota_abstractions/authentication/access_token_provider.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/authentication/access_token_provider.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/authentication/access_token_provider.rb diff --git a/lib/microsoft_kiota_abstractions/authentication/allowed_hosts_validator.rb b/components/abstractions/lib/microsoft_kiota_abstractions/authentication/allowed_hosts_validator.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/authentication/allowed_hosts_validator.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/authentication/allowed_hosts_validator.rb diff --git a/lib/microsoft_kiota_abstractions/authentication/anonymous_authentication_provider.rb b/components/abstractions/lib/microsoft_kiota_abstractions/authentication/anonymous_authentication_provider.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/authentication/anonymous_authentication_provider.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/authentication/anonymous_authentication_provider.rb diff --git a/lib/microsoft_kiota_abstractions/authentication/authentication_provider.rb b/components/abstractions/lib/microsoft_kiota_abstractions/authentication/authentication_provider.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/authentication/authentication_provider.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/authentication/authentication_provider.rb diff --git a/lib/microsoft_kiota_abstractions/authentication/base_bearer_token_authentication_provider.rb b/components/abstractions/lib/microsoft_kiota_abstractions/authentication/base_bearer_token_authentication_provider.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/authentication/base_bearer_token_authentication_provider.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/authentication/base_bearer_token_authentication_provider.rb diff --git a/lib/microsoft_kiota_abstractions/base_request_builder.rb b/components/abstractions/lib/microsoft_kiota_abstractions/base_request_builder.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/base_request_builder.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/base_request_builder.rb diff --git a/lib/microsoft_kiota_abstractions/http_method.rb b/components/abstractions/lib/microsoft_kiota_abstractions/http_method.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/http_method.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/http_method.rb diff --git a/lib/microsoft_kiota_abstractions/request_adapter.rb b/components/abstractions/lib/microsoft_kiota_abstractions/request_adapter.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/request_adapter.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/request_adapter.rb diff --git a/lib/microsoft_kiota_abstractions/request_configuration.rb b/components/abstractions/lib/microsoft_kiota_abstractions/request_configuration.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/request_configuration.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/request_configuration.rb diff --git a/lib/microsoft_kiota_abstractions/request_headers.rb b/components/abstractions/lib/microsoft_kiota_abstractions/request_headers.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/request_headers.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/request_headers.rb diff --git a/lib/microsoft_kiota_abstractions/request_information.rb b/components/abstractions/lib/microsoft_kiota_abstractions/request_information.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/request_information.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/request_information.rb diff --git a/lib/microsoft_kiota_abstractions/request_option.rb b/components/abstractions/lib/microsoft_kiota_abstractions/request_option.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/request_option.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/request_option.rb diff --git a/lib/microsoft_kiota_abstractions/serialization/additional_data_holder.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/additional_data_holder.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/serialization/additional_data_holder.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/serialization/additional_data_holder.rb diff --git a/lib/microsoft_kiota_abstractions/serialization/composed_type_wrapper.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/composed_type_wrapper.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/serialization/composed_type_wrapper.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/serialization/composed_type_wrapper.rb diff --git a/lib/microsoft_kiota_abstractions/serialization/iso_duration.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/iso_duration.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/serialization/iso_duration.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/serialization/iso_duration.rb diff --git a/lib/microsoft_kiota_abstractions/serialization/parsable.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parsable.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/serialization/parsable.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/serialization/parsable.rb diff --git a/lib/microsoft_kiota_abstractions/serialization/parse_node.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/serialization/parse_node.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node.rb diff --git a/lib/microsoft_kiota_abstractions/serialization/parse_node_factory.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_factory.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/serialization/parse_node_factory.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_factory.rb diff --git a/lib/microsoft_kiota_abstractions/serialization/parse_node_factory_registry.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_factory_registry.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/serialization/parse_node_factory_registry.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_factory_registry.rb diff --git a/lib/microsoft_kiota_abstractions/serialization/parse_node_helper.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_helper.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/serialization/parse_node_helper.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_helper.rb diff --git a/lib/microsoft_kiota_abstractions/serialization/serialization_writer.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/serialization/serialization_writer.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer.rb diff --git a/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory.rb diff --git a/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory_registry.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory_registry.rb similarity index 100% rename from lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory_registry.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory_registry.rb diff --git a/lib/microsoft_kiota_abstractions/version.rb b/components/abstractions/lib/microsoft_kiota_abstractions/version.rb similarity index 76% rename from lib/microsoft_kiota_abstractions/version.rb rename to components/abstractions/lib/microsoft_kiota_abstractions/version.rb index 528a94a..aa84da6 100644 --- a/lib/microsoft_kiota_abstractions/version.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module MicrosoftKiotaAbstractions - VERSION = "0.16.0" + VERSION = "0.17.0" end diff --git a/microsoft_kiota_abstractions.gemspec b/components/abstractions/microsoft_kiota_abstractions.gemspec similarity index 81% rename from microsoft_kiota_abstractions.gemspec rename to components/abstractions/microsoft_kiota_abstractions.gemspec index a24f43f..10bcd9c 100644 --- a/microsoft_kiota_abstractions.gemspec +++ b/components/abstractions/microsoft_kiota_abstractions.gemspec @@ -12,11 +12,11 @@ Gem::Specification.new do |spec| spec.homepage = 'https://microsoft.github.io/kiota/' spec.license = 'MIT' spec.metadata = { - 'bug_tracker_uri' => 'https://github.com/microsoft/kiota-abstractions-ruby/issues', - 'changelog_uri' => 'https://github.com/microsoft/kiota-abstractions-ruby/blob/main/CHANGELOG.md', + 'bug_tracker_uri' => 'https://github.com/microsoft/kiota-ruby/issues', + 'changelog_uri' => 'https://github.com/microsoft/kiota-ruby/blob/main/components/abstractions/CHANGELOG.md', 'homepage_uri' => spec.homepage, - 'source_code_uri' => 'https://github.com/microsoft/kiota-abstractions-ruby', - 'github_repo' => 'ssh://github.com/microsoft/kiota-abstractions-ruby' + 'source_code_uri' => 'https://github.com/microsoft/kiota-ruby/tree/main/components/abstractions', + 'github_repo' => 'ssh://github.com/microsoft/kiota-ruby' } spec.required_ruby_version = '>= 3.3.0' diff --git a/spec/access_token_provider_mock.rb b/components/abstractions/spec/access_token_provider_mock.rb similarity index 100% rename from spec/access_token_provider_mock.rb rename to components/abstractions/spec/access_token_provider_mock.rb diff --git a/spec/microsoft_kiota_abstractions_spec.rb b/components/abstractions/spec/microsoft_kiota_abstractions_spec.rb similarity index 100% rename from spec/microsoft_kiota_abstractions_spec.rb rename to components/abstractions/spec/microsoft_kiota_abstractions_spec.rb diff --git a/spec/parse_node_factory_mock.rb b/components/abstractions/spec/parse_node_factory_mock.rb similarity index 100% rename from spec/parse_node_factory_mock.rb rename to components/abstractions/spec/parse_node_factory_mock.rb diff --git a/spec/parse_node_factory_registry_spec.rb b/components/abstractions/spec/parse_node_factory_registry_spec.rb similarity index 100% rename from spec/parse_node_factory_registry_spec.rb rename to components/abstractions/spec/parse_node_factory_registry_spec.rb diff --git a/spec/parse_node_helper_spec.rb b/components/abstractions/spec/parse_node_helper_spec.rb similarity index 100% rename from spec/parse_node_helper_spec.rb rename to components/abstractions/spec/parse_node_helper_spec.rb diff --git a/spec/query_parameters_mock.rb b/components/abstractions/spec/query_parameters_mock.rb similarity index 100% rename from spec/query_parameters_mock.rb rename to components/abstractions/spec/query_parameters_mock.rb diff --git a/spec/request_headers_spec.rb b/components/abstractions/spec/request_headers_spec.rb similarity index 100% rename from spec/request_headers_spec.rb rename to components/abstractions/spec/request_headers_spec.rb diff --git a/spec/request_information_spec.rb b/components/abstractions/spec/request_information_spec.rb similarity index 100% rename from spec/request_information_spec.rb rename to components/abstractions/spec/request_information_spec.rb diff --git a/spec/request_option_mock.rb b/components/abstractions/spec/request_option_mock.rb similarity index 100% rename from spec/request_option_mock.rb rename to components/abstractions/spec/request_option_mock.rb diff --git a/spec/serialization_writer_factory_mock.rb b/components/abstractions/spec/serialization_writer_factory_mock.rb similarity index 100% rename from spec/serialization_writer_factory_mock.rb rename to components/abstractions/spec/serialization_writer_factory_mock.rb diff --git a/spec/serialization_writer_factory_registry_spec.rb b/components/abstractions/spec/serialization_writer_factory_registry_spec.rb similarity index 100% rename from spec/serialization_writer_factory_registry_spec.rb rename to components/abstractions/spec/serialization_writer_factory_registry_spec.rb diff --git a/spec/spec_helper.rb b/components/abstractions/spec/spec_helper.rb similarity index 100% rename from spec/spec_helper.rb rename to components/abstractions/spec/spec_helper.rb diff --git a/components/authentication/oauth/CHANGELOG.md b/components/authentication/oauth/CHANGELOG.md new file mode 100644 index 0000000..2ad597e --- /dev/null +++ b/components/authentication/oauth/CHANGELOG.md @@ -0,0 +1,52 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.9.0](https://github.com/microsoft/kiota-authentication-oauth-ruby/compare/v0.8.0...v0.9.0) (2026-04-23) + + +### Features + +* upgrade ruby CI matrix to 3.3, 3.4 and 4.0 ([11dcef4](https://github.com/microsoft/kiota-authentication-oauth-ruby/commit/11dcef469492e12d7f81a781818300aac080929f)) +* upgrade ruby CI matrix to 3.3, 3.4 and 4.0 ([d76fa2a](https://github.com/microsoft/kiota-authentication-oauth-ruby/commit/d76fa2a1889da1331ac0e0f17af8edd396736610)) + + +### Bug Fixes + +* update minimum required ruby version to 3.3.0 ([552f23f](https://github.com/microsoft/kiota-authentication-oauth-ruby/commit/552f23f8f80e37ada087c4b25faacf184dae869f)) +* update minimum required ruby version to 3.3.0 ([97d915c](https://github.com/microsoft/kiota-authentication-oauth-ruby/commit/97d915ca475600c2e26a85df79df6f538b99288f)) + +## [Unreleased] + +### Added + +### Changed + +## [0.8.0] - 2023-03-28 + +### Changed + +- Updated kiota abstractions reference +- Bumped minimum required ruby version to 3.0. + +## [0.7.0] - 2023-01-17 + +### Changed + +- Removed Microsoft Graph specific defaults. +- Fixed an issue where the access token provider would fail on return. + +## [0.6.0] - 2023-01-16 + +### Changed + +- Fixed a bug where the authentication provider would fail to load. + +## [0.5.0] - 2022-12-30 + +### Added + +- Initial public release of the package. diff --git a/components/authentication/oauth/Gemfile b/components/authentication/oauth/Gemfile new file mode 100644 index 0000000..37d7d74 --- /dev/null +++ b/components/authentication/oauth/Gemfile @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "microsoft_kiota_abstractions", path: "../../abstractions" + +gemspec diff --git a/components/authentication/oauth/Rakefile b/components/authentication/oauth/Rakefile new file mode 100644 index 0000000..2856f1c --- /dev/null +++ b/components/authentication/oauth/Rakefile @@ -0,0 +1,9 @@ +# frozen_string_literal: true + + +require 'bundler/gem_tasks' +require 'rspec/core/rake_task' + +RSpec::Core::RakeTask.new(:spec) + +task default: :spec diff --git a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth.rb b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth.rb new file mode 100644 index 0000000..bafb08f --- /dev/null +++ b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require_relative "microsoft_kiota_authentication_oauth/version" +require_relative "microsoft_kiota_authentication_oauth/contexts/authorization_code_context" +require_relative "microsoft_kiota_authentication_oauth/contexts/client_credential_context" +require_relative "microsoft_kiota_authentication_oauth/contexts/on_behalf_of_context" +require_relative "microsoft_kiota_authentication_oauth/contexts/oauth_context" +require_relative "microsoft_kiota_authentication_oauth/contexts/oauth_custom_flow" +require_relative "microsoft_kiota_authentication_oauth/extensions/oauth2_ext" +require_relative "microsoft_kiota_authentication_oauth/oauth_access_token_provider" +require_relative "microsoft_kiota_authentication_oauth/oauth_authentication_provider" + +module MicrosoftKiotaAuthenticationOAuth +end diff --git a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_context.rb b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_context.rb new file mode 100644 index 0000000..433fc0e --- /dev/null +++ b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_context.rb @@ -0,0 +1,87 @@ +# frozen_string_literal: true + +require 'oauth2' +require_relative './oauth_context' + +module MicrosoftKiotaAuthenticationOAuth + # Token request context class for the authorization code grant type. + class AuthorizationCodeContext < MicrosoftKiotaAuthenticationOAuth::OAuthContext + attr_reader :grant_type, :redirect_uri, :additional_params, + :tenant_id, :client_id, :client_secret, :auth_code, :oauth_provider + attr_writer :scopes + + # This is the initializer for AuthorizationCodeContext, the token request context when + # using the authorization code grant flow. + # :params + # tenant_id: a string containing the tenant id + # client_id: a string containing the client id + # client_secret: a string containing the client secret + # redirect_uri: a string containing redirect_uri + # auth_code: a string containting the auth code; default is nil, can be updated post-initialization + def initialize(tenant_id, client_id, client_secret, redirect_uri, auth_code = nil) + raise StandardError, 'redirect_uri cannot be nil/empty' if redirect_uri.nil? || redirect_uri.empty? + + @tenant_id = tenant_id + @client_id = client_id + @client_secret = client_secret + @auth_code = auth_code + @redirect_uri = redirect_uri + @scopes = nil + @oauth_provider = nil + @grant_type = 'authorization code' + + if @tenant_id.nil? || @client_id.nil? || @client_secret.nil? || @tenant_id.empty? || @client_id.empty? || @client_secret.empty? + raise StandardError, 'tenant_id, client_id, and client_secret cannot be empty' + end + end + + # setter for auth_code + def auth_code=(code) + raise StandardError, 'auth_code cannot be empty/nil.' if code.nil? || code.empty? + + @auth_code = code + end + + # This function generates an authorize URL for obtaining the auth code. + # :params + # scopes: an array of stings, where each string is a scope + # additional_params: hash of symbols to string values, ie { response_mode: 'fragment', prompt: 'login' } + # default is empty hash + def generate_authorize_url(scopes, additional_params = {}) + @additional_params = additional_params + + self.initialize_scopes(scopes) + self.initialize_oauth_provider + + parameters = { scope: @scopes, redirect_uri: @redirect_uri, access_type: 'offline', prompt: 'consent'} + parameters = parameters.merge(additional_params) + @oauth_provider.auth_code.authorize_url(parameters) + end + + def get_token + @oauth_provider.auth_code.get_token(@auth_code, redirect_uri: @redirect_uri) + end + + def initialize_oauth_provider + @oauth_provider = OAuth2::Client.new(@client_id, @client_secret, + site: 'https://login.microsoftonline.com', + authorize_url: "/#{@tenant_id}/oauth2/v2.0/authorize", + token_url: "/#{@tenant_id}/oauth2/v2.0/token") + end + + def initialize_scopes(scopes) + scope_str = '' + scopes.each { |scope| scope_str += scope + ' '} + raise StandardError, 'scopes cannot be empty/nil.' if scope_str.empty? + + scope_str = 'offline_access ' + scope_str + + @scopes = scope_str + end + + private + + attr_writer :grant_type, :redirect_uri, :additional_params, + :tenant_id, :client_id, :client_secret, :oauth_provider + end +end diff --git a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb new file mode 100644 index 0000000..c2ef8d7 --- /dev/null +++ b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +require 'oauth2' +require_relative './oauth_context' + +module MicrosoftKiotaAuthenticationOAuth + # Token request context class for the client credential grant type. + class ClientCredentialContext < MicrosoftKiotaAuthenticationOAuth::OAuthContext + attr_reader :grant_type, :additional_params, :tenant_id, :client_id, :client_secret, :oauth_provider + attr_writer :scopes + + # This is the initializer for ClientCredentialContext, the token request context when + # using the client credential grant flow. + # :params + # tenant_id: a string containing the tenant id + # client_id: a string containing the client id + # client_secret: a string containing the client secret + # additional_params: hash of symbols to string values, ie { response_mode: 'fragment', prompt: 'login' } + # default is empty hash + def initialize(tenant_id, client_id, client_secret, additional_params = {}) + @tenant_id = tenant_id + @client_id = client_id + @client_secret = client_secret + @additional_params = additional_params + @scopes = nil + @oauth_provider = nil + @grant_type = 'client credential' + + + if @tenant_id.nil? || @client_id.nil? || @client_secret.nil? || @tenant_id.empty? || @client_id.empty? || @client_secret.empty? + raise StandardError, 'tenant_id, client_id and client_secret cannot be empty' + end + end + + def get_token + @oauth_provider.client_credentials.get_token({ scope: @scopes }) + end + + def initialize_oauth_provider + @oauth_provider = OAuth2::Client.new(@client_id, @client_secret, + site: 'https://login.microsoftonline.com', + authorize_url: "/#{@tenant_id}/oauth2/v2.0/authorize", + token_url: "/#{@tenant_id}/oauth2/v2.0/token") + end + + # Function to initialize the scope for the client credential context object. + # Only a single scope is supported for this flow and it's expected to be schme://service/.default + def initialize_scopes(scopes = []) + @scopes = scopes[0] unless scopes.empty? + end + + + private + + attr_writer :grant_type, :additional_params, :tenant_id, :client_id, :client_secret, :oauth_provider + end +end diff --git a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/oauth_context.rb b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/oauth_context.rb new file mode 100644 index 0000000..e9578f7 --- /dev/null +++ b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/oauth_context.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'oauth2' +require_relative './oauth_custom_flow' + +module MicrosoftKiotaAuthenticationOAuth + # Base class for token request contexs. + class OAuthContext + attr_accessor :scopes + attr_reader :oauth_provider + include MicrosoftKiotaAuthenticationOAuth::OAuthCustomFlow + + def get_token + OAuthCustomFlow.get_token + end + + def initialize_scopes(scopes = []) + @scopes = OAuthCustomFlow.get_scopes + end + + def initialize_oauth_provider + @oauth_provider = OAuthCustomFlow.get_oauth_provider + end + + private + + attr_writer :oauth_provider + + end +end \ No newline at end of file diff --git a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/oauth_custom_flow.rb b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/oauth_custom_flow.rb new file mode 100644 index 0000000..2d499d6 --- /dev/null +++ b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/oauth_custom_flow.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'oauth2' + +module MicrosoftKiotaAuthenticationOAuth + # Module that can be optionally implemented for supporting custom token grant flows. + # To use a cutsom token grant flow, implement the functions below and + # use MicrosoftKiotaAuthenticationOAuth::OAuthContext.new as your token_request_context + # object for the use by the MicrosoftKiotaAuthenticationOAuth::OAuthAccessTokenProvider + module OAuthCustomFlow + # Function that returns an oauth client using the oauth2 gem + def self.get_oauth_provider + raise NotImplementedError.new + end + + # Function that returns a space seperated string of scopes, beginning with + # the offline_access scope if relevant + def self.get_scopes + raise NotImplementedError.new + end + + # Function that returns the access token + def self.get_token + raise NotImplementedError.new + end + end +end \ No newline at end of file diff --git a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/on_behalf_of_context.rb b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/on_behalf_of_context.rb new file mode 100644 index 0000000..631bec1 --- /dev/null +++ b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/on_behalf_of_context.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +require 'oauth2' +require_relative './oauth_context' + +module MicrosoftKiotaAuthenticationOAuth + # Token request context class for the on behlaf of grant type. + class OnBehalfOfContext < MicrosoftKiotaAuthenticationOAuth::OAuthContext + attr_reader :grant_type, :additional_params, :tenant_id, :client_id, :client_secret, :oauth_provider + attr_writer :scopes + + # This is the initializer for OnBehalfOfContext, the token request context when + # using the client credential grant flow. + # :params + # tenant_id: a string containing the tenant id + # client_id: a string containing the client id + # client_secret: a string containing the client secret + # assertion: string containing assertion (access token used in the request) + # additional_params: hash of symbols to string values, ie { response_mode: 'fragment', prompt: 'login' } + # default is empty hash + def initialize(tenant_id, client_id, client_secret, assertion, additional_params = {}) + raise StandardError, 'assertion cannot be empty' if assertion.nil? || assertion.empty? + + @tenant_id = tenant_id + @client_id = client_id + @client_secret = client_secret + @assertion = assertion + @additional_params = additional_params + @scopes = nil + @oauth_provider = nil + @grant_type = 'urn:ietf:params:Oauth:grant-type:jwt-bearer' + + if @tenant_id.nil? || @client_id.nil? || @client_secret.nil? || @client_secret.empty? || @tenant_id.empty? || @client_id.empty? + raise StandardError, 'tenant_id, client_secret, and client_id cannot be empty' + end + end + + def get_token + params = { + grant_type: @grant_type, + assertion: @assertion, + scope: @scopes, + requested_token_use: 'on_behalf_of' + } + @oauth_provider.on_behalf_of.get_token(params) + end + + def initialize_oauth_provider + @oauth_provider = OAuth2::Client.new(@client_id, @client_secret, + site: 'https://login.microsoftonline.com', + authorize_url: "/#{@tenant_id}/oauth2/v2.0/authorize", + token_url: "/#{@tenant_id}/oauth2/v2.0/token") + end + + def initialize_scopes(scopes) + scope_str = '' + scopes.each { |scope| scope_str += scope + ' '} + + raise StandardError, 'scopes cannot be empty/nil.' if scope_str.empty? + + scope_str = 'offline_access ' + scope_str + + @scopes = scope_str + end + + private + + attr_writer :grant_type, :additional_params, :tenant_id, :client_id, + :client_secret, :oauth_provider + + end +end diff --git a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/extensions/oauth2_ext.rb b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/extensions/oauth2_ext.rb new file mode 100644 index 0000000..8597d26 --- /dev/null +++ b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/extensions/oauth2_ext.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'oauth2' + +# Extension of Oauth2 Library to Include On Behalf Of Grant Type +module OAuth2 + module Strategy + class OnBehalfOf < Base + def get_token(params, response_opts = {}) + @client.get_token(params, response_opts) + end + end + end +end + +module OAuth2 + class Client + def on_behalf_of + @on_behalf_of ||= OAuth2::Strategy::OnBehalfOf.new(self) + end + end +end \ No newline at end of file diff --git a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/oauth_access_token_provider.rb b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/oauth_access_token_provider.rb new file mode 100644 index 0000000..fe18bd9 --- /dev/null +++ b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/oauth_access_token_provider.rb @@ -0,0 +1,91 @@ +# frozen_string_literal: true + +require 'microsoft_kiota_abstractions' +require 'oauth2' +require_relative 'extensions/oauth2_ext' +require_relative 'contexts/client_credential_context' +require_relative 'contexts/authorization_code_context' +require_relative 'contexts/on_behalf_of_context' +require_relative 'contexts/oauth_context' +require_relative 'contexts/oauth_custom_flow' + +module MicrosoftKiotaAuthenticationOAuth + # Access Token Provider class implementation + class OAuthAccessTokenProvider + # This is the initializer for OAuthAccessTokenProvider. + # :params + # token_request_context: a instance of one of our token request context or a custom implementation + # allowed_hosts: an array of strings, where each string is an allowed host, default is empty + # scopes: an array of strings, where each string is a scope, default is empty array + def initialize(token_request_context, allowed_hosts = [], scopes = []) + raise StandardError, 'Parameter token_request_context cannot be nil.' if token_request_context.nil? + + @token_request_context = token_request_context + + unless @token_request_context.is_a?(MicrosoftKiotaAuthenticationOAuth::OAuthContext) + raise StandardError, 'Parameter token_request_context must be an instance of one of our grant flow context classes.' + end + + @cached_token = nil + + @host_validator = if allowed_hosts.nil? || allowed_hosts.size.zero? + MicrosoftKiotaAbstractions::AllowedHostsValidator.new([]) + else + MicrosoftKiotaAbstractions::AllowedHostsValidator.new(allowed_hosts) + end + @token_request_context.initialize_oauth_provider + if scopes.nil? + @scopes = [] + else + @scopes = scopes + end + end + + # This function obtains the authorization token. + # :params + # uri: a string containing the uri + # additional_params: hash of symbols to string values, ie { response_mode: 'fragment', prompt: 'login' } + # default is empty hash + def get_authorization_token(uri, additional_properties = {}) + nil if !uri || !@host_validator.url_host_valid?(uri) + + parsed_url = URI(uri) + + raise StandardError, 'Only https is supported' if parsed_url.scheme != 'https' + + if @scopes.empty? + @scopes << "#{parsed_url.scheme}://#{parsed_url.host}/.default" + end + @token_request_context.initialize_scopes(@scopes) + Fiber.new do + if @cached_token + token = OAuth2::AccessToken.from_hash(@token_request_context.oauth_provider, @cached_token) + token.token unless token.nil? || token.expired? + + if token.expired? + token = token.refresh! + @cached_token = token.to_hash + token.token + end + end + + token = nil + token = @token_request_context.get_token + + if !token.nil? + @cached_token = token.to_hash + token.token + else + nil + end + end + end + + attr_reader :scopes, :host_validator + + protected + + attr_writer :host_validator, :token_credential, :scopes, :cached_token + + end +end diff --git a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/oauth_authentication_provider.rb b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/oauth_authentication_provider.rb new file mode 100644 index 0000000..00487de --- /dev/null +++ b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/oauth_authentication_provider.rb @@ -0,0 +1,10 @@ +require 'microsoft_kiota_abstractions' +require_relative './oauth_access_token_provider' + +module MicrosoftKiotaAuthenticationOAuth + class OAuthAuthenticationProvider < MicrosoftKiotaAbstractions::BaseBearerTokenAuthenticationProvider + def initialize(token_request_context, allowed_hosts, scopes) + super(MicrosoftKiotaAuthenticationOAuth::OAuthAccessTokenProvider.new(token_request_context, allowed_hosts, scopes)) + end + end +end diff --git a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/version.rb b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/version.rb new file mode 100644 index 0000000..28c5900 --- /dev/null +++ b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/version.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +module MicrosoftKiotaAuthenticationOAuth + VERSION = "0.17.0" +end diff --git a/components/authentication/oauth/microsoft_kiota_authentication_oauth.gemspec b/components/authentication/oauth/microsoft_kiota_authentication_oauth.gemspec new file mode 100644 index 0000000..f65cdfb --- /dev/null +++ b/components/authentication/oauth/microsoft_kiota_authentication_oauth.gemspec @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require_relative "lib/microsoft_kiota_authentication_oauth/version" + +Gem::Specification.new do |spec| + spec.name = "microsoft_kiota_authentication_oauth" + spec.version = MicrosoftKiotaAuthenticationOAuth::VERSION + spec.authors = 'Microsoft Corporation' + spec.email = 'graphsdkpub+ruby@microsoft.com' + spec.description = 'Kiota Authentication implementation with oauth2' + spec.summary = 'Microsoft Kiota Authentication OAuth - Kiota Ruby Authentication OAuth library' + spec.homepage = 'https://microsoft.github.io/kiota/' + spec.license = 'MIT' + spec.metadata = { + 'bug_tracker_uri' => 'https://github.com/microsoft/kiota-ruby/issues', + 'changelog_uri' => 'https://github.com/microsoft/kiota-ruby/blob/main/components/authentication/oauth/CHANGELOG.md', + 'homepage_uri' => spec.homepage, + 'source_code_uri' => 'https://github.com/microsoft/kiota-ruby/tree/main/components/authentication/oauth', + 'github_repo' => 'ssh://github.com/microsoft/kiota-ruby' + } + spec.required_ruby_version = ">= 3.3.0" + + # Specify which files should be added to the gem when it is released. + # The `git ls-files -z` loads the files in the RubyGem that have been added into git. + spec.files = Dir.chdir(File.expand_path(__dir__)) do + `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) } + end + + 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.17', '< 0.18' + spec.add_runtime_dependency 'oauth2', '~> 2.0' + spec.add_development_dependency 'rake', '~> 13.0' + spec.add_development_dependency 'rspec', '~> 3.0' + spec.add_development_dependency 'rubocop' +end diff --git a/components/authentication/oauth/spec/microsoft_kiota_authentication_oauth_spec.rb b/components/authentication/oauth/spec/microsoft_kiota_authentication_oauth_spec.rb new file mode 100644 index 0000000..2c4693f --- /dev/null +++ b/components/authentication/oauth/spec/microsoft_kiota_authentication_oauth_spec.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require 'uri' +require_relative 'spec_helper' + +RSpec.describe MicrosoftKiotaAuthenticationOAuth do + it '(client credential context) throws when tenant_id/client_secret is nil/empty' do + expect { MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new(nil, nil, nil, {}) }.to raise_error(StandardError) + expect { MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new('tenant_id', 'client_id', 'client_secret', {}) }.not_to raise_error + expect { MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new('', 'client_id', 'client_secret', {}) }.to raise_error(StandardError) + expect { MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new('tenant_id', '', 'client_secret', {}) }.to raise_error(StandardError) + expect { MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new('tenant_id', 'client_id', '', {}) }.to raise_error(StandardError) + end + + it '(auth code context) throws when tenant_id/client_secret is nil/empty' do + expect { MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new(nil, nil, nil, nil) }.to raise_error(StandardError) + expect { MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('tenant_id', 'client_id', 'client_secret', 'redirect_uri') }.not_to raise_error + expect { MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('', 'client_id', 'client_secret', 'redirect_uri', 'code') }.to raise_error(StandardError) + expect { MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('tenant_id', '', 'client_secret', '') }.to raise_error(StandardError) + expect { MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('tenant_id', 'client_id', '', 'redirect_uri') }.to raise_error(StandardError) + expect { MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('tenant_id', '', 'client_secret', 'redirect_uri') }.to raise_error(StandardError) + end + + + it '(on behalf of) throws when tenant_id/client_secret is nil/empty' do + expect { MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new(nil, nil, nil, nil) }.to raise_error(StandardError) + expect { MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('tenant_id', 'client_id', 'client_secret', 'assertion') }.not_to raise_error + expect { MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('', 'client_id', 'client_secret', 'assertion') }.to raise_error(StandardError) + expect { MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('tenant_id', '', 'client_secret', 'assertion') }.to raise_error(StandardError) + expect { MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('tenant_id', 'client_id', '', 'assertion') }.to raise_error(StandardError) + expect { MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('tenant_id', 'client_id', 'client_secret', '') }.to raise_error(StandardError) + end + + it 'throws when OAuthContext is used, but a custom flow is not implemented' do + expect { MicrosoftKiotaAuthenticationOAuth::OAuthContext.get_token }.to raise_error(NoMethodError) + end + + it 'recognizes contexts as an OAuthContext' do + expect(MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new('tenant_id', 'client_id', 'client_secret', {}).is_a? MicrosoftKiotaAuthenticationOAuth::OAuthContext).to eq(true) + expect(MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('tenant_id', 'client_id', 'client_secret', 'assertion').is_a? MicrosoftKiotaAuthenticationOAuth::OAuthContext).to eq(true) + expect(MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('tenant_id', 'client_id', 'client_secret', 'redirect_uri').is_a? MicrosoftKiotaAuthenticationOAuth::OAuthContext).to eq(true) + end +end diff --git a/components/authentication/oauth/spec/spec_helper.rb b/components/authentication/oauth/spec/spec_helper.rb new file mode 100644 index 0000000..fac733c --- /dev/null +++ b/components/authentication/oauth/spec/spec_helper.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +require 'microsoft_kiota_abstractions' +require_relative '../lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context' +require_relative '../lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_context' +require_relative '../lib/microsoft_kiota_authentication_oauth/contexts/on_behalf_of_context' +require_relative '../lib/microsoft_kiota_authentication_oauth/contexts/oauth_context' +require_relative '../lib/microsoft_kiota_authentication_oauth/contexts/oauth_custom_flow' +require_relative '../lib/microsoft_kiota_authentication_oauth/extensions/oauth2_ext' +require_relative '../lib/microsoft_kiota_authentication_oauth/oauth_access_token_provider' +require_relative '../lib/microsoft_kiota_authentication_oauth/oauth_authentication_provider' + +RSpec.configure do |config| + # Enable flags like --only-failures and --next-failure + config.example_status_persistence_file_path = ".rspec_status" + + # Disable RSpec exposing methods globally on `Module` and `main` + config.disable_monkey_patching! + +end diff --git a/components/http/.rspec b/components/http/.rspec new file mode 100644 index 0000000..34c5164 --- /dev/null +++ b/components/http/.rspec @@ -0,0 +1,3 @@ +--format documentation +--color +--require spec_helper diff --git a/components/http/CHANGELOG.md b/components/http/CHANGELOG.md new file mode 100644 index 0000000..a7e49cb --- /dev/null +++ b/components/http/CHANGELOG.md @@ -0,0 +1,69 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.16.0](https://github.com/microsoft/kiota-http-ruby/compare/v0.15.0...v0.16.0) (2026-04-23) + + +### Features + +* upgrade ruby CI matrix to 3.3, 3.4 and 4.0 ([7bf4976](https://github.com/microsoft/kiota-http-ruby/commit/7bf497603ae5106b57e7b1baf5b51b902049d17c)) +* upgrade ruby CI matrix to 3.3, 3.4 and 4.0 ([278f84d](https://github.com/microsoft/kiota-http-ruby/commit/278f84dd0fd8f2d9d13927089b8c09fcc51b5402)) + + +### Bug Fixes + +* update minimum required ruby version to 3.3.0 ([fa6e13f](https://github.com/microsoft/kiota-http-ruby/commit/fa6e13fbd422c508a690a29e678ebc1ca3d7f33a)) +* update minimum required ruby version to 3.3.0 ([f867d27](https://github.com/microsoft/kiota-http-ruby/commit/f867d270aa008881650af6470428cc19b29d2abd)) + +## [Unreleased] + +### Added + +### Changed + +## [0.15.0] - 2024-02-16 + +### Changed + +- Ensure get_parse_node does not fail when response body is empty. [#27](https://github.com/microsoft/kiota-http-ruby/pull/28) + +## [0.14.0] - 2024-02-14 + +### Changed + +- Make sure the base_url is set when calling authenticate_request. [#27](https://github.com/microsoft/kiota-http-ruby/pull/27) + +## [0.13.0] - 2024-02-05 + +### Changed + +- Added support for error mapping deduplication to reduce generated code. [#20](https://github.com/microsoft/kiota-http-ruby/issues/20) + +## [0.12.0] - 2023-03-28 + +### Changed + +- Updated kiota abstractions reference +- Bumped minimum required ruby version to 3.0. + +## [0.11.0] - 2023-01-10 + +### Added + +- Added a method to convert abstract requests to native requests in the request adapter interface. + +## [0.10.0] - 2023-01-06 + +### Added + +- Added a user agent handler to add the product to the request header. + +## [0.9.0] - 2022-12-30 + +### Added + +- Initial public release of the package. diff --git a/components/http/Gemfile b/components/http/Gemfile new file mode 100644 index 0000000..961a5eb --- /dev/null +++ b/components/http/Gemfile @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "microsoft_kiota_abstractions", path: "../abstractions" + +gemspec diff --git a/components/http/Rakefile b/components/http/Rakefile new file mode 100644 index 0000000..0a44f59 --- /dev/null +++ b/components/http/Rakefile @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +# frozen_string_literal: true + +require 'bundler/gem_tasks' +require 'rspec/core/rake_task' + +RSpec::Core::RakeTask.new(:spec) + +task default: :spec diff --git a/components/http/lib/microsoft_kiota_faraday.rb b/components/http/lib/microsoft_kiota_faraday.rb new file mode 100644 index 0000000..4b2f3c7 --- /dev/null +++ b/components/http/lib/microsoft_kiota_faraday.rb @@ -0,0 +1,13 @@ +# 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/middleware/user_agent_option' +require_relative 'microsoft_kiota_faraday/middleware/user_agent_handler' +require_relative 'microsoft_kiota_faraday/kiota_client_factory' +require_relative 'microsoft_kiota_faraday/faraday_request_adapter' + +module MicrosoftKiotaFaraday +end diff --git a/components/http/lib/microsoft_kiota_faraday/faraday_request_adapter.rb b/components/http/lib/microsoft_kiota_faraday/faraday_request_adapter.rb new file mode 100644 index 0000000..85cee2e --- /dev/null +++ b/components/http/lib/microsoft_kiota_faraday/faraday_request_adapter.rb @@ -0,0 +1,168 @@ +require 'microsoft_kiota_abstractions' +require 'faraday' +require 'net/http' +require_relative 'kiota_client_factory' +require_relative 'middleware/response_handler_option' + +module MicrosoftKiotaFaraday + class FaradayRequestAdapter + include MicrosoftKiotaAbstractions::RequestAdapter + + attr_accessor :authentication_provider, :content_type_header_key, :parse_node_factory, :serialization_writer_factory, :client + + def initialize(authentication_provider, parse_node_factory=MicrosoftKiotaAbstractions::ParseNodeFactoryRegistry.default_instance, serialization_writer_factory=MicrosoftKiotaAbstractions::SerializationWriterFactoryRegistry.default_instance, client = KiotaClientFactory::get_default_http_client) + + if !authentication_provider + raise StandardError , 'authentication provider cannot be null' + end + @authentication_provider = authentication_provider + @content_type_header_key = 'Content-Type' + @parse_node_factory = parse_node_factory + if @parse_node_factory.nil? + @parse_node_factory = MicrosoftKiotaAbstractions::ParseNodeFactoryRegistry.default_instance + end + @serialization_writer_factory = serialization_writer_factory + if @serialization_writer_factory.nil? + @serialization_writer_factory = MicrosoftKiotaAbstractions::SerializationWriterFactoryRegistry.default_instance + end + @client = client + if @client.nil? + @client = KiotaClientFactory::get_default_http_client + end + @base_url = '' + end + + def set_base_url(base_url) + @base_url = base_url + end + + def get_base_url() + @base_url + end + + def get_serialization_writer_factory() + @serialization_writer_factory + end + + 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 + + Fiber.new do + set_base_url_for_request_information(request_info) + @authentication_provider.authenticate_request(request_info).resume + request = self.get_request_from_request_info(request_info) + response = @client.run_request(request.http_method, request.path, request.body, request.headers) + + 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); + raise StandardError, 'no response content type found for deserialization' unless response_content_type + return if response.body.nil? || response.body.empty? + return @parse_node_factory.get_parse_node(response_content_type, response.body) + end + + def throw_if_failed_reponse(response, errors_mapping) + raise StandardError, 'response cannot be null' unless response + + status_code = response.status; + if status_code < 400 then + return + end + error_factory = errors_mapping[status_code] unless errors_mapping.nil? + error_factory = errors_mapping['4XX'] unless !error_factory.nil? || errors_mapping.nil? || status_code > 500 + error_factory = errors_mapping['5XX'] unless !error_factory.nil? || errors_mapping.nil? || status_code < 500 || status_code > 600 + error_factory = errors_mapping['XXX'] unless !error_factory.nil? || errors_mapping.nil? || status_code < 400 || status_code > 600 + raise MicrosoftKiotaAbstractions::ApiError, 'The server returned an unexpected status code and no error factory is registered for this code:' + status_code.to_s if error_factory.nil? + root_node = self.get_root_parse_node(response) + error = root_node.get_object_value(error_factory) unless root_node.nil? + raise error unless error.nil? + raise MicrosoftKiotaAbstractions::ApiError, 'The server returned an unexpected status code:' + status_code.to_s + end + + def get_request_from_request_info(request_info) + set_base_url_for_request_information(request_info) + case request_info.http_method + when :GET + request = @client.build_request(:get) + when :POST + request = @client.build_request(:post) + when :PATCH + request = @client.build_request(:patch) + when :DELETE + request = @client.build_request(:delete) + when :OPTIONS + request = @client.build_request(:options) + when :CONNECT + request = @client.build_request(:connect) + when :PUT + request = @client.build_request(:put) + when :TRACE + request = @client.build_request(:trace) + when :HEAD + request = @client.build_request(:head) + else + raise StandardError, 'unsupported http method' + end + request.path = request_info.uri + unless request_info.headers.nil? then + request.headers = Faraday::Utils::Headers.new + request_info.headers.get_all.select{|k,v| + if v.kind_of? Array then + request.headers[k] = v.join(',') + elsif v.kind_of? String then + request.headers[k] = v + else + request.headers[k] = v.to_s + end + } + end + request.body = request_info.content unless request_info.content.nil? || request_info.content.empty? + # TODO the json serialization writer returns a string at the moment, change to body_stream when this is fixed + request_options = request_info.get_request_options + if !request_options.nil? && !request_options.empty? then + request.options = Faraday::RequestOptions.new if request.options.nil? + request_options.each do |value| + request.options.context[value.get_key] = value + end + end + request + end + + def get_response_content_type(response) + begin + response.headers['content-type'].split(';')[0].downcase() + rescue + return nil + end + end + + def convert_to_native_request_async(request_info) + raise StandardError, 'request_info cannot be null' unless request_info + return Fiber.new do + set_base_url_for_request_information(request_info) + @authentication_provider.authenticate_request(request_info).resume + return self.get_request_from_request_info(request_info) + end + end + + private + + def set_base_url_for_request_information(request_info) + request_info.path_parameters['baseurl'] = @base_url + end + end +end diff --git a/components/http/lib/microsoft_kiota_faraday/kiota_client_factory.rb b/components/http/lib/microsoft_kiota_faraday/kiota_client_factory.rb new file mode 100644 index 0000000..9024ff9 --- /dev/null +++ b/components/http/lib/microsoft_kiota_faraday/kiota_client_factory.rb @@ -0,0 +1,37 @@ +require 'net/https' +require 'faraday' +require_relative 'middleware/parameters_name_decoding_handler' +require_relative 'middleware/user_agent_handler' +module MicrosoftKiotaFaraday + class KiotaClientFactory + def self.get_default_middleware() + return [ + MicrosoftKiotaFaraday::Middleware::ParametersNameDecodingHandler, + MicrosoftKiotaFaraday::Middleware::UserAgentHandler + ] + end + + def self.get_default_http_client(middleware=nil, default_middleware_options=Array.new) + if middleware.nil? #empty is fine in case the user doesn't want to use any middleware + middleware = self.get_default_middleware() + end + connection_options = Hash.new + connection_options[:request] = Hash.new + connection_options[:request][:context] = Hash.new + unless default_middleware_options.nil? || default_middleware_options.empty? then + default_middleware_options.each do |value| + connection_options[:request][:context][value.get_key] = value + end + end + conn = Faraday::Connection.new(nil, connection_options) do |builder| + builder.adapter Faraday.default_adapter + builder.ssl.verify = true + builder.ssl.verify_mode = OpenSSL::SSL::VERIFY_PEER + middleware.each do |handler| + builder.use handler + end + end + conn + end + end +end \ No newline at end of file diff --git a/components/http/lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_handler.rb b/components/http/lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_handler.rb new file mode 100644 index 0000000..a73e1ac --- /dev/null +++ b/components/http/lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_handler.rb @@ -0,0 +1,29 @@ +require 'faraday' +require_relative 'parameters_name_decoding_option' +module MicrosoftKiotaFaraday + module Middleware + class ParametersNameDecodingHandler < Faraday::Middleware + @@default_option = ParametersNameDecodingOption.new + def call(request_env) + request_option = request_env[:request][:context][@@default_option.get_key] unless request_env[:request].nil? || request_env[:request][:context].nil? + request_option = @@default_option if request_option.nil? + unless request_env[:url].nil? || !request_option.enabled || request_option.characters_to_decode.nil? || request_option.characters_to_decode.empty? then + request_url = request_env[:url].to_s + request_option.characters_to_decode.each do |character| + request_url = request_url.gsub(get_regex_for_character(character), character) + end + request_env[:url] = URI.parse(request_url) + end + @app.call(request_env) unless @app.nil? + end + + def get_regex_for_character(character) + @regex_cache ||= Hash.new + if @regex_cache[character].nil? then + @regex_cache[character] = Regexp.new("%#{character.ord.to_s(16)}", true) + end + return @regex_cache[character] + end + end + end +end \ No newline at end of file diff --git a/components/http/lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_option.rb b/components/http/lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_option.rb new file mode 100644 index 0000000..4c971e4 --- /dev/null +++ b/components/http/lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_option.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true +require 'microsoft_kiota_abstractions' +module MicrosoftKiotaFaraday + module Middleware + class ParametersNameDecodingOption + include MicrosoftKiotaAbstractions::RequestOption + attr_accessor :enabled, :characters_to_decode + + def initialize(enabled = true, characters_to_decode = ['$', '.', '-', '~']) + @enabled = enabled + @characters_to_decode = characters_to_decode + end + + def get_key() + "parametersNameDecoding" + end + end + end +end \ No newline at end of file diff --git a/components/http/lib/microsoft_kiota_faraday/middleware/response_handler_option.rb b/components/http/lib/microsoft_kiota_faraday/middleware/response_handler_option.rb new file mode 100644 index 0000000..d183d7e --- /dev/null +++ b/components/http/lib/microsoft_kiota_faraday/middleware/response_handler_option.rb @@ -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 diff --git a/components/http/lib/microsoft_kiota_faraday/middleware/user_agent_handler.rb b/components/http/lib/microsoft_kiota_faraday/middleware/user_agent_handler.rb new file mode 100644 index 0000000..f105c46 --- /dev/null +++ b/components/http/lib/microsoft_kiota_faraday/middleware/user_agent_handler.rb @@ -0,0 +1,24 @@ +require 'faraday' +require_relative 'user_agent_option' +module MicrosoftKiotaFaraday + module Middleware + class UserAgentHandler < Faraday::Middleware + @@default_option = UserAgentOption.new + @@user_agent_key = "User-Agent" + def call(request_env) + request_option = request_env[:request][:context][@@default_option.get_key] unless request_env[:request].nil? || request_env[:request][:context].nil? + request_option = @@default_option if request_option.nil? + unless request_env[:request_headers].nil? || !request_option.enabled || request_option.product_name.nil? || request_option.product_name.empty? || request_option.product_version.nil? || request_option.product_version.empty? then + existing_value = request_env[:request_headers][@@user_agent_key] + additional_value = "#{request_option.product_name}/#{request_option.product_version}" + if !existing_value || existing_value.empty? then + request_env[:request_headers][@@user_agent_key] = additional_value + elsif !existing_value.include? additional_value then + request_env[:request_headers][@@user_agent_key] = "#{existing_value} #{additional_value}" + end + end + @app.call(request_env) unless @app.nil? + end + end + end +end \ No newline at end of file diff --git a/components/http/lib/microsoft_kiota_faraday/middleware/user_agent_option.rb b/components/http/lib/microsoft_kiota_faraday/middleware/user_agent_option.rb new file mode 100644 index 0000000..fb903cb --- /dev/null +++ b/components/http/lib/microsoft_kiota_faraday/middleware/user_agent_option.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true +require 'microsoft_kiota_abstractions' +require_relative '../version.rb' +module MicrosoftKiotaFaraday + module Middleware + class UserAgentOption + include MicrosoftKiotaAbstractions::RequestOption + attr_accessor :enabled, :product_name, :product_version + def initialize() + @enabled = true + @product_name = "kiota-ruby" + @product_version = MicrosoftKiotaFaraday::VERSION + end + + def get_key() + "userAgent" + end + end + end +end diff --git a/components/http/lib/microsoft_kiota_faraday/version.rb b/components/http/lib/microsoft_kiota_faraday/version.rb new file mode 100644 index 0000000..475bf63 --- /dev/null +++ b/components/http/lib/microsoft_kiota_faraday/version.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +module MicrosoftKiotaFaraday + VERSION = '0.17.0' +end diff --git a/components/http/microsoft_kiota_faraday.gemspec b/components/http/microsoft_kiota_faraday.gemspec new file mode 100644 index 0000000..9610fcb --- /dev/null +++ b/components/http/microsoft_kiota_faraday.gemspec @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require_relative "lib/microsoft_kiota_faraday/version" + +Gem::Specification.new do |spec| + spec.name = "microsoft_kiota_faraday" + spec.version = MicrosoftKiotaFaraday::VERSION + spec.authors = 'Microsoft Corporation' + spec.email = 'graphsdkpub+ruby@microsoft.com' + spec.description = 'Kiota HttpCore implementation with Faraday' + spec.summary = "Microsoft Kiota Faraday - Kiota Ruby http request adapter for running requests" + spec.homepage = 'https://microsoft.github.io/kiota/' + spec.license = 'MIT' + spec.metadata = { + 'bug_tracker_uri' => 'https://github.com/microsoft/kiota-ruby/issues', + 'changelog_uri' => 'https://github.com/microsoft/kiota-ruby/blob/main/components/http/CHANGELOG.md', + 'homepage_uri' => spec.homepage, + 'source_code_uri' => 'https://github.com/microsoft/kiota-ruby/tree/main/components/http', + 'github_repo' => 'ssh://github.com/microsoft/kiota-ruby' + } + spec.required_ruby_version = ">= 3.3.0" + + # Specify which files should be added to the gem when it is released. + # The `git ls-files -z` loads the files in the RubyGem that have been added into git. + spec.files = Dir.chdir(File.expand_path(__dir__)) do + `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) } + end + 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.17', '< 0.18' + spec.add_runtime_dependency 'faraday', '~> 2.7', '>= 2.7.2' + spec.add_development_dependency 'rake', '~> 13.0' + spec.add_development_dependency 'rspec', '~> 3.0' + spec.add_development_dependency 'rubocop' +end diff --git a/components/http/spec/authentication_provider.rb b/components/http/spec/authentication_provider.rb new file mode 100644 index 0000000..0a65a84 --- /dev/null +++ b/components/http/spec/authentication_provider.rb @@ -0,0 +1,5 @@ +require 'microsoft_kiota_abstractions' + +class AuthenticationProvider + include MicrosoftKiotaAbstractions::AuthenticationProvider +end \ No newline at end of file diff --git a/components/http/spec/microsoft_kiota_faraday.rb b/components/http/spec/microsoft_kiota_faraday.rb new file mode 100644 index 0000000..c3479b2 --- /dev/null +++ b/components/http/spec/microsoft_kiota_faraday.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true +require_relative 'authentication_provider' + +RSpec.describe MicrosoftKiotaFaraday do + it "has a version number" do + expect(MicrosoftKiotaFaraday::VERSION).not_to be nil + end + + it "does something useful" do + expect(true).to eq(true) + end + + it "can instantiate a request adapter" do + auth_provider = AuthenticationProvider.new() + adapter = MicrosoftKiotaFaraday::FaradayRequestAdapter.new(auth_provider) + expect(adapter).to_not be nil + end +end diff --git a/components/http/spec/microsoft_kiota_faraday/faraday_request_adapter_spec.rb b/components/http/spec/microsoft_kiota_faraday/faraday_request_adapter_spec.rb new file mode 100644 index 0000000..289fefb --- /dev/null +++ b/components/http/spec/microsoft_kiota_faraday/faraday_request_adapter_spec.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true +RSpec.describe MicrosoftKiotaFaraday::FaradayRequestAdapter do + subject(:adapter) { described_class.new(authentication_provider) } + + let(:authentication_provider) { double("authentication_provider") } + let(:headers) { { 'content-type' => 'application/json' } } + let(:body) { { key: "value" }.to_json } + + describe "#get_root_parse_node" do + context "when response is null" do + it "raises an error" do + expect { adapter.get_root_parse_node(nil) }.to raise_error(StandardError, 'response cannot be null') + end + end + + context "when response content type is not found" do + let(:response) { instance_double(Faraday::Response, body:, headers: {}) } + + it "raises an error" do + expect { adapter.get_root_parse_node(response) }.to raise_error(StandardError, 'no response content type found for deserialization') + end + end + + context "when response body is nil" do + let(:response) { instance_double(Faraday::Response, body: nil, headers:) } + + it "returns nil" do + expect(adapter.get_root_parse_node(response)).to be_nil + end + end + + context "when response body is empty" do + let(:response) { instance_double(Faraday::Response, body: "", headers:) } + + it "returns nil" do + expect(adapter.get_root_parse_node(response)).to be_nil + end + end + + context "when response body is not nil" do + subject(:adapter) { described_class.new(authentication_provider, parse_node_factory) } + + let(:response) { instance_double(Faraday::Response, body:, headers:) } + let(:parse_node_factory) { double("parse_node_factory") } + let(:parse_node) { double("parse_node") } + + before do + allow(parse_node_factory).to receive(:get_parse_node).with("application/json", body).and_return(parse_node) + end + + it "returns the parse node" do + expect(adapter.get_root_parse_node(response)).to eq(parse_node) + end + end + end +end diff --git a/components/http/spec/parameters_name_decoding_handler_spec.rb b/components/http/spec/parameters_name_decoding_handler_spec.rb new file mode 100644 index 0000000..b61d492 --- /dev/null +++ b/components/http/spec/parameters_name_decoding_handler_spec.rb @@ -0,0 +1,46 @@ +require 'faraday' + +# frozen_string_literal: true +RSpec.describe MicrosoftKiotaFaraday do + it "decodes encoded query parameters" do + values = Hash.new + values["?%24select=diplayName&api%2Dversion=2"] = "?$select=diplayName&api-version=2" + values["?%24select=diplayName&api%7Eversion=2"] = "?$select=diplayName&api~version=2" + values["?%24select=diplayName&api%2Eversion=2"] = "?$select=diplayName&api.version=2" + values["/api-version/?%24select=diplayName&api%2Eversion=2"] = "/api-version/?$select=diplayName&api.version=2" + values[""] = "" + + handler = MicrosoftKiotaFaraday::Middleware::ParametersNameDecodingHandler.new() + values.each do |key, value| + env = { + url: URI.parse("https://graph.microsoft.com/v1.0/users#{key}") + } + handler.call(env) + expect(env[:url].to_s).to eq("https://graph.microsoft.com/v1.0/users#{value}") + end + end + + it "doesn't decode when disabled on request" do + values = Hash.new + values["?%24select=diplayName&api%2Dversion=2"] = "?%24select=diplayName&api%2Dversion=2" + values["?%24select=diplayName&api%7Eversion=2"] = "?%24select=diplayName&api%7Eversion=2" + values["?%24select=diplayName&api%2Eversion=2"] = "?%24select=diplayName&api%2Eversion=2" + values["/api-version/?%24select=diplayName&api%2Eversion=2"] = "/api-version/?%24select=diplayName&api%2Eversion=2" + values[""] = "" + + option = MicrosoftKiotaFaraday::Middleware::ParametersNameDecodingOption.new(false) + handler = MicrosoftKiotaFaraday::Middleware::ParametersNameDecodingHandler.new() + values.each do |key, value| + env = { + url: URI.parse("https://graph.microsoft.com/v1.0/users#{key}"), + request: { + context: { + option.get_key => option + } + } + } + handler.call(env) + expect(env[:url].to_s).to eq("https://graph.microsoft.com/v1.0/users#{value}") + end + end +end diff --git a/components/http/spec/spec_helper.rb b/components/http/spec/spec_helper.rb new file mode 100644 index 0000000..3f2bbab --- /dev/null +++ b/components/http/spec/spec_helper.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require "microsoft_kiota_faraday" + +Dir["#{File.dirname(__FILE__)}/./../lib/*.rb"].each { |f| load(f) } + +RSpec.configure do |config| + # Enable flags like --only-failures and --next-failure + config.example_status_persistence_file_path = ".rspec_status" + + # Disable RSpec exposing methods globally on `Module` and `main` + config.disable_monkey_patching! + + config.expect_with :rspec do |c| + c.syntax = :expect + end +end diff --git a/components/http/spec/user_agent_handler_spec.rb b/components/http/spec/user_agent_handler_spec.rb new file mode 100644 index 0000000..d3f30f2 --- /dev/null +++ b/components/http/spec/user_agent_handler_spec.rb @@ -0,0 +1,44 @@ +require 'faraday' + +# frozen_string_literal: true +RSpec.describe MicrosoftKiotaFaraday do + user_agent_key = "User-Agent" + url = "https://graph.microsoft.com/v1.0/users" + it "adds the user agent product" do + handler = MicrosoftKiotaFaraday::Middleware::UserAgentHandler.new() + env = { + url: URI.parse(url), + request_headers: {} + } + handler.call(env) + expect(env[:request_headers][user_agent_key].split("/")[0]).to eq("kiota-ruby") + end + + it "adds the user agent product once" do + handler = MicrosoftKiotaFaraday::Middleware::UserAgentHandler.new() + env = { + url: URI.parse(url), + request_headers: {} + } + handler.call(env) + handler.call(env) + expect(env[:request_headers][user_agent_key].split("kiota-ruby").length).to eq(2) + end + it "doesnt add the header when disabled" do + handler = MicrosoftKiotaFaraday::Middleware::UserAgentHandler.new() + opt = MicrosoftKiotaFaraday::Middleware::UserAgentOption.new() + opt.enabled = false + env = { + url: URI.parse(url), + request_headers: {}, + request: { + context: { + opt.get_key => opt + } + } + } + handler.call(env) + handler.call(env) + expect(env[:request_headers][user_agent_key]).to be_nil + end +end diff --git a/components/serialization/json/CHANGELOG.md b/components/serialization/json/CHANGELOG.md new file mode 100644 index 0000000..3cb0dc3 --- /dev/null +++ b/components/serialization/json/CHANGELOG.md @@ -0,0 +1,57 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.10.0](https://github.com/microsoft/kiota-serialization-json-ruby/compare/v0.9.2...v0.10.0) (2026-04-23) + + +### Features + +* upgrade ruby CI matrix to 3.3, 3.4 and 4.0 ([d5cdcbe](https://github.com/microsoft/kiota-serialization-json-ruby/commit/d5cdcbe3cba93c669c0a2070092c223e0fe07ea5)) +* upgrade ruby CI matrix to 3.3, 3.4 and 4.0 ([d3ae6c7](https://github.com/microsoft/kiota-serialization-json-ruby/commit/d3ae6c703a86b90ab65140ef02d9f1ef329c0e6b)) + + +### Bug Fixes + +* update minimum required ruby version to 3.3.0 ([9f270ae](https://github.com/microsoft/kiota-serialization-json-ruby/commit/9f270aeb873d1e420ff766c7de90100753bec8cb)) +* update minimum required ruby version to 3.3.0 ([ec00107](https://github.com/microsoft/kiota-serialization-json-ruby/commit/ec001079bedb0d5c3cd65dedf0ac4b31fe901076)) + +## [Unreleased] + +### Added + +### Changed + +## [0.9.2] - 2025-03-11 + +### Changed + +- Updated dependencies including JSON. + +## [0.9.1] - 2023-08-18 + +### Changed + +- Improve handling of null values (#13) + +## [0.9.0] - 2023-03-28 + +### Changed + +- Updated kiota abstractions reference +- Bumped minimum required ruby version to 3.0. + +## [0.8.0] - 2023-01-18 + +### Changed + +- Fixed a version misalignment with abstractions dependencies. + +## [0.7.0] - 2022-12-30 + +### Added + +- Initial public release of the package. diff --git a/components/serialization/json/Gemfile b/components/serialization/json/Gemfile new file mode 100644 index 0000000..37d7d74 --- /dev/null +++ b/components/serialization/json/Gemfile @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "microsoft_kiota_abstractions", path: "../../abstractions" + +gemspec diff --git a/components/serialization/json/Rakefile b/components/serialization/json/Rakefile new file mode 100644 index 0000000..b6ae734 --- /dev/null +++ b/components/serialization/json/Rakefile @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +require "bundler/gem_tasks" +require "rspec/core/rake_task" + +RSpec::Core::RakeTask.new(:spec) + +task default: :spec diff --git a/components/serialization/json/lib/microsoft_kiota_serialization_json.rb b/components/serialization/json/lib/microsoft_kiota_serialization_json.rb new file mode 100644 index 0000000..83bd6f3 --- /dev/null +++ b/components/serialization/json/lib/microsoft_kiota_serialization_json.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +require_relative "microsoft_kiota_serialization_json/json_parse_node" +require_relative "microsoft_kiota_serialization_json/json_parse_node_factory" +require_relative "microsoft_kiota_serialization_json/json_serialization_writer" +require_relative "microsoft_kiota_serialization_json/json_serialization_writer_factory" +require_relative "microsoft_kiota_serialization_json/version" + +module MicrosoftKiotaSerializationJson +end diff --git a/components/serialization/json/lib/microsoft_kiota_serialization_json/json_parse_node.rb b/components/serialization/json/lib/microsoft_kiota_serialization_json/json_parse_node.rb new file mode 100644 index 0000000..5b0bc94 --- /dev/null +++ b/components/serialization/json/lib/microsoft_kiota_serialization_json/json_parse_node.rb @@ -0,0 +1,134 @@ +require 'time' +require 'date' +require 'json' +require 'uuidtools' +require 'microsoft_kiota_abstractions' + + +module MicrosoftKiotaSerializationJson + class JsonParseNode + include MicrosoftKiotaAbstractions::ParseNode + def initialize(node) + @current_node = node + end + + def get_string_value + @current_node.to_s + end + + def get_boolean_value + @current_node + end + + def get_number_value + @current_node.to_i + end + + def get_float_value + @current_node.to_f + end + + def get_guid_value + UUIDTools::UUID.parse(@current_node) + end + + def get_date_value + Date.parse(@current_node) + end + + def get_time_value() + Time.parse(@current_node) + end + + def get_date_time_value() + DateTime.parse(@current_node) + end + + def get_duration_value() + MicrosoftKiotaAbstractions::ISODuration.new(@current_node) + end + + def get_collection_of_primitive_values(type) + @current_node.map do |object| + next if object.nil? + + current_parse_node = JsonParseNode.new(object) + case type + when String + current_parse_node.get_string_value + when Float + current_parse_node.get_float_value + when Integer + current_parse_node.get_float_value + when "Boolean" + current_parse_node.get_float_value + when DateTime + current_parse_node.get_date_time_value + when Time + current_parse_node.get_time_value + when Date + current_parse_node.get_date_value + when MicrosoftKiotaAbstractions::ISODuration + current_parse_node.get_duration_value + when UUIDTools::UUID + current_parse_node.get_guid_value + else + current_parse_node.get_string_value + end + rescue StandardError => e + raise e.class, `Failed to fetch #{type} type` + end + end + + def get_collection_of_object_values(factory) + raise StandardError, 'Factory cannot be null' if factory.nil? + @current_node.map do |object| + next if object.nil? + + current_parse_node = JsonParseNode.new(object) + current_parse_node.get_object_value(factory) + end + end + + def get_object_value(factory) + raise StandardError, 'Factory cannot be null' if factory.nil? + item = factory.call(self) + assign_field_values(item) + item + rescue StandardError => e + raise e.class, 'Error during deserialization' + end + + def assign_field_values(item) + fields = item.get_field_deserializers + @current_node.each do |k, v| + next if v.nil? + + deserializer = fields[k] + if deserializer + deserializer.call(JsonParseNode.new(v)) + elsif item.additional_data + item.additional_data[k] = v + else + item.additional_data = Hash.new(k => v) + end + end + end + + def get_enum_values(_type) + raw_values = get_string_value + raw_values.split(',').map(&:strip) + end + + def get_enum_value(type) + items = get_enum_values(type).map(&:to_sym) + items[0] if items.length.positive? + end + + def get_child_node(name) + raise StandardError, 'Name cannot be null' if name.nil? || name.empty? + raw_value = @current_node[name] + return JsonParseNode.new(raw_value) if raw_value + end + end +end diff --git a/components/serialization/json/lib/microsoft_kiota_serialization_json/json_parse_node_factory.rb b/components/serialization/json/lib/microsoft_kiota_serialization_json/json_parse_node_factory.rb new file mode 100644 index 0000000..6556ff0 --- /dev/null +++ b/components/serialization/json/lib/microsoft_kiota_serialization_json/json_parse_node_factory.rb @@ -0,0 +1,23 @@ +require 'json' +require 'microsoft_kiota_abstractions' + +module MicrosoftKiotaSerializationJson + class JsonParseNodeFactory + include MicrosoftKiotaAbstractions::ParseNodeFactory + + def get_valid_content_type + 'application/json' + end + + def get_parse_node(content_type, content) + if !content_type + raise StandardError, 'content type cannot be undefined or empty' + elsif get_valid_content_type != content_type + raise StandardError, `expected a #{get_valid_content_type} content type` + end + raise StandardError, 'content cannot be undefined or empty' unless content + + JsonParseNode.new(JSON.parse(content)) + end + end +end diff --git a/components/serialization/json/lib/microsoft_kiota_serialization_json/json_serialization_writer.rb b/components/serialization/json/lib/microsoft_kiota_serialization_json/json_serialization_writer.rb new file mode 100644 index 0000000..5856f8c --- /dev/null +++ b/components/serialization/json/lib/microsoft_kiota_serialization_json/json_serialization_writer.rb @@ -0,0 +1,229 @@ +require 'time' +require 'date' +require 'json' +require "uuidtools" +require 'microsoft_kiota_abstractions' + +module MicrosoftKiotaSerializationJson + class JsonSerializationWriter + include MicrosoftKiotaAbstractions::SerializationWriter + @writer + + def initialize() + @writer = Hash.new() + end + + def writer + @writer + end + + def write_string_value(key, value) + if !key && !value + raise StandardError, "no key or value included in write_string_value(key, value)" + end + if !key + return value.to_s + end + if !value + @writer[key] = nil + else + @writer[key] = value + end + end + + def write_boolean_value(key, value) + if !key && !value + raise StandardError, "no key or value included in write_boolean_value(key, value)" + end + if !key + return value + end + @writer[key] = value + end + + def write_number_value(key, value) + if !key && !value + raise StandardError, "no key or value included in write_number_value(key, value)" + end + if !key + return value + end + @writer[key] = value + end + + def write_float_value(key, value) + if !key && !value + raise StandardError, "no key or value included in write_float_value(key, value)" + end + if !key + return value + end + @writer[key] = value + end + + def write_guid_value(key, value) + if !key && !value + raise StandardError, "no key or value included in write_guid_value(key, value)" + end + if !key + return value.to_s + end + if !value + @writer[key] = nil + else + @writer[key] = value.to_s + end + end + + def write_date_value(key, value) + if !key && !value + raise StandardError, "no key or value included in write_date_value(key, value)" + end + if !key + return value.strftime("%Y-%m-%d") + end + if !value + @writer[key] = nil + else + @writer[key] = value.strftime("%Y-%m-%d") + end + end + + def write_time_value(key, value) + if !key && !value + raise StandardError, "no key or value included in write_time_value(key, value)" + end + if !key + return value.strftime("%H:%M:%S%Z") + end + if !value + @writer[key] = nil + else + @writer[key] = value.strftime("%H:%M:%S%Z") + end + end + + def write_date_time_value(key, value) + if !key && !value + raise StandardError, "no key or value included in write_date_time_value(key, value)" + end + if !key + return value.strftime("%Y-%m-%dT%H:%M:%S%Z") + end + if !value + @writer[key] = nil + else + @writer[key] = value.strftime("%Y-%m-%dT%H:%M:%S%Z") + end + end + + def write_duration_value(key, value) + if !key && !value + raise StandardError, "no key or value included in write_duration_value(key, value)" + end + if !key + return value.string + end + if !value + @writer[key] = nil + else + @writer[key] = value.string + end + end + + def write_collection_of_primitive_values(key, values) + if values + if !key + return values.map do |v| + self.write_any_value(nil, v) + end + end + @writer[key] = values.map do |v| + self.write_any_value(key, v) + end + end + end + + def write_collection_of_object_values(key, values) + if values + if !key + return values.map { |v| write_object_value(nil, v) } + end + @writer[key] = values.map { |v| object_value_hash(v) } + end + end + + def write_object_value(key, value, *additional_values_to_merge) + if value + if key + @writer[key] = object_value_hash(value, *additional_values_to_merge) + else + value.serialize(self) + additional_values_to_merge.each { |v| v.serialize(self) unless v.nil? } + end + end + end + + def write_enum_value(key, values) + self.write_string_value(key, values.to_s) + end + + def get_serialized_content() + return @writer.to_json #TODO encode to byte array to stay content type agnostic + end + + def write_additional_data(value) + if !value + return + end + value.each do |x, y| + self.write_any_value(x,y) + end + end + + private + + def object_value_hash(value, *additional_values_to_merge) + temp = JsonSerializationWriter.new + value.serialize(temp) + additional_values_to_merge.each { |v| v.serialize(temp) unless v.nil? } + temp.writer + end + + public + + def write_any_value(key, value) + if value + if !!value == value + return value + elsif value.instance_of? String + return self.write_string_value(key, value) + elsif value.instance_of? Integer + return self.write_number_value(key, value) + elsif value.instance_of? Float + return self.write_float_value(key, value) + elsif value.instance_of? DateTime + return self.write_date_time_value(key, value) + elsif value.instance_of? Time + return self.write_time_value(key, value) + elsif value.instance_of? Date + return self.write_date_value(key, value) + elsif value.instance_of? MicrosoftKiotaAbstractions::ISODuration + return self.write_duration_value(key, value) + elsif value.instance_of? Array + return self.write_collection_of_primitive_values(key, value) + elsif value.is_a? Object + return value.to_s + else + raise StandardError, "encountered unknown value type during serialization #{value.to_s}" + end + else + if key + @writer[key] = nil + else + raise StandardError, "no key included when writing json property" + end + end + end + end +end diff --git a/components/serialization/json/lib/microsoft_kiota_serialization_json/json_serialization_writer_factory.rb b/components/serialization/json/lib/microsoft_kiota_serialization_json/json_serialization_writer_factory.rb new file mode 100644 index 0000000..3432d7f --- /dev/null +++ b/components/serialization/json/lib/microsoft_kiota_serialization_json/json_serialization_writer_factory.rb @@ -0,0 +1,21 @@ +require 'microsoft_kiota_abstractions' + +module MicrosoftKiotaSerializationJson + class JsonSerializationWriterFactory + include MicrosoftKiotaAbstractions::SerializationWriterFactory + + def get_valid_content_type + 'application/json' + end + + def get_serialization_writer(content_type) + if !content_type + raise StandardError, 'content type cannot be undefined or empty' + elsif get_valid_content_type != content_type + raise StandardError, `expected a #{get_valid_content_type} content type` + end + + JsonSerializationWriter.new + end + end +end diff --git a/components/serialization/json/lib/microsoft_kiota_serialization_json/version.rb b/components/serialization/json/lib/microsoft_kiota_serialization_json/version.rb new file mode 100644 index 0000000..93f54d5 --- /dev/null +++ b/components/serialization/json/lib/microsoft_kiota_serialization_json/version.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +module MicrosoftKiotaSerializationJson + VERSION = "0.17.0" +end diff --git a/components/serialization/json/microsoft_kiota_serialization_json.gemspec b/components/serialization/json/microsoft_kiota_serialization_json.gemspec new file mode 100644 index 0000000..1a343ea --- /dev/null +++ b/components/serialization/json/microsoft_kiota_serialization_json.gemspec @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require_relative "lib/microsoft_kiota_serialization_json/version" + +Gem::Specification.new do |spec| + spec.name = "microsoft_kiota_serialization_json" + spec.version = MicrosoftKiotaSerializationJson::VERSION + spec.authors = 'Microsoft Corporation' + spec.email = 'graphsdkpub@microsoft.com' + spec.description = 'Implementation of Kiota Serialization interfaces for JSON' + spec.summary = 'Microsoft Kiota Serialization - Ruby serialization for building library agnostic http client' + spec.homepage = 'https://microsoft.github.io/kiota/' + spec.license = 'MIT' + spec.metadata = { + 'bug_tracker_uri' => 'https://github.com/microsoft/kiota-ruby/issues', + 'changelog_uri' => 'https://github.com/microsoft/kiota-ruby/blob/main/components/serialization/json/CHANGELOG.md', + 'homepage_uri' => spec.homepage, + 'source_code_uri' => 'https://github.com/microsoft/kiota-ruby/tree/main/components/serialization/json', + 'github_repo' => 'ssh://github.com/microsoft/kiota-ruby' + } + spec.required_ruby_version = ">= 3.3.0" + + # Specify which files should be added to the gem when it is released. + # The `git ls-files -z` loads the files in the RubyGem that have been added into git. + spec.files = Dir.chdir(File.expand_path(__dir__)) do + `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) } + end + + 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.17', '< 0.18' + spec.add_runtime_dependency 'uuidtools', '>= 2.2', '< 3.1' + spec.add_runtime_dependency 'json', '>= 2.6.3', '< 2.22.0' + spec.add_development_dependency 'rake', '~> 13.0' + spec.add_development_dependency 'rspec', '~> 3.0' + spec.add_development_dependency 'rubocop' +end diff --git a/components/serialization/json/spec/files/body_type.rb b/components/serialization/json/spec/files/body_type.rb new file mode 100644 index 0000000..8409dc2 --- /dev/null +++ b/components/serialization/json/spec/files/body_type.rb @@ -0,0 +1,6 @@ +module Files + BodyType = { + Text: :Text, + Html: :Html, + } +end diff --git a/components/serialization/json/spec/files/email_address.rb b/components/serialization/json/spec/files/email_address.rb new file mode 100644 index 0000000..5e1b057 --- /dev/null +++ b/components/serialization/json/spec/files/email_address.rb @@ -0,0 +1,98 @@ +require 'microsoft_kiota_abstractions' + +module Files + class EmailAddress + include MicrosoftKiotaAbstractions::AdditionalDataHolder, MicrosoftKiotaAbstractions::Parsable + ## + # Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + @additional_data + ## + # The email address of the person or entity. + @address + ## + # The display name of the person or entity. + @name + ## + ## Gets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## @return a i_dictionary + ## + def additional_data + return @additional_data + end + ## + ## Sets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## @param value Value to set for the AdditionalData property. + ## @return a void + ## + def additional_data=(value) + @additional_data = value + end + ## + ## Gets the address property value. The email address of the person or entity. + ## @return a string + ## + def address + return @address + end + ## + ## Sets the address property value. The email address of the person or entity. + ## @param value Value to set for the address property. + ## @return a void + ## + def address=(value) + @address = value + end + ## + ## Instantiates a new emailAddress and sets the default values. + ## @return a void + ## + def initialize() + @additional_data = Hash.new + end + ## + ## Creates a new instance of the appropriate class based on discriminator value + ## @param parseNode The parse node to use to read the discriminator value and create the object + ## @return a email_address + ## + def self.create_from_discriminator_value(parse_node) + raise StandardError, 'parse_node cannot be null' if parse_node.nil? + return EmailAddress.new + end + ## + ## The deserialization information for the current model + ## @return a i_dictionary + ## + def get_field_deserializers() + return { + "address" => lambda {|n| @address = n.get_string_value() }, + "name" => lambda {|n| @name = n.get_string_value() }, + } + end + ## + ## Gets the name property value. The display name of the person or entity. + ## @return a string + ## + def name + return @name + end + ## + ## Sets the name property value. The display name of the person or entity. + ## @param value Value to set for the name property. + ## @return a void + ## + def name=(value) + @name = value + end + ## + ## Serializes information the current object + ## @param writer Serialization writer to use to serialize this model + ## @return a void + ## + def serialize(writer) + raise StandardError, 'writer cannot be null' if writer.nil? + writer.write_string_value("address", @address) + writer.write_string_value("name", @name) + writer.write_additional_data(@additional_data) + end + end +end diff --git a/components/serialization/json/spec/files/entity.rb b/components/serialization/json/spec/files/entity.rb new file mode 100644 index 0000000..8b3c9eb --- /dev/null +++ b/components/serialization/json/spec/files/entity.rb @@ -0,0 +1,78 @@ +require 'microsoft_kiota_abstractions' + +module Files + class Entity + include MicrosoftKiotaAbstractions::AdditionalDataHolder, MicrosoftKiotaAbstractions::Parsable + ## + # Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + @additional_data + ## + # The unique idenfier for an entity. Read-only. + @id + ## + ## Gets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## @return a i_dictionary + ## + def additional_data + return @additional_data + end + ## + ## Sets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## @param value Value to set for the AdditionalData property. + ## @return a void + ## + def additional_data=(value) + @additional_data = value + end + ## + ## Instantiates a new entity and sets the default values. + ## @return a void + ## + def initialize() + @additional_data = Hash.new + end + ## + ## Creates a new instance of the appropriate class based on discriminator value + ## @param parseNode The parse node to use to read the discriminator value and create the object + ## @return a entity + ## + def self.create_from_discriminator_value(parse_node) + raise StandardError, 'parse_node cannot be null' if parse_node.nil? + return Entity.new + end + ## + ## The deserialization information for the current model + ## @return a i_dictionary + ## + def get_field_deserializers() + return { + "id" => lambda {|n| @id = n.get_string_value() }, + } + end + ## + ## Gets the id property value. The unique idenfier for an entity. Read-only. + ## @return a string + ## + def id + return @id + end + ## + ## Sets the id property value. The unique idenfier for an entity. Read-only. + ## @param value Value to set for the id property. + ## @return a void + ## + def id=(value) + @id = value + end + ## + ## Serializes information the current object + ## @param writer Serialization writer to use to serialize this model + ## @return a void + ## + def serialize(writer) + raise StandardError, 'writer cannot be null' if writer.nil? + writer.write_string_value("id", @id) + writer.write_additional_data(@additional_data) + end + end +end diff --git a/components/serialization/json/spec/files/files.rb b/components/serialization/json/spec/files/files.rb new file mode 100644 index 0000000..868ff5a --- /dev/null +++ b/components/serialization/json/spec/files/files.rb @@ -0,0 +1,12 @@ +require 'microsoft_kiota_abstractions' +require_relative './body_type' +require_relative './email_address' +require_relative './entity' +require_relative './item_body' +require_relative './message' +require_relative './messages_response' +require_relative './outlook_item' +require_relative './recipient' + +module Files +end \ No newline at end of file diff --git a/components/serialization/json/spec/files/item_body.rb b/components/serialization/json/spec/files/item_body.rb new file mode 100644 index 0000000..b557597 --- /dev/null +++ b/components/serialization/json/spec/files/item_body.rb @@ -0,0 +1,98 @@ +require 'microsoft_kiota_abstractions' + +module Files + class ItemBody + include MicrosoftKiotaAbstractions::AdditionalDataHolder, MicrosoftKiotaAbstractions::Parsable + ## + # Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + @additional_data + ## + # The content of the item. + @content + ## + # The contentType property + @content_type + ## + ## Gets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## @return a i_dictionary + ## + def additional_data + return @additional_data + end + ## + ## Sets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## @param value Value to set for the AdditionalData property. + ## @return a void + ## + def additional_data=(value) + @additional_data = value + end + ## + ## Instantiates a new itemBody and sets the default values. + ## @return a void + ## + def initialize() + @additional_data = Hash.new + end + ## + ## Gets the content property value. The content of the item. + ## @return a string + ## + def content + return @content + end + ## + ## Sets the content property value. The content of the item. + ## @param value Value to set for the content property. + ## @return a void + ## + def content=(value) + @content = value + end + ## + ## Gets the contentType property value. The contentType property + ## @return a body_type + ## + def content_type + return @content_type + end + ## + ## Sets the contentType property value. The contentType property + ## @param value Value to set for the contentType property. + ## @return a void + ## + def content_type=(value) + @content_type = value + end + ## + ## Creates a new instance of the appropriate class based on discriminator value + ## @param parseNode The parse node to use to read the discriminator value and create the object + ## @return a item_body + ## + def self.create_from_discriminator_value(parse_node) + raise StandardError, 'parse_node cannot be null' if parse_node.nil? + return ItemBody.new + end + ## + ## The deserialization information for the current model + ## @return a i_dictionary + ## + def get_field_deserializers() + return { + "content" => lambda {|n| @content = n.get_string_value() }, + "contentType" => lambda {|n| @content_type = n.get_enum_value(Files::BodyType) }, + } + end + ## + ## Serializes information the current object + ## @param writer Serialization writer to use to serialize this model + ## @return a void + ## + def serialize(writer) + raise StandardError, 'writer cannot be null' if writer.nil? + writer.write_string_value("content", @content) + writer.write_enum_value("contentType", @content_type) + writer.write_additional_data(@additional_data) + end + end +end diff --git a/components/serialization/json/spec/files/message.rb b/components/serialization/json/spec/files/message.rb new file mode 100644 index 0000000..fad72a5 --- /dev/null +++ b/components/serialization/json/spec/files/message.rb @@ -0,0 +1,643 @@ +require 'date' +require 'microsoft_kiota_abstractions' +require_relative './outlook_item' + +module Files + class Message < Files::OutlookItem + include MicrosoftKiotaAbstractions::Parsable + @guid_id + def guid_id=(guid_id) + @guid_id = guid_id + end + def guid_id + return @guid_id + end + ## + # The fileAttachment and itemAttachment attachments for the message. + @attachments + ## + # The Bcc: recipients for the message. + @bcc_recipients + ## + # The body property + @body + ## + # The first 255 characters of the message body. It is in text format. + @body_preview + ## + # The Cc: recipients for the message. + @cc_recipients + ## + # The ID of the conversation the email belongs to. + @conversation_id + ## + # Indicates the position of the message within the conversation. + @conversation_index + ## + # The collection of open extensions defined for the message. Nullable. + @extensions + ## + # The flag property + @flag + ## + # The from property + @from + ## + # Indicates whether the message has attachments. This property doesn't include inline attachments, so if a message contains only inline attachments, this property is false. To verify the existence of inline attachments, parse the body property to look for a src attribute, such as . + @has_attachments + ## + # The importance property + @importance + ## + # The inferenceClassification property + @inference_classification + ## + # The internetMessageHeaders property + @internet_message_headers + ## + # The internetMessageId property + @internet_message_id + ## + # The isDeliveryReceiptRequested property + @is_delivery_receipt_requested + ## + # The isDraft property + @is_draft + ## + # The isRead property + @is_read + ## + # The isReadReceiptRequested property + @is_read_receipt_requested + ## + # The collection of multi-value extended properties defined for the message. Nullable. + @multi_value_extended_properties + ## + # The parentFolderId property + @parent_folder_id + ## + # The receivedDateTime property + @received_date_time + ## + # The replyTo property + @reply_to + ## + # The sender property + @sender + ## + # The sentDateTime property + @sent_date_time + ## + # The collection of single-value extended properties defined for the message. Nullable. + @single_value_extended_properties + ## + # The subject property + @subject + ## + # The toRecipients property + @to_recipients + ## + # The uniqueBody property + @unique_body + ## + # The webLink property + @web_link + ## + ## Gets the attachments property value. The fileAttachment and itemAttachment attachments for the message. + ## @return a attachment + ## + def attachments + return @attachments + end + ## + ## Sets the attachments property value. The fileAttachment and itemAttachment attachments for the message. + ## @param value Value to set for the attachments property. + ## @return a void + ## + def attachments=(value) + @attachments = value + end + ## + ## Gets the bccRecipients property value. The Bcc: recipients for the message. + ## @return a recipient + ## + def bcc_recipients + return @bcc_recipients + end + ## + ## Sets the bccRecipients property value. The Bcc: recipients for the message. + ## @param value Value to set for the bccRecipients property. + ## @return a void + ## + def bcc_recipients=(value) + @bcc_recipients = value + end + ## + ## Gets the body property value. The body property + ## @return a item_body + ## + def body + return @body + end + ## + ## Sets the body property value. The body property + ## @param value Value to set for the body property. + ## @return a void + ## + def body=(value) + @body = value + end + ## + ## Gets the bodyPreview property value. The first 255 characters of the message body. It is in text format. + ## @return a string + ## + def body_preview + return @body_preview + end + ## + ## Sets the bodyPreview property value. The first 255 characters of the message body. It is in text format. + ## @param value Value to set for the bodyPreview property. + ## @return a void + ## + def body_preview=(value) + @body_preview = value + end + ## + ## Gets the ccRecipients property value. The Cc: recipients for the message. + ## @return a recipient + ## + def cc_recipients + return @cc_recipients + end + ## + ## Sets the ccRecipients property value. The Cc: recipients for the message. + ## @param value Value to set for the ccRecipients property. + ## @return a void + ## + def cc_recipients=(value) + @cc_recipients = value + end + ## + ## Instantiates a new message and sets the default values. + ## @return a void + ## + def initialize() + super + end + ## + ## Gets the conversationId property value. The ID of the conversation the email belongs to. + ## @return a string + ## + def conversation_id + return @conversation_id + end + ## + ## Sets the conversationId property value. The ID of the conversation the email belongs to. + ## @param value Value to set for the conversationId property. + ## @return a void + ## + def conversation_id=(value) + @conversation_id = value + end + ## + ## Gets the conversationIndex property value. Indicates the position of the message within the conversation. + ## @return a binary + ## + def conversation_index + return @conversation_index + end + ## + ## Sets the conversationIndex property value. Indicates the position of the message within the conversation. + ## @param value Value to set for the conversationIndex property. + ## @return a void + ## + def conversation_index=(value) + @conversation_index = value + end + ## + ## Creates a new instance of the appropriate class based on discriminator value + ## @param parseNode The parse node to use to read the discriminator value and create the object + ## @return a message + ## + def self.create_from_discriminator_value(parse_node) + raise StandardError, 'parse_node cannot be null' if parse_node.nil? + return Message.new + end + ## + ## Gets the extensions property value. The collection of open extensions defined for the message. Nullable. + ## @return a extension + ## + def extensions + return @extensions + end + ## + ## Sets the extensions property value. The collection of open extensions defined for the message. Nullable. + ## @param value Value to set for the extensions property. + ## @return a void + ## + def extensions=(value) + @extensions = value + end + ## + ## Gets the flag property value. The flag property + ## @return a followup_flag + ## + def flag + return @flag + end + ## + ## Sets the flag property value. The flag property + ## @param value Value to set for the flag property. + ## @return a void + ## + def flag=(value) + @flag = value + end + ## + ## Gets the from property value. The from property + ## @return a recipient + ## + def from + return @from + end + ## + ## Sets the from property value. The from property + ## @param value Value to set for the from property. + ## @return a void + ## + def from=(value) + @from = value + end + ## + ## The deserialization information for the current model + ## @return a i_dictionary + ## + def get_field_deserializers() + return super.merge({ + "guidId" => lambda {|n| @guid_id = n.get_guid_value() }, + "bccRecipients" => lambda {|n| @bcc_recipients = n.get_collection_of_object_values(lambda {|pn| Files::Recipient.create_from_discriminator_value(pn) }) }, + "body" => lambda {|n| @body = n.get_object_value(lambda {|pn| Files::ItemBody.create_from_discriminator_value(pn) }) }, + "bodyPreview" => lambda {|n| @body_preview = n.get_string_value() }, + "ccRecipients" => lambda {|n| @cc_recipients = n.get_collection_of_object_values(lambda {|pn| Files::Recipient.create_from_discriminator_value(pn) }) }, + "conversationId" => lambda {|n| @conversation_id = n.get_string_value() }, + "conversationIndex" => lambda {|n| @conversation_index = n.get_string_value() }, + "from" => lambda {|n| @from = n.get_object_value(lambda {|pn| Files::Recipient.create_from_discriminator_value(pn) }) }, + "hasAttachments" => lambda {|n| @has_attachments = n.get_boolean_value() }, + "internetMessageId" => lambda {|n| @internet_message_id = n.get_string_value() }, + "isDeliveryReceiptRequested" => lambda {|n| @is_delivery_receipt_requested = n.get_boolean_value() }, + "isDraft" => lambda {|n| @is_draft = n.get_boolean_value() }, + "isRead" => lambda {|n| @is_read = n.get_boolean_value() }, + "isReadReceiptRequested" => lambda {|n| @is_read_receipt_requested = n.get_boolean_value() }, + "parentFolderId" => lambda {|n| @parent_folder_id = n.get_string_value() }, + "receivedDateTime" => lambda {|n| @received_date_time = n.get_date_time_value() }, + "replyTo" => lambda {|n| @reply_to = n.get_collection_of_object_values(lambda {|pn| Files::Recipient.create_from_discriminator_value(pn) }) }, + "sender" => lambda {|n| @sender = n.get_object_value(lambda {|pn| Files::Recipient.create_from_discriminator_value(pn) }) }, + "sentDateTime" => lambda {|n| @sent_date_time = n.get_date_time_value() }, + "subject" => lambda {|n| @subject = n.get_string_value() }, + "toRecipients" => lambda {|n| @to_recipients = n.get_collection_of_object_values(lambda {|pn| Files::Recipient.create_from_discriminator_value(pn) }) }, + "uniqueBody" => lambda {|n| @unique_body = n.get_object_value(lambda {|pn| Files::ItemBody.create_from_discriminator_value(pn) }) }, + "webLink" => lambda {|n| @web_link = n.get_string_value() }, + }) + end + ## + ## Gets the hasAttachments property value. Indicates whether the message has attachments. This property doesn't include inline attachments, so if a message contains only inline attachments, this property is false. To verify the existence of inline attachments, parse the body property to look for a src attribute, such as . + ## @return a boolean + ## + def has_attachments + return @has_attachments + end + ## + ## Sets the hasAttachments property value. Indicates whether the message has attachments. This property doesn't include inline attachments, so if a message contains only inline attachments, this property is false. To verify the existence of inline attachments, parse the body property to look for a src attribute, such as . + ## @param value Value to set for the hasAttachments property. + ## @return a void + ## + def has_attachments=(value) + @has_attachments = value + end + ## + ## Gets the importance property value. The importance property + ## @return a importance + ## + def importance + return @importance + end + ## + ## Sets the importance property value. The importance property + ## @param value Value to set for the importance property. + ## @return a void + ## + def importance=(value) + @importance = value + end + ## + ## Gets the inferenceClassification property value. The inferenceClassification property + ## @return a inference_classification_type + ## + def inference_classification + return @inference_classification + end + ## + ## Sets the inferenceClassification property value. The inferenceClassification property + ## @param value Value to set for the inferenceClassification property. + ## @return a void + ## + def inference_classification=(value) + @inference_classification = value + end + ## + ## Gets the internetMessageHeaders property value. The internetMessageHeaders property + ## @return a internet_message_header + ## + def internet_message_headers + return @internet_message_headers + end + ## + ## Sets the internetMessageHeaders property value. The internetMessageHeaders property + ## @param value Value to set for the internetMessageHeaders property. + ## @return a void + ## + def internet_message_headers=(value) + @internet_message_headers = value + end + ## + ## Gets the internetMessageId property value. The internetMessageId property + ## @return a string + ## + def internet_message_id + return @internet_message_id + end + ## + ## Sets the internetMessageId property value. The internetMessageId property + ## @param value Value to set for the internetMessageId property. + ## @return a void + ## + def internet_message_id=(value) + @internet_message_id = value + end + ## + ## Gets the isDeliveryReceiptRequested property value. The isDeliveryReceiptRequested property + ## @return a boolean + ## + def is_delivery_receipt_requested + return @is_delivery_receipt_requested + end + ## + ## Sets the isDeliveryReceiptRequested property value. The isDeliveryReceiptRequested property + ## @param value Value to set for the isDeliveryReceiptRequested property. + ## @return a void + ## + def is_delivery_receipt_requested=(value) + @is_delivery_receipt_requested = value + end + ## + ## Gets the isDraft property value. The isDraft property + ## @return a boolean + ## + def is_draft + return @is_draft + end + ## + ## Sets the isDraft property value. The isDraft property + ## @param value Value to set for the isDraft property. + ## @return a void + ## + def is_draft=(value) + @is_draft = value + end + ## + ## Gets the isRead property value. The isRead property + ## @return a boolean + ## + def is_read + return @is_read + end + ## + ## Sets the isRead property value. The isRead property + ## @param value Value to set for the isRead property. + ## @return a void + ## + def is_read=(value) + @is_read = value + end + ## + ## Gets the isReadReceiptRequested property value. The isReadReceiptRequested property + ## @return a boolean + ## + def is_read_receipt_requested + return @is_read_receipt_requested + end + ## + ## Sets the isReadReceiptRequested property value. The isReadReceiptRequested property + ## @param value Value to set for the isReadReceiptRequested property. + ## @return a void + ## + def is_read_receipt_requested=(value) + @is_read_receipt_requested = value + end + ## + ## Gets the multiValueExtendedProperties property value. The collection of multi-value extended properties defined for the message. Nullable. + ## @return a multi_value_legacy_extended_property + ## + def multi_value_extended_properties + return @multi_value_extended_properties + end + ## + ## Sets the multiValueExtendedProperties property value. The collection of multi-value extended properties defined for the message. Nullable. + ## @param value Value to set for the multiValueExtendedProperties property. + ## @return a void + ## + def multi_value_extended_properties=(value) + @multi_value_extended_properties = value + end + ## + ## Gets the parentFolderId property value. The parentFolderId property + ## @return a string + ## + def parent_folder_id + return @parent_folder_id + end + ## + ## Sets the parentFolderId property value. The parentFolderId property + ## @param value Value to set for the parentFolderId property. + ## @return a void + ## + def parent_folder_id=(value) + @parent_folder_id = value + end + ## + ## Gets the receivedDateTime property value. The receivedDateTime property + ## @return a date_time + ## + def received_date_time + return @received_date_time + end + ## + ## Sets the receivedDateTime property value. The receivedDateTime property + ## @param value Value to set for the receivedDateTime property. + ## @return a void + ## + def received_date_time=(value) + @received_date_time = value + end + ## + ## Gets the replyTo property value. The replyTo property + ## @return a recipient + ## + def reply_to + return @reply_to + end + ## + ## Sets the replyTo property value. The replyTo property + ## @param value Value to set for the replyTo property. + ## @return a void + ## + def reply_to=(value) + @reply_to = value + end + ## + ## Gets the sender property value. The sender property + ## @return a recipient + ## + def sender + return @sender + end + ## + ## Sets the sender property value. The sender property + ## @param value Value to set for the sender property. + ## @return a void + ## + def sender=(value) + @sender = value + end + ## + ## Gets the sentDateTime property value. The sentDateTime property + ## @return a date_time + ## + def sent_date_time + return @sent_date_time + end + ## + ## Sets the sentDateTime property value. The sentDateTime property + ## @param value Value to set for the sentDateTime property. + ## @return a void + ## + def sent_date_time=(value) + @sent_date_time = value + end + ## + ## Serializes information the current object + ## @param writer Serialization writer to use to serialize this model + ## @return a void + ## + def serialize(writer) + raise StandardError, 'writer cannot be null' if writer.nil? + super + writer.write_guid_value("guidId", @guid_id) + writer.write_collection_of_object_values("attachments", @attachments) + writer.write_collection_of_object_values("bccRecipients", @bcc_recipients) + writer.write_object_value("body", @body) + writer.write_string_value("bodyPreview", @body_preview) + writer.write_collection_of_object_values("ccRecipients", @cc_recipients) + writer.write_string_value("conversationId", @conversation_id) + # writer.write_object_value("conversationIndex", @conversation_index) byte array is not supported yet + writer.write_collection_of_object_values("extensions", @extensions) + writer.write_object_value("flag", @flag) + writer.write_object_value("from", @from) + writer.write_boolean_value("hasAttachments", @has_attachments) + writer.write_enum_value("importance", @importance) + writer.write_enum_value("inferenceClassification", @inference_classification) + writer.write_collection_of_object_values("internetMessageHeaders", @internet_message_headers) + writer.write_string_value("internetMessageId", @internet_message_id) + writer.write_boolean_value("isDeliveryReceiptRequested", @is_delivery_receipt_requested) + writer.write_boolean_value("isDraft", @is_draft) + writer.write_boolean_value("isRead", @is_read) + writer.write_boolean_value("isReadReceiptRequested", @is_read_receipt_requested) + writer.write_collection_of_object_values("multiValueExtendedProperties", @multi_value_extended_properties) + writer.write_string_value("parentFolderId", @parent_folder_id) + writer.write_date_time_value("receivedDateTime", @received_date_time) + writer.write_collection_of_object_values("replyTo", @reply_to) + writer.write_object_value("sender", @sender) + writer.write_date_time_value("sentDateTime", @sent_date_time) + writer.write_collection_of_object_values("singleValueExtendedProperties", @single_value_extended_properties) + writer.write_string_value("subject", @subject) + writer.write_collection_of_object_values("toRecipients", @to_recipients) + writer.write_object_value("uniqueBody", @unique_body) + writer.write_string_value("webLink", @web_link) + end + ## + ## Gets the singleValueExtendedProperties property value. The collection of single-value extended properties defined for the message. Nullable. + ## @return a single_value_legacy_extended_property + ## + def single_value_extended_properties + return @single_value_extended_properties + end + ## + ## Sets the singleValueExtendedProperties property value. The collection of single-value extended properties defined for the message. Nullable. + ## @param value Value to set for the singleValueExtendedProperties property. + ## @return a void + ## + def single_value_extended_properties=(value) + @single_value_extended_properties = value + end + ## + ## Gets the subject property value. The subject property + ## @return a string + ## + def subject + return @subject + end + ## + ## Sets the subject property value. The subject property + ## @param value Value to set for the subject property. + ## @return a void + ## + def subject=(value) + @subject = value + end + ## + ## Gets the toRecipients property value. The toRecipients property + ## @return a recipient + ## + def to_recipients + return @to_recipients + end + ## + ## Sets the toRecipients property value. The toRecipients property + ## @param value Value to set for the toRecipients property. + ## @return a void + ## + def to_recipients=(value) + @to_recipients = value + end + ## + ## Gets the uniqueBody property value. The uniqueBody property + ## @return a item_body + ## + def unique_body + return @unique_body + end + ## + ## Sets the uniqueBody property value. The uniqueBody property + ## @param value Value to set for the uniqueBody property. + ## @return a void + ## + def unique_body=(value) + @unique_body = value + end + ## + ## Gets the webLink property value. The webLink property + ## @return a string + ## + def web_link + return @web_link + end + ## + ## Sets the webLink property value. The webLink property + ## @param value Value to set for the webLink property. + ## @return a void + ## + def web_link=(value) + @web_link = value + end + end +end diff --git a/components/serialization/json/spec/files/messages_response.rb b/components/serialization/json/spec/files/messages_response.rb new file mode 100644 index 0000000..f90f0af --- /dev/null +++ b/components/serialization/json/spec/files/messages_response.rb @@ -0,0 +1,98 @@ +require 'microsoft_kiota_abstractions' + +module Files + class MessageCollectionResponse + include MicrosoftKiotaAbstractions::AdditionalDataHolder, MicrosoftKiotaAbstractions::Parsable + ## + # Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + @additional_data + ## + # The OdataNextLink property + @odata_next_link + ## + # The value property + @value + ## + ## Gets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## @return a i_dictionary + ## + def additional_data + return @additional_data + end + ## + ## Sets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## @param value Value to set for the AdditionalData property. + ## @return a void + ## + def additional_data=(value) + @additional_data = value + end + ## + ## Instantiates a new MessageCollectionResponse and sets the default values. + ## @return a void + ## + def initialize() + @additional_data = Hash.new + end + ## + ## Creates a new instance of the appropriate class based on discriminator value + ## @param parseNode The parse node to use to read the discriminator value and create the object + ## @return a message_collection_response + ## + def self.create_from_discriminator_value(parse_node) + raise StandardError, 'parse_node cannot be null' if parse_node.nil? + return MessageCollectionResponse.new + end + ## + ## The deserialization information for the current model + ## @return a i_dictionary + ## + def get_field_deserializers() + return { + "@odata.nextLink" => lambda {|n| @odata_next_link = n.get_string_value() }, + "value" => lambda {|n| @value = n.get_collection_of_object_values(lambda {|pn| Files::Message.create_from_discriminator_value(pn) }) }, + } + end + ## + ## Gets the @odata.nextLink property value. The OdataNextLink property + ## @return a string + ## + def odata_next_link + return @odata_next_link + end + ## + ## Sets the @odata.nextLink property value. The OdataNextLink property + ## @param value Value to set for the OdataNextLink property. + ## @return a void + ## + def odata_next_link=(value) + @odata_next_link = value + end + ## + ## Serializes information the current object + ## @param writer Serialization writer to use to serialize this model + ## @return a void + ## + def serialize(writer) + raise StandardError, 'writer cannot be null' if writer.nil? + writer.write_string_value("@odata.nextLink", @odata_next_link) + writer.write_collection_of_object_values("value", @value) + writer.write_additional_data(@additional_data) + end + ## + ## Gets the value property value. The value property + ## @return a message + ## + def value + return @value + end + ## + ## Sets the value property value. The value property + ## @param value Value to set for the value property. + ## @return a void + ## + def value=(value) + @value = value + end + end +end diff --git a/components/serialization/json/spec/files/outlook_item.rb b/components/serialization/json/spec/files/outlook_item.rb new file mode 100644 index 0000000..1ee373b --- /dev/null +++ b/components/serialization/json/spec/files/outlook_item.rb @@ -0,0 +1,122 @@ +require 'date' +require 'microsoft_kiota_abstractions' +require_relative './entity' + +module Files + class OutlookItem < Files::Entity + include MicrosoftKiotaAbstractions::Parsable + ## + # The categories associated with the item + @categories + ## + # Identifies the version of the item. Every time the item is changed, changeKey changes as well. This allows Exchange to apply changes to the correct version of the object. Read-only. + @change_key + ## + # The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z + @created_date_time + ## + # The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z + @last_modified_date_time + ## + ## Gets the categories property value. The categories associated with the item + ## @return a string + ## + def categories + return @categories + end + ## + ## Sets the categories property value. The categories associated with the item + ## @param value Value to set for the categories property. + ## @return a void + ## + def categories=(value) + @categories = value + end + ## + ## Gets the changeKey property value. Identifies the version of the item. Every time the item is changed, changeKey changes as well. This allows Exchange to apply changes to the correct version of the object. Read-only. + ## @return a string + ## + def change_key + return @change_key + end + ## + ## Sets the changeKey property value. Identifies the version of the item. Every time the item is changed, changeKey changes as well. This allows Exchange to apply changes to the correct version of the object. Read-only. + ## @param value Value to set for the changeKey property. + ## @return a void + ## + def change_key=(value) + @change_key = value + end + ## + ## Instantiates a new outlookItem and sets the default values. + ## @return a void + ## + def initialize() + super + end + ## + ## Gets the createdDateTime property value. The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z + ## @return a date_time + ## + def created_date_time + return @created_date_time + end + ## + ## Sets the createdDateTime property value. The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z + ## @param value Value to set for the createdDateTime property. + ## @return a void + ## + def created_date_time=(value) + @created_date_time = value + end + ## + ## Creates a new instance of the appropriate class based on discriminator value + ## @param parseNode The parse node to use to read the discriminator value and create the object + ## @return a outlook_item + ## + def self.create_from_discriminator_value(parse_node) + raise StandardError, 'parse_node cannot be null' if parse_node.nil? + return OutlookItem.new + end + ## + ## The deserialization information for the current model + ## @return a i_dictionary + ## + def get_field_deserializers() + return super.merge({ + "categories" => lambda {|n| @categories = n.get_collection_of_primitive_values(String) }, + "changeKey" => lambda {|n| @change_key = n.get_string_value() }, + "createdDateTime" => lambda {|n| @created_date_time = n.get_date_time_value() }, + "lastModifiedDateTime" => lambda {|n| @last_modified_date_time = n.get_date_time_value() }, + }) + end + ## + ## Gets the lastModifiedDateTime property value. The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z + ## @return a date_time + ## + def last_modified_date_time + return @last_modified_date_time + end + ## + ## Sets the lastModifiedDateTime property value. The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z + ## @param value Value to set for the lastModifiedDateTime property. + ## @return a void + ## + def last_modified_date_time=(value) + @last_modified_date_time = value + end + ## + ## Serializes information the current object + ## @param writer Serialization writer to use to serialize this model + ## @return a void + ## + def serialize(writer) + raise StandardError, 'writer cannot be null' if writer.nil? + super + writer.write_collection_of_primitive_values("categories", @categories) + writer.write_string_value("changeKey", @change_key) + writer.write_date_time_value("createdDateTime", @created_date_time) + writer.write_date_time_value("lastModifiedDateTime", @last_modified_date_time) + end + end +end diff --git a/components/serialization/json/spec/files/recipient.rb b/components/serialization/json/spec/files/recipient.rb new file mode 100644 index 0000000..cbfb18b --- /dev/null +++ b/components/serialization/json/spec/files/recipient.rb @@ -0,0 +1,78 @@ +require 'microsoft_kiota_abstractions' + +module Files + class Recipient + include MicrosoftKiotaAbstractions::AdditionalDataHolder, MicrosoftKiotaAbstractions::Parsable + ## + # Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + @additional_data + ## + # The emailAddress property + @email_address + ## + ## Gets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## @return a i_dictionary + ## + def additional_data + return @additional_data + end + ## + ## Sets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## @param value Value to set for the AdditionalData property. + ## @return a void + ## + def additional_data=(value) + @additional_data = value + end + ## + ## Instantiates a new recipient and sets the default values. + ## @return a void + ## + def initialize() + @additional_data = Hash.new + end + ## + ## Creates a new instance of the appropriate class based on discriminator value + ## @param parseNode The parse node to use to read the discriminator value and create the object + ## @return a recipient + ## + def self.create_from_discriminator_value(parse_node) + raise StandardError, 'parse_node cannot be null' if parse_node.nil? + return Recipient.new + end + ## + ## Gets the emailAddress property value. The emailAddress property + ## @return a email_address + ## + def email_address + return @email_address + end + ## + ## Sets the emailAddress property value. The emailAddress property + ## @param value Value to set for the emailAddress property. + ## @return a void + ## + def email_address=(value) + @email_address = value + end + ## + ## The deserialization information for the current model + ## @return a i_dictionary + ## + def get_field_deserializers() + return { + "emailAddress" => lambda {|n| @email_address = n.get_object_value(lambda {|pn| Files::EmailAddress.create_from_discriminator_value(pn) }) }, + } + end + ## + ## Serializes information the current object + ## @param writer Serialization writer to use to serialize this model + ## @return a void + ## + def serialize(writer) + raise StandardError, 'writer cannot be null' if writer.nil? + writer.write_object_value("emailAddress", @email_address) + writer.write_additional_data(@additional_data) + end + end +end diff --git a/components/serialization/json/spec/json_serialization_writer_composed_type_spec.rb b/components/serialization/json/spec/json_serialization_writer_composed_type_spec.rb new file mode 100644 index 0000000..9bffd43 --- /dev/null +++ b/components/serialization/json/spec/json_serialization_writer_composed_type_spec.rb @@ -0,0 +1,272 @@ +# frozen_string_literal: true + +require_relative 'spec_helper' +require 'microsoft_kiota_abstractions' + +module TestModels + class SimpleParsable + include MicrosoftKiotaAbstractions::Parsable + + attr_accessor :name, :age + + def get_field_deserializers + { + 'name' => lambda { |n| @name = n.get_string_value }, + 'age' => lambda { |n| @age = n.get_number_value } + } + end + + def serialize(writer) + writer.write_string_value('name', @name) + writer.write_number_value('age', @age) + end + + def self.create_from_discriminator_value(_parse_node) + SimpleParsable.new + end + end + + class AnotherParsable + include MicrosoftKiotaAbstractions::Parsable + + attr_accessor :email + + def get_field_deserializers + { 'email' => lambda { |n| @email = n.get_string_value } } + end + + def serialize(writer) + writer.write_string_value('email', @email) + end + + def self.create_from_discriminator_value(_parse_node) + AnotherParsable.new + end + end + + class UnionTypeWrapper + include MicrosoftKiotaAbstractions::Parsable + include MicrosoftKiotaAbstractions::ComposedTypeWrapper + + attr_accessor :simple, :another + + def get_field_deserializers + return @simple.get_field_deserializers if @simple + return @another.get_field_deserializers if @another + {} + end + + def serialize(writer) + if @simple + writer.write_object_value(nil, @simple) + elsif @another + writer.write_object_value(nil, @another) + end + end + + def self.create_from_discriminator_value(_parse_node) + UnionTypeWrapper.new + end + end + + class IntersectionTypeWrapper + include MicrosoftKiotaAbstractions::Parsable + include MicrosoftKiotaAbstractions::ComposedTypeWrapper + + attr_accessor :simple, :another + + def get_field_deserializers + MicrosoftKiotaAbstractions::ParseNodeHelper + .merge_deserializers_for_intersection_wrapper(@simple, @another) + end + + def serialize(writer) + writer.write_object_value(nil, @simple, @another) + end + + def self.create_from_discriminator_value(_parse_node) + IntersectionTypeWrapper.new + end + end +end + +RSpec.describe MicrosoftKiotaSerializationJson::JsonSerializationWriter do + describe '#write_object_value' do + it 'serializes a regular object with a key' do + writer = MicrosoftKiotaSerializationJson::JsonSerializationWriter.new + obj = TestModels::SimpleParsable.new + obj.name = 'Alice' + obj.age = 30 + + writer.write_object_value('person', obj) + expect(writer.writer['person']).to eq({ 'name' => 'Alice', 'age' => 30 }) + end + + it 'serializes a regular object with additional values merged under a key' do + writer = MicrosoftKiotaSerializationJson::JsonSerializationWriter.new + obj1 = TestModels::SimpleParsable.new + obj1.name = 'Alice' + obj1.age = 30 + obj2 = TestModels::AnotherParsable.new + obj2.email = 'alice@example.com' + + writer.write_object_value('person', obj1, obj2) + expect(writer.writer['person']).to eq({ 'name' => 'Alice', 'age' => 30, 'email' => 'alice@example.com' }) + end + + it 'skips nil additional values' do + writer = MicrosoftKiotaSerializationJson::JsonSerializationWriter.new + obj = TestModels::SimpleParsable.new + obj.name = 'Bob' + obj.age = 22 + + writer.write_object_value('person', obj, nil, nil) + expect(writer.writer['person']).to eq({ 'name' => 'Bob', 'age' => 22 }) + end + + it 'returns nil when value is nil' do + writer = MicrosoftKiotaSerializationJson::JsonSerializationWriter.new + result = writer.write_object_value('key', nil) + expect(result).to be_nil + expect(writer.writer).to eq({}) + end + + it 'serializes into self when key is nil for a non-composed type' do + writer = MicrosoftKiotaSerializationJson::JsonSerializationWriter.new + obj = TestModels::SimpleParsable.new + obj.name = 'Eve' + obj.age = 40 + + writer.write_object_value(nil, obj) + expect(writer.writer).to eq({ 'name' => 'Eve', 'age' => 40 }) + end + end + + describe '#write_object_value with union types' do + it 'serializes the first branch of a union into the current writer' do + writer = MicrosoftKiotaSerializationJson::JsonSerializationWriter.new + union = TestModels::UnionTypeWrapper.new + inner = TestModels::SimpleParsable.new + inner.name = 'Charlie' + inner.age = 25 + union.simple = inner + + writer.write_object_value(nil, union) + expect(writer.writer).to eq({ 'name' => 'Charlie', 'age' => 25 }) + end + + it 'serializes the second branch of a union into the current writer' do + writer = MicrosoftKiotaSerializationJson::JsonSerializationWriter.new + union = TestModels::UnionTypeWrapper.new + inner = TestModels::AnotherParsable.new + inner.email = 'test@example.com' + union.another = inner + + writer.write_object_value(nil, union) + expect(writer.writer).to eq({ 'email' => 'test@example.com' }) + end + + it 'produces valid JSON for a union type' do + writer = MicrosoftKiotaSerializationJson::JsonSerializationWriter.new + union = TestModels::UnionTypeWrapper.new + inner = TestModels::SimpleParsable.new + inner.name = 'Charlie' + inner.age = 25 + union.simple = inner + + writer.write_object_value(nil, union) + json = writer.get_serialized_content + parsed = JSON.parse(json) + expect(parsed).to eq({ 'name' => 'Charlie', 'age' => 25 }) + end + end + + describe '#write_object_value with intersection types' do + it 'merges all intersection members into the current writer' do + writer = MicrosoftKiotaSerializationJson::JsonSerializationWriter.new + intersection = TestModels::IntersectionTypeWrapper.new + obj1 = TestModels::SimpleParsable.new + obj1.name = 'Dana' + obj1.age = 28 + obj2 = TestModels::AnotherParsable.new + obj2.email = 'dana@example.com' + intersection.simple = obj1 + intersection.another = obj2 + + writer.write_object_value(nil, intersection) + expect(writer.writer).to eq({ 'name' => 'Dana', 'age' => 28, 'email' => 'dana@example.com' }) + end + + it 'produces valid JSON for an intersection type' do + writer = MicrosoftKiotaSerializationJson::JsonSerializationWriter.new + intersection = TestModels::IntersectionTypeWrapper.new + obj1 = TestModels::SimpleParsable.new + obj1.name = 'Dana' + obj1.age = 28 + obj2 = TestModels::AnotherParsable.new + obj2.email = 'dana@example.com' + intersection.simple = obj1 + intersection.another = obj2 + + writer.write_object_value(nil, intersection) + json = writer.get_serialized_content + parsed = JSON.parse(json) + expect(parsed).to eq({ 'name' => 'Dana', 'age' => 28, 'email' => 'dana@example.com' }) + end + end + + describe '#write_collection_of_object_values' do + it 'serializes a collection of objects under a key' do + writer = MicrosoftKiotaSerializationJson::JsonSerializationWriter.new + obj1 = TestModels::SimpleParsable.new + obj1.name = 'Alice' + obj1.age = 30 + obj2 = TestModels::SimpleParsable.new + obj2.name = 'Bob' + obj2.age = 25 + + writer.write_collection_of_object_values('people', [obj1, obj2]) + expect(writer.writer['people']).to eq([ + { 'name' => 'Alice', 'age' => 30 }, + { 'name' => 'Bob', 'age' => 25 } + ]) + end + + it 'serializes into self when key is nil' do + writer = MicrosoftKiotaSerializationJson::JsonSerializationWriter.new + obj1 = TestModels::SimpleParsable.new + obj1.name = 'Alice' + obj1.age = 30 + + writer.write_collection_of_object_values(nil, [obj1]) + expect(writer.writer).to eq({ 'name' => 'Alice', 'age' => 30 }) + end + + it 'does not contaminate the parent writer' do + writer = MicrosoftKiotaSerializationJson::JsonSerializationWriter.new + writer.write_string_value('top_level', 'value') + obj = TestModels::SimpleParsable.new + obj.name = 'Alice' + obj.age = 30 + + writer.write_collection_of_object_values('people', [obj]) + expect(writer.writer.keys).to contain_exactly('top_level', 'people') + end + + it 'produces valid JSON with a collection' do + writer = MicrosoftKiotaSerializationJson::JsonSerializationWriter.new + obj1 = TestModels::SimpleParsable.new + obj1.name = 'Alice' + obj1.age = 30 + obj2 = TestModels::AnotherParsable.new + obj2.email = 'bob@example.com' + + writer.write_collection_of_object_values('items', [obj1]) + writer.write_object_value('contact', obj2) + json = writer.get_serialized_content + parsed = JSON.parse(json) + expect(parsed['items']).to eq([{ 'name' => 'Alice', 'age' => 30 }]) + expect(parsed['contact']).to eq({ 'email' => 'bob@example.com' }) + end + end +end diff --git a/components/serialization/json/spec/microsoft_kiota_serialization_json_spec.rb b/components/serialization/json/spec/microsoft_kiota_serialization_json_spec.rb new file mode 100644 index 0000000..40bd11e --- /dev/null +++ b/components/serialization/json/spec/microsoft_kiota_serialization_json_spec.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +require_relative 'spec_helper' +require_relative './files/files.rb' +require 'microsoft_kiota_abstractions' +require 'json' + +RSpec.describe MicrosoftKiotaSerializationJson do + it "has a version number" do + expect(MicrosoftKiotaSerializationJson::VERSION).not_to be nil + end + + it "can build jsonParseNode" do + json_parse_node = MicrosoftKiotaSerializationJson::JsonParseNode.new(JSON.parse('{"value": [{"hasAttachments": false}] }')) + expect(json_parse_node).not_to be nil + expect(json_parse_node.get_string_value().gsub(/\s+/, "")).to eq("{\"value\"=>[{\"hasAttachments\"=>false}]}") + end + + it "can deserialize payload" do + file = File.open("#{File.dirname(__FILE__)}/sample.json") + data = file.read + file.close + message_response = MicrosoftKiotaSerializationJson::JsonParseNodeFactory.new.get_parse_node("application/json", data) + object_value = message_response.get_object_value(lambda {|pn| Files::MessageCollectionResponse.create_from_discriminator_value(pn)}) + + ## Object Value tests + expect(object_value.instance_of? Files::MessageCollectionResponse).to eq(true) + expect(object_value.value[0].instance_of? Files::Message).to eq(true) + expect(object_value.value[0].body.instance_of? Files::ItemBody).to eq(true) + expect(object_value.value[0].cc_recipients[0].instance_of? Files::Recipient).to eq(true) + expect(object_value.value[0].cc_recipients[0].email_address.instance_of? Files::EmailAddress).to eq(true) + + ## String tests + expect(object_value.odata_next_link.instance_of? String).to eq(true) + expect(object_value.value[0].body_preview.instance_of? String).to eq(true) + + ## Boolean tests + expect(object_value.value[0].is_draft.to_s.downcase == "true" || object_value.value[0].is_draft.to_s.downcase == "false").to eq(true) + expect(object_value.value[0].is_read.to_s.downcase == "true" || object_value.value[0].is_read.to_s.downcase == "false").to eq(true) + expect(object_value.value[0].body_preview.to_s.downcase == "true" || object_value.value[0].body_preview.to_s.downcase == "false").to eq(false) + + ## Number tests + expect(object_value.additional_data["numb"].instance_of? Integer).to eq(true) + + ## GUID tests + expect(object_value.value[0].guid_id.instance_of? UUIDTools::UUID).to eq(true) + + ## Date tests + expect(object_value.value[0].received_date_time).to eq(nil) + expect((object_value.value[0].sent_date_time).instance_of? DateTime).to eq(true) + + ## Collection of Primitive values tests + expect(object_value.additional_data["primativeValues"].instance_of? Array).to eq(true) + + ## Collection of object values tests + expect(object_value.value.instance_of? Array).to eq(true) + + ## Enum tests + expect(object_value.value[0].body.content_type.instance_of? Symbol).to eq(true) + end + + it "can serialize payload" do + file = File.open("#{File.dirname(__FILE__)}/sample.json") + data = file.read + file.close + message_response = MicrosoftKiotaSerializationJson::JsonParseNodeFactory.new().get_parse_node("application/json", data) + object_value = message_response.get_object_value(lambda {|pn| Files::MessageCollectionResponse.create_from_discriminator_value(pn)}) + serializer = MicrosoftKiotaSerializationJson::JsonSerializationWriterFactory.new().get_serialization_writer("application/json") + object_value.serialize(serializer) + expect(object_value.value[0].id.to_s == serializer.writer["value"][0]["id"]).to eq(true) + end +end diff --git a/components/serialization/json/spec/sample.json b/components/serialization/json/spec/sample.json new file mode 100644 index 0000000..ecd6eb9 --- /dev/null +++ b/components/serialization/json/spec/sample.json @@ -0,0 +1,73 @@ +{ + "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('607f7b25-541a-4af6-b2f6-562bdf65b448')/messages", + "@odata.nextLink": "https://graph.microsoft.com/v1.0/me/messages?$skip=10", + "numb": 22, + "primativeValues": ["a","b",1,2], + "value": [ + { + "guidId": "093e9e30-440c-4374-84ea-a95821d7cb4c", + "@odata.etag": "W/\"CQAAABYAAABLW5j2RED8SKPe/uUseM8lAAAqleh7\"", + "id": "AAMkADY3ZWJmMDUzLWU5ZmQtNDU2ZS05MTk0LWMxNTg0OTQxNDA1ZgBGAAAAAABUU3b30v09Q7_8TGMESZIYBwBLW5j2RED8SKPe-uUseM8lAAAAAAEMAABLW5j2RED8SKPe-uUseM8lAAAqxrxGAAA=", + "createdDateTime": "2021-08-02T18:14:36Z", + "lastModifiedDateTime": "2021-08-02T18:14:38Z", + "changeKey": "CQAAABYAAABLW5j2RED8SKPe/uUseM8lAAAqleh7", + "categories": ["cat1", "cat2", "cat3"], + "receivedDateTime": null, + "sentDateTime": "2021-08-02T18:14:14Z", + "hasAttachments": false, + "internetMessageId": "", + "subject": "Re: Our processor does not receive events for Permanent Delete", + "bodyPreview": "Hi @Jun Cao,I want to get all deletes (soft + hard) for emails for which our other processors have processed data and patched a property. Our processors ingest and maintain secondary FileItems in the WorkingSet based on links and attachments shared in", + "importance": "normal", + "parentFolderId": "AQMkADY3ZWJmMDUzLWU5ZmQtNDU2ZS05MTk0LWMxNTg0OTQxNDA1ZgAuAAADVFN299L9PUO-vExjBEmSGAEAS1uY9kRA-Eij3v7lLHjPJQAAAgEMAAAA", + "conversationId": "AAQkADY3ZWJmMDUzLWU5ZmQtNDU2ZS05MTk0LWMxNTg0OTQxNDA1ZgAQAD4eTN3FHLlHh-j-zvIITkI=", + "conversationIndex": "AQHXhYCbPh5M3cUcuUeH+P/O8ghOQqtcA1OJgAAMjReAA9KG24AAb7pZgAAgpbCAAA6myw==", + "isDeliveryReceiptRequested": null, + "isReadReceiptRequested": false, + "isRead": false, + "isDraft": false, + "webLink": "https://outlook.office365.com/owa/", + "inferenceClassification": "focused", + "body": { + "contentType": "html", + "content": "" + }, + "sender": { + "emailAddress": { + "name": "Kristian Elsebø", + "address": "krelse@exchange.microsoft.com" + } + }, + "from": { + "emailAddress": { + "name": "Kristian Elsebø", + "address": "krelse@exchange.microsoft.com" + } + }, + "toRecipients": [ + { + "emailAddress": { + "name": "Jun Cao", + "address": "juncao@microsoft.com" + } + }, + { + "emailAddress": { + "name": "Martin Owen", + "address": "mowen@microsoft.com" + } + } + ], + "ccRecipients": [ + { + "emailAddress": { + "name": "FAST Everything Shared", + "address": "fastshared@microsoft.com" + } + } + ], + "bccRecipients": [], + "replyTo": [] + } + ] +} diff --git a/components/serialization/json/spec/spec_helper.rb b/components/serialization/json/spec/spec_helper.rb new file mode 100644 index 0000000..e233ca1 --- /dev/null +++ b/components/serialization/json/spec/spec_helper.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true +require "microsoft_kiota_abstractions" + +Dir["#{File.dirname(__FILE__)}/./../lib/*.rb"].each { |f| load(f) } + +RSpec.configure do |config| + # Enable flags like --only-failures and --next-failure + config.example_status_persistence_file_path = ".rspec_status" + + # Disable RSpec exposing methods globally on `Module` and `main` + config.disable_monkey_patching! + + config.expect_with :rspec do |c| + c.syntax = :expect + end +end diff --git a/release-please-config.json b/release-please-config.json index 3cef212..61c53cf 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -1,15 +1,48 @@ { "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", "packages": { - ".": { + "components/abstractions": { "release-type": "ruby", "package-name": "microsoft_kiota_abstractions", "changelog-path": "CHANGELOG.md", - "include-v-in-tag": true, - "include-component-in-tag": false, - "bump-minor-pre-major": true, - "version-file": "lib/microsoft_kiota_abstractions/version.rb" + "version-file": "lib/microsoft_kiota_abstractions/version.rb", + "component": "microsoft_kiota_abstractions" + }, + "components/serialization/json": { + "release-type": "ruby", + "package-name": "microsoft_kiota_serialization_json", + "changelog-path": "CHANGELOG.md", + "version-file": "lib/microsoft_kiota_serialization_json/version.rb", + "component": "microsoft_kiota_serialization_json" + }, + "components/http": { + "release-type": "ruby", + "package-name": "microsoft_kiota_faraday", + "changelog-path": "CHANGELOG.md", + "version-file": "lib/microsoft_kiota_faraday/version.rb", + "component": "microsoft_kiota_faraday" + }, + "components/authentication/oauth": { + "release-type": "ruby", + "package-name": "microsoft_kiota_authentication_oauth", + "changelog-path": "CHANGELOG.md", + "version-file": "lib/microsoft_kiota_authentication_oauth/version.rb", + "component": "microsoft_kiota_authentication_oauth" } }, - "bootstrap-sha": "aada60935d93a41dd422c94db2e129f24eb30ac9" + "plugins": [ + { + "type": "linked-versions", + "groupName": "kiota-ruby", + "components": [ + "microsoft_kiota_abstractions", + "microsoft_kiota_serialization_json", + "microsoft_kiota_faraday", + "microsoft_kiota_authentication_oauth" + ] + } + ], + "include-v-in-tag": true, + "include-component-in-tag": false, + "bump-minor-pre-major": true } From 84b68beb17688bb08daf33aff7a91240e9e86687 Mon Sep 17 00:00:00 2001 From: andreatp Date: Fri, 21 Aug 2026 16:07:52 +0100 Subject: [PATCH 2/7] chore: single root changelog, normalize formatting, rubocop auto-fix - Switch from per-component changelogs to single root CHANGELOG.md matching kiota-java pattern - Simplify release-please to release-type: simple with version.txt and x-release-please-version markers in version.rb files - Normalize all gemspecs and Rakefiles to consistent formatting (single quotes, aligned fields, unified email) - Fix .gitignore root-anchored patterns for monorepo layout - Run rubocop -A to auto-fix all correctable offenses across all component source files - Add rubocop lint job to CI workflow, rubocop task to root Rakefile, rubocop to root Gemfile, and document in README --- .github/workflows/ruby.yml | 14 +- .release-please-manifest.json | 5 +- .../abstractions/CHANGELOG.md => CHANGELOG.md | 0 Gemfile | 15 +- README.md | 9 +- Rakefile | 26 +- components/abstractions/Rakefile | 4 +- .../lib/microsoft_kiota_abstractions.rb | 48 +- .../api_client_builder.rb | 21 +- .../microsoft_kiota_abstractions/api_error.rb | 38 +- .../authentication/access_token_provider.rb | 7 +- .../authentication/allowed_hosts_validator.rb | 3 +- .../anonymous_authentication_provider.rb | 7 +- .../authentication/authentication_provider.rb | 8 +- ...se_bearer_token_authentication_provider.rb | 7 +- .../base_request_builder.rb | 66 +- .../http_method.rb | 8 +- .../request_adapter.rb | 26 +- .../request_configuration.rb | 36 +- .../request_headers.rb | 112 +- .../request_information.rb | 138 +- .../request_option.rb | 12 +- .../serialization/additional_data_holder.rb | 10 +- .../serialization/composed_type_wrapper.rb | 2 + .../serialization/iso_duration.rb | 127 +- .../serialization/parsable.rb | 8 +- .../serialization/parse_node.rb | 60 +- .../serialization/parse_node_factory.rb | 6 +- .../parse_node_factory_registry.rb | 34 +- .../serialization/parse_node_helper.rb | 2 + .../serialization/serialization_writer.rb | 74 +- .../serialization_writer_factory.rb | 8 +- .../serialization_writer_factory_registry.rb | 25 +- .../microsoft_kiota_abstractions/version.rb | 2 +- .../microsoft_kiota_abstractions.gemspec | 13 +- .../spec/access_token_provider_mock.rb | 16 +- .../spec/microsoft_kiota_abstractions_spec.rb | 118 +- .../spec/parse_node_factory_mock.rb | 19 +- .../spec/parse_node_factory_registry_spec.rb | 28 +- .../spec/query_parameters_mock.rb | 96 +- .../abstractions/spec/request_headers_spec.rb | 94 +- .../spec/request_information_spec.rb | 74 +- .../abstractions/spec/request_option_mock.rb | 10 +- .../spec/serialization_writer_factory_mock.rb | 19 +- ...ialization_writer_factory_registry_spec.rb | 25 +- components/abstractions/spec/spec_helper.rb | 2 +- components/authentication/oauth/CHANGELOG.md | 52 - components/authentication/oauth/Gemfile | 4 +- components/authentication/oauth/Rakefile | 1 - .../microsoft_kiota_authentication_oauth.rb | 18 +- .../contexts/authorization_code_context.rb | 22 +- .../contexts/client_credential_context.rb | 22 +- .../contexts/oauth_context.rb | 38 +- .../contexts/oauth_custom_flow.rb | 38 +- .../contexts/on_behalf_of_context.rb | 115 +- .../extensions/oauth2_ext.rb | 4 +- .../oauth_access_token_provider.rb | 36 +- .../oauth_authentication_provider.rb | 7 +- .../version.rb | 2 +- ...crosoft_kiota_authentication_oauth.gemspec | 29 +- ...crosoft_kiota_authentication_oauth_spec.rb | 92 +- .../authentication/oauth/spec/spec_helper.rb | 3 +- components/http/CHANGELOG.md | 69 - components/http/Gemfile | 4 +- components/http/Rakefile | 2 - .../faraday_request_adapter.rb | 145 +- .../kiota_client_factory.rb | 59 +- .../parameters_name_decoding_handler.rb | 50 +- .../parameters_name_decoding_option.rb | 28 +- .../middleware/response_handler_option.rb | 20 +- .../middleware/user_agent_handler.rb | 46 +- .../middleware/user_agent_option.rb | 33 +- .../lib/microsoft_kiota_faraday/version.rb | 2 +- .../http/microsoft_kiota_faraday.gemspec | 21 +- .../http/spec/authentication_provider.rb | 6 +- .../http/spec/microsoft_kiota_faraday.rb | 9 +- .../faraday_request_adapter_spec.rb | 40 +- .../parameters_name_decoding_handler_spec.rb | 75 +- components/http/spec/spec_helper.rb | 4 +- .../http/spec/user_agent_handler_spec.rb | 76 +- components/serialization/json/CHANGELOG.md | 57 - components/serialization/json/Gemfile | 4 +- components/serialization/json/Rakefile | 4 +- .../lib/microsoft_kiota_serialization_json.rb | 10 +- .../json_parse_node.rb | 19 +- .../json_parse_node_factory.rb | 2 + .../json_serialization_writer.rb | 217 ++- .../json_serialization_writer_factory.rb | 2 + .../version.rb | 2 +- ...microsoft_kiota_serialization_json.gemspec | 25 +- .../json/spec/files/body_type.rb | 10 +- .../json/spec/files/email_address.rb | 183 ++- .../serialization/json/spec/files/entity.rb | 147 +- .../serialization/json/spec/files/files.rb | 22 +- .../json/spec/files/item_body.rb | 183 ++- .../serialization/json/spec/files/message.rb | 1190 ++++++++--------- .../json/spec/files/messages_response.rb | 187 +-- .../json/spec/files/outlook_item.rb | 223 ++- .../json/spec/files/recipient.rb | 151 ++- ...serialization_writer_composed_type_spec.rb | 13 +- ...microsoft_kiota_serialization_json_spec.rb | 62 +- .../serialization/json/spec/spec_helper.rb | 5 +- release-please-config.json | 52 +- version.txt | 1 + 104 files changed, 2612 insertions(+), 2813 deletions(-) rename components/abstractions/CHANGELOG.md => CHANGELOG.md (100%) delete mode 100644 components/authentication/oauth/CHANGELOG.md delete mode 100644 components/http/CHANGELOG.md delete mode 100644 components/serialization/json/CHANGELOG.md create mode 100644 version.txt diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index b6de75e..ade4cd7 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -7,6 +7,18 @@ on: pull_request: jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: ruby/setup-ruby@95ef2b042f9d7a56d8268cba8559e2842e2ad01b # v1.321.0 + with: + ruby-version: '3.4' + bundler-cache: true + bundler: 'latest' + - name: Run rubocop + run: bundle exec rubocop + build: strategy: fail-fast: false @@ -36,7 +48,7 @@ jobs: # Use this as a PR status check for GitHub Policy Service instead of individual matrix entry checks. check-ruby-version-matrix: runs-on: ubuntu-latest - needs: [build] + needs: [lint, build] if: always() steps: - name: All build matrix options are successful diff --git a/.release-please-manifest.json b/.release-please-manifest.json index ab5b69f..7b51ca0 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,6 +1,3 @@ { - "components/abstractions": "0.17.0", - "components/serialization/json": "0.17.0", - "components/http": "0.17.0", - "components/authentication/oauth": "0.17.0" + ".": "0.17.0" } diff --git a/components/abstractions/CHANGELOG.md b/CHANGELOG.md similarity index 100% rename from components/abstractions/CHANGELOG.md rename to CHANGELOG.md diff --git a/Gemfile b/Gemfile index 0213798..aa8a008 100644 --- a/Gemfile +++ b/Gemfile @@ -1,11 +1,12 @@ # frozen_string_literal: true -source "https://rubygems.org" +source 'https://rubygems.org' -gem "microsoft_kiota_abstractions", path: "components/abstractions" -gem "microsoft_kiota_serialization_json", path: "components/serialization/json" -gem "microsoft_kiota_faraday", path: "components/http" -gem "microsoft_kiota_authentication_oauth", path: "components/authentication/oauth" +gem 'microsoft_kiota_abstractions', path: 'components/abstractions' +gem 'microsoft_kiota_authentication_oauth', path: 'components/authentication/oauth' +gem 'microsoft_kiota_faraday', path: 'components/http' +gem 'microsoft_kiota_serialization_json', path: 'components/serialization/json' -gem "rake", "~> 13.0" -gem "rspec", "~> 3.0" +gem 'rake', '~> 13.0' +gem 'rspec', '~> 3.0' +gem 'rubocop' diff --git a/README.md b/README.md index a774b39..31d7e15 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,8 @@ gem "microsoft_kiota_authentication_oauth" git clone https://github.com/microsoft/kiota-ruby.git cd kiota-ruby bundle install -rake spec +rake spec # run all tests +rake rubocop # run linter ``` To run tests for a specific component: @@ -42,6 +43,12 @@ rake http:spec rake authentication-oauth:spec ``` +To auto-fix formatting issues: + +```shell +bundle exec rubocop -a +``` + ## Contributing This project welcomes contributions and suggestions. Most contributions require you to agree to a diff --git a/Rakefile b/Rakefile index c0aea8a..1f2c3f9 100644 --- a/Rakefile +++ b/Rakefile @@ -1,15 +1,15 @@ # frozen_string_literal: true COMPONENTS = { - "abstractions" => "components/abstractions", - "serialization-json" => "components/serialization/json", - "http" => "components/http", - "authentication-oauth" => "components/authentication/oauth", + 'abstractions' => 'components/abstractions', + 'serialization-json' => 'components/serialization/json', + 'http' => 'components/http', + 'authentication-oauth' => 'components/authentication/oauth' }.freeze def run_in_component(dir, command) Dir.chdir(dir) do - sh "bundle install --quiet" unless ENV["CI"] + sh 'bundle install --quiet' unless ENV['CI'] sh command end end @@ -18,30 +18,34 @@ COMPONENTS.each do |name, path| namespace name do desc "Run specs for #{name}" task :spec do - run_in_component(path, "bundle exec rake spec") + run_in_component(path, 'bundle exec rake spec') end desc "Build gem for #{name}" task :build do - run_in_component(path, "bundle exec rake build") + run_in_component(path, 'bundle exec rake build') end end end -desc "Run all component specs" +desc 'Run all component specs' task :spec do COMPONENTS.each do |name, path| puts "\n=== Running specs for #{name} ===" - run_in_component(path, "bundle exec rake spec") + run_in_component(path, 'bundle exec rake spec') end end -desc "Build all gems" +desc 'Build all gems' task :build do COMPONENTS.each do |name, path| puts "\n=== Building #{name} ===" - run_in_component(path, "bundle exec rake build") + run_in_component(path, 'bundle exec rake build') end end +require 'rubocop/rake_task' + +RuboCop::RakeTask.new(:rubocop) + task default: :spec diff --git a/components/abstractions/Rakefile b/components/abstractions/Rakefile index b6ae734..82bb534 100644 --- a/components/abstractions/Rakefile +++ b/components/abstractions/Rakefile @@ -1,7 +1,7 @@ # frozen_string_literal: true -require "bundler/gem_tasks" -require "rspec/core/rake_task" +require 'bundler/gem_tasks' +require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) diff --git a/components/abstractions/lib/microsoft_kiota_abstractions.rb b/components/abstractions/lib/microsoft_kiota_abstractions.rb index b73722b..d7147e6 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions.rb @@ -1,29 +1,29 @@ # frozen_string_literal: true -require_relative "microsoft_kiota_abstractions/authentication/authentication_provider" -require_relative "microsoft_kiota_abstractions/authentication/base_bearer_token_authentication_provider" -require_relative "microsoft_kiota_abstractions/authentication/anonymous_authentication_provider" -require_relative "microsoft_kiota_abstractions/api_error" -require_relative "microsoft_kiota_abstractions/http_method" -require_relative "microsoft_kiota_abstractions/base_request_builder" -require_relative "microsoft_kiota_abstractions/api_client_builder" -require_relative "microsoft_kiota_abstractions/request_adapter" -require_relative "microsoft_kiota_abstractions/request_configuration" -require_relative "microsoft_kiota_abstractions/request_option" -require_relative "microsoft_kiota_abstractions/request_headers" -require_relative "microsoft_kiota_abstractions/request_information" -require_relative "microsoft_kiota_abstractions/version" -require_relative "microsoft_kiota_abstractions/serialization/parsable" -require_relative "microsoft_kiota_abstractions/serialization/iso_duration" -require_relative "microsoft_kiota_abstractions/serialization/additional_data_holder" -require_relative "microsoft_kiota_abstractions/serialization/parse_node" -require_relative "microsoft_kiota_abstractions/serialization/parse_node_factory" -require_relative "microsoft_kiota_abstractions/serialization/parse_node_factory_registry" -require_relative "microsoft_kiota_abstractions/serialization/serialization_writer" -require_relative "microsoft_kiota_abstractions/serialization/serialization_writer_factory" -require_relative "microsoft_kiota_abstractions/serialization/serialization_writer_factory_registry" -require_relative "microsoft_kiota_abstractions/serialization/composed_type_wrapper" -require_relative "microsoft_kiota_abstractions/serialization/parse_node_helper" +require_relative 'microsoft_kiota_abstractions/authentication/authentication_provider' +require_relative 'microsoft_kiota_abstractions/authentication/base_bearer_token_authentication_provider' +require_relative 'microsoft_kiota_abstractions/authentication/anonymous_authentication_provider' +require_relative 'microsoft_kiota_abstractions/api_error' +require_relative 'microsoft_kiota_abstractions/http_method' +require_relative 'microsoft_kiota_abstractions/base_request_builder' +require_relative 'microsoft_kiota_abstractions/api_client_builder' +require_relative 'microsoft_kiota_abstractions/request_adapter' +require_relative 'microsoft_kiota_abstractions/request_configuration' +require_relative 'microsoft_kiota_abstractions/request_option' +require_relative 'microsoft_kiota_abstractions/request_headers' +require_relative 'microsoft_kiota_abstractions/request_information' +require_relative 'microsoft_kiota_abstractions/version' +require_relative 'microsoft_kiota_abstractions/serialization/parsable' +require_relative 'microsoft_kiota_abstractions/serialization/iso_duration' +require_relative 'microsoft_kiota_abstractions/serialization/additional_data_holder' +require_relative 'microsoft_kiota_abstractions/serialization/parse_node' +require_relative 'microsoft_kiota_abstractions/serialization/parse_node_factory' +require_relative 'microsoft_kiota_abstractions/serialization/parse_node_factory_registry' +require_relative 'microsoft_kiota_abstractions/serialization/serialization_writer' +require_relative 'microsoft_kiota_abstractions/serialization/serialization_writer_factory' +require_relative 'microsoft_kiota_abstractions/serialization/serialization_writer_factory_registry' +require_relative 'microsoft_kiota_abstractions/serialization/composed_type_wrapper' +require_relative 'microsoft_kiota_abstractions/serialization/parse_node_helper' module MicrosoftKiotaAbstractions end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/api_client_builder.rb b/components/abstractions/lib/microsoft_kiota_abstractions/api_client_builder.rb index 7cd6079..21d08e1 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/api_client_builder.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/api_client_builder.rb @@ -1,19 +1,22 @@ -require_relative "serialization/parse_node_factory" -require_relative "serialization/parse_node_factory_registry" -require_relative "serialization/serialization_writer_factory" -require_relative "serialization/serialization_writer_factory_registry" +# frozen_string_literal: true + +require_relative 'serialization/parse_node_factory' +require_relative 'serialization/parse_node_factory_registry' +require_relative 'serialization/serialization_writer_factory' +require_relative 'serialization/serialization_writer_factory_registry' module MicrosoftKiotaAbstractions class ApiClientBuilder def self.register_default_serializer(factory_class) - factory = factory_class.new() - MicrosoftKiotaAbstractions::SerializationWriterFactoryRegistry.default_instance.content_type_associated_factories[factory.get_valid_content_type()] = factory + factory = factory_class.new + MicrosoftKiotaAbstractions::SerializationWriterFactoryRegistry.default_instance.content_type_associated_factories[factory.get_valid_content_type] = + factory end def self.register_default_deserializer(factory_class) - factory = factory_class.new() - MicrosoftKiotaAbstractions::ParseNodeFactoryRegistry.default_instance.content_type_associated_factories[factory.get_valid_content_type()] = factory + factory = factory_class.new + MicrosoftKiotaAbstractions::ParseNodeFactoryRegistry.default_instance.content_type_associated_factories[factory.get_valid_content_type] = + factory end end end - diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/api_error.rb b/components/abstractions/lib/microsoft_kiota_abstractions/api_error.rb index a842823..ebc5a69 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/api_error.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/api_error.rb @@ -1,23 +1,25 @@ +# frozen_string_literal: true + require_relative 'serialization/parsable' module MicrosoftKiotaAbstractions - class ApiError < StandardError - include MicrosoftKiotaAbstractions::Parsable + class ApiError < StandardError + include MicrosoftKiotaAbstractions::Parsable - ## - ## The deserialization information for the current model - ## @return a i_dictionary - ## - def get_field_deserializers() - return Hash.new - end - ## - ## Serializes information the current object - ## @param writer Serialization writer to use to serialize this model - ## @return a void - ## - def serialize(writer) - raise StandardError, 'writer cannot be null' if writer.nil? - end + ## + ## The deserialization information for the current model + ## @return a i_dictionary + ## + def get_field_deserializers + {} + end + ## + ## Serializes information the current object + ## @param writer Serialization writer to use to serialize this model + ## @return a void + ## + def serialize(writer) + raise StandardError, 'writer cannot be null' if writer.nil? end -end \ No newline at end of file + end +end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/authentication/access_token_provider.rb b/components/abstractions/lib/microsoft_kiota_abstractions/authentication/access_token_provider.rb index ad3df83..aa356f1 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/authentication/access_token_provider.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/authentication/access_token_provider.rb @@ -7,14 +7,13 @@ module MicrosoftKiotaAbstractions module AccessTokenProvider # This function obtains the authorization token. # :params - # uri: a string containing the uri + # uri: a string containing the uri # additional_params: hash of symbols to string values, ie { response_mode: 'fragment', prompt: 'login' } # default is empty hash - def get_authorization_token(uri, additional_properties = {}) - raise NotImplementedError.new + def get_authorization_token(_uri, _additional_properties = {}) + raise NotImplementedError end attr_accessor :scopes, :host_validator - end end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/authentication/allowed_hosts_validator.rb b/components/abstractions/lib/microsoft_kiota_abstractions/authentication/allowed_hosts_validator.rb index 72379ea..f912e51 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/authentication/allowed_hosts_validator.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/authentication/allowed_hosts_validator.rb @@ -24,11 +24,10 @@ def url_host_valid?(url) parsed_url = URI(url) return false if parsed_url.host.nil? - + return false unless parsed_url.is_a?(URI::HTTPS) @allowed_hosts.key? parsed_url.host.downcase - rescue URI::InvalidURIError false end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/authentication/anonymous_authentication_provider.rb b/components/abstractions/lib/microsoft_kiota_abstractions/authentication/anonymous_authentication_provider.rb index 8c0747a..208a304 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/authentication/anonymous_authentication_provider.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/authentication/anonymous_authentication_provider.rb @@ -1,10 +1,13 @@ +# frozen_string_literal: true + module MicrosoftKiotaAbstractions class AnonymousAuthenticationProvider include MicrosoftKiotaAbstractions::AuthenticationProvider - def authenticate_request(request, additional_properties = {}) + + def authenticate_request(_request, _additional_properties = {}) # return an empty Fiber - all other authentication providers do the same, and the FaradayRequestAdapter requires it. Fiber.new do end end end -end \ No newline at end of file +end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/authentication/authentication_provider.rb b/components/abstractions/lib/microsoft_kiota_abstractions/authentication/authentication_provider.rb index 25aebf6..2c79499 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/authentication/authentication_provider.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/authentication/authentication_provider.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + module MicrosoftKiotaAbstractions module AuthenticationProvider - def authenticate_request(request, additional_properties = {}) - raise NotImplementedError.new - end + def authenticate_request(_request, _additional_properties = {}) + raise NotImplementedError + end end end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/authentication/base_bearer_token_authentication_provider.rb b/components/abstractions/lib/microsoft_kiota_abstractions/authentication/base_bearer_token_authentication_provider.rb index e03fe92..6d476d0 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/authentication/base_bearer_token_authentication_provider.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/authentication/base_bearer_token_authentication_provider.rb @@ -1,17 +1,18 @@ # frozen_string_literal: true -require_relative './authentication_provider' -require_relative './access_token_provider' +require_relative 'authentication_provider' +require_relative 'access_token_provider' module MicrosoftKiotaAbstractions # Provides a base class for implementing AuthenticationProvider for Bearer token scheme class BaseBearerTokenAuthenticationProvider include MicrosoftKiotaAbstractions::AuthenticationProvider + def initialize(access_token_provider) raise StandardError, 'access_token_provider parameter cannot be nil' if access_token_provider.nil? @access_token_provider = access_token_provider - end + end AUTHORIZATION_HEADER_KEY = 'Authorization' def authenticate_request(request, additional_properties = {}) diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/base_request_builder.rb b/components/abstractions/lib/microsoft_kiota_abstractions/base_request_builder.rb index 6b69b0e..46a8b54 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/base_request_builder.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/base_request_builder.rb @@ -1,36 +1,36 @@ +# frozen_string_literal: true + module MicrosoftKiotaAbstractions - ## - # Base class for request builders. Performs basic validation and defines common properties. - class BaseRequestBuilder - ## - # Path parameters for the request - @path_parameters - ## - # The request adapter to use to execute the requests. - @request_adapter - ## - # Url template to use to build the URL for the current request builder - @url_template - ## - ## Instantiates a new BaseRequestBuilder and sets the default values. - ## @param path_parameters Path parameters for the request - ## @param request_adapter The request adapter to use to execute the requests. - ## @param url_template Url template to use to build the URL for the current request builder - ## @return a void - ## - def initialize(path_parameters, request_adapter, url_template) - raise StandardError, 'request_adapter cannot be null' if request_adapter.nil? - raise StandardError, 'url_template cannot be null' if url_template.nil? || url_template.empty? - @request_adapter = request_adapter - unless path_parameters.nil? then - if path_parameters.is_a? Hash then - @path_parameters = path_parameters.clone - elsif path_parameters.is_a? String then - @path_parameters = { "request-raw-url" => path_parameters } - end - end - @path_parameters = Hash.new if path_parameters.nil? - @url_template = url_template + ## + # Base class for request builders. Performs basic validation and defines common properties. + class BaseRequestBuilder + ## + # Path parameters for the request + ## + # The request adapter to use to execute the requests. + ## + # Url template to use to build the URL for the current request builder + ## + ## Instantiates a new BaseRequestBuilder and sets the default values. + ## @param path_parameters Path parameters for the request + ## @param request_adapter The request adapter to use to execute the requests. + ## @param url_template Url template to use to build the URL for the current request builder + ## @return a void + ## + def initialize(path_parameters, request_adapter, url_template) + raise StandardError, 'request_adapter cannot be null' if request_adapter.nil? + raise StandardError, 'url_template cannot be null' if url_template.nil? || url_template.empty? + + @request_adapter = request_adapter + unless path_parameters.nil? + if path_parameters.is_a? Hash + @path_parameters = path_parameters.clone + elsif path_parameters.is_a? String + @path_parameters = { 'request-raw-url' => path_parameters } end + end + @path_parameters = {} if path_parameters.nil? + @url_template = url_template end -end \ No newline at end of file + end +end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/http_method.rb b/components/abstractions/lib/microsoft_kiota_abstractions/http_method.rb index ed7b913..9b1a95d 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/http_method.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/http_method.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true + module MicrosoftKiotaAbstractions module HttpMethod - HTTP_METHOD = { GET: :GET, POST: :POST, @@ -11,7 +12,6 @@ module HttpMethod PUT: :PUT, TRACE: :TRACE, HEAD: :HEAD - } - - end + }.freeze end +end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/request_adapter.rb b/components/abstractions/lib/microsoft_kiota_abstractions/request_adapter.rb index b12a4e7..0888674 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/request_adapter.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/request_adapter.rb @@ -1,30 +1,30 @@ +# frozen_string_literal: true + require_relative 'request_information' module MicrosoftKiotaAbstractions module RequestAdapter - - def send_async(request_info, factory, errors_mapping) - raise NotImplementedError.new + def send_async(_request_info, _factory, _errors_mapping) + raise NotImplementedError end - # TODO we're most likley missing something for enums and collections or at least at the implemenation level + # TODO: we're most likley missing something for enums and collections or at least at the implemenation level - def get_serialization_writer_factory() - raise NotImplementedError.new + def get_serialization_writer_factory + raise NotImplementedError end - def set_base_url(base_url) - raise NotImplementedError.new + def set_base_url(_base_url) + raise NotImplementedError end - def get_base_url() - raise NotImplementedError.new + def get_base_url + raise NotImplementedError end # Converts the given RequestInformation into a native HTTP request. - def convert_to_native_request_async(request_info) - raise NotImplementedError.new + def convert_to_native_request_async(_request_info) + raise NotImplementedError end - end end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/request_configuration.rb b/components/abstractions/lib/microsoft_kiota_abstractions/request_configuration.rb index 5c8abf4..f8f44ee 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/request_configuration.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/request_configuration.rb @@ -1,22 +1,24 @@ +# frozen_string_literal: true + require_relative 'request_headers' module MicrosoftKiotaAbstractions - ## - # Configuration for the request such as headers, query parameters, and middleware options. - class RequestConfiguration - ## - # Request headers - attr_accessor :headers - ## - # Request options - attr_accessor :options - ## - # Request query parameters - attr_accessor :query_parameters + ## + # Configuration for the request such as headers, query parameters, and middleware options. + class RequestConfiguration + ## + # Request headers + attr_accessor :headers + ## + # Request options + attr_accessor :options + ## + # Request query parameters + attr_accessor :query_parameters - def initialize - @headers = RequestHeaders.new - @options = Array.new - end + def initialize + @headers = RequestHeaders.new + @options = [] end -end \ No newline at end of file + end +end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/request_headers.rb b/components/abstractions/lib/microsoft_kiota_abstractions/request_headers.rb index 307ecf0..c417215 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/request_headers.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/request_headers.rb @@ -1,56 +1,60 @@ +# frozen_string_literal: true + module MicrosoftKiotaAbstractions - class RequestHeaders - def initialize() - @headers = Hash.new - end - def add(key, value) - if key.nil? || key.empty? || value.nil? || value.empty? then - raise ArgumentError, 'key and value cannot be nil or empty' - end - existing_value = @headers[key] - if existing_value.nil? then - if value.kind_of?(Array) then - @headers[key] = value - else - @headers[key] = Array[value.to_s] - end - else - if value.kind_of?(Array) then - @headers[key] = existing_value | value - else - existing_value << value.to_s - end - end - end - def try_add(key, value) - if key.nil? || key.empty? || value.nil? || value.empty? then - raise ArgumentError, 'key and value cannot be nil or empty' - end - existing_value = @headers[key] - if existing_value.nil? || existing_value.empty? then - @headers[key] = Array[value.to_s] - return true - else - return false - end - end - def get(key) - if key.nil? || key.empty? then - raise ArgumentError, 'key cannot be nil or empty' - end - return @headers[key] - end - def remove(key) - if key.nil? || key.empty? then - raise ArgumentError, 'key cannot be nil or empty' - end - @headers.delete(key) - end - def clear() - @headers.clear() - end - def get_all() - return @headers - end + class RequestHeaders + def initialize + @headers = {} end -end \ No newline at end of file + + def add(key, value) + if key.nil? || key.empty? || value.nil? || value.empty? + raise ArgumentError, 'key and value cannot be nil or empty' + end + + existing_value = @headers[key] + if existing_value.nil? + @headers[key] = if value.is_a?(Array) + value + else + [value.to_s] + end + elsif value.is_a?(Array) + @headers[key] = existing_value | value + else + existing_value << value.to_s + end + end + + def try_add(key, value) + if key.nil? || key.empty? || value.nil? || value.empty? + raise ArgumentError, 'key and value cannot be nil or empty' + end + + existing_value = @headers[key] + return false unless existing_value.nil? || existing_value.empty? + + @headers[key] = [value.to_s] + true + end + + def get(key) + raise ArgumentError, 'key cannot be nil or empty' if key.nil? || key.empty? + + @headers[key] + end + + def remove(key) + raise ArgumentError, 'key cannot be nil or empty' if key.nil? || key.empty? + + @headers.delete(key) + end + + def clear + @headers.clear + end + + def get_all + @headers + end + end +end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/request_information.rb b/components/abstractions/lib/microsoft_kiota_abstractions/request_information.rb index f78c9e9..8ef6d40 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/request_information.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/request_information.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'uri' require 'stduritemplate' require_relative 'http_method' @@ -7,75 +9,65 @@ module MicrosoftKiotaAbstractions class RequestInformation attr_reader :content, :http_method, :headers attr_accessor :url_template, :path_parameters, :query_parameters + @@binary_content_type = 'application/octet-stream' @@content_type_header = 'Content-Type' @@raw_url_key = 'request-raw-url' - def initialize() + def initialize @headers = RequestHeaders.new - @query_parameters = Hash.new - @path_parameters = Hash.new + @query_parameters = {} + @path_parameters = {} end - + def uri=(arg) - if arg.nil? || arg.empty? - raise ArgumentError, 'arg cannot be nil or empty' - end - self.path_parameters.clear() - self.query_parameters.clear() + raise ArgumentError, 'arg cannot be nil or empty' if arg.nil? || arg.empty? + + path_parameters.clear + query_parameters.clear @uri = URI(arg) end def uri - if @uri != nil - return @uri - else - if self.path_parameters[@@raw_url_key] != nil - self.uri = self.path_parameters[@@raw_url_key] - return @uri - else - return URI(StdUriTemplate.expand(@url_template, self.path_parameters.merge(self.query_parameters))) - end + return @uri unless @uri.nil? + + if path_parameters[@@raw_url_key].nil? + return URI(StdUriTemplate.expand(@url_template, path_parameters.merge(query_parameters))) end + + self.uri = path_parameters[@@raw_url_key] + @uri end def add_request_options(request_options_to_add) - unless request_options_to_add.nil? then - @request_options ||= Hash.new - unless request_options_to_add.kind_of?(Array) then - request_options_to_add = [request_options_to_add] - end - request_options_to_add.each do |request_option| - key = request_option.get_key - @request_options[key] = request_option - end + return if request_options_to_add.nil? + + @request_options ||= {} + request_options_to_add = [request_options_to_add] unless request_options_to_add.is_a?(Array) + request_options_to_add.each do |request_option| + key = request_option.get_key + @request_options[key] = request_option end end - def get_request_options() - if @request_options.nil? then - return [] - else - return @request_options.values - end + def get_request_options + return [] if @request_options.nil? + + @request_options.values end def get_request_option(key) - if @request_options.nil? || key.nil? || key.empty? then - return nil - else - return @request_options[key] - end + return nil if @request_options.nil? || key.nil? || key.empty? + + @request_options[key] end def remove_request_options(keys) - unless keys.nil? || @request_options.nil? then - unless keys.kind_of?(Array) then - keys = [keys] - end - keys.each do |key| - @request_options.delete(key) - end + return if keys.nil? || @request_options.nil? + + keys = [keys] unless keys.is_a?(Array) + keys.each do |key| + @request_options.delete(key) end end @@ -85,48 +77,44 @@ def http_method=(method) def set_stream_content(value = $stdin, content_type) @content = value - if content_type.nil? || content_type.empty? - content_type = @@binary_content_type - end + content_type = @@binary_content_type if content_type.nil? || content_type.empty? @headers.try_add(@@content_type_header, content_type) end def set_content_from_parsable(request_adapter, content_type, values) - begin - writer = request_adapter.get_serialization_writer_factory().get_serialization_writer(content_type) - @headers.try_add(@@content_type_header, content_type) - if values != nil && values.kind_of?(Array) - writer.write_collection_of_object_values(nil, values) - else - writer.write_object_value(nil, values); - end - @content = writer.get_serialized_content(); - rescue => exception - raise Exception.new "could not serialize payload" + writer = request_adapter.get_serialization_writer_factory.get_serialization_writer(content_type) + @headers.try_add(@@content_type_header, content_type) + if !values.nil? && values.is_a?(Array) + writer.write_collection_of_object_values(nil, values) + else + writer.write_object_value(nil, values) end + @content = writer.get_serialized_content + rescue StandardError + raise StandardError, 'could not serialize payload' end def add_headers_from_raw_object(h) - h.get_all.select{|x,y| @headers.add(x.to_s, y)} unless !h + h&.get_all&.select { |x, y| @headers.add(x.to_s, y) } end - + def set_query_string_parameters_from_raw_object(q) - if !q || q.is_a?(Hash) || q.is_a?(Array) - return - end - q.class.instance_methods(false).select{|x| + return if !q || q.is_a?(Hash) || q.is_a?(Array) + + q.class.instance_methods(false).select do |x| method_name = x.to_s - unless method_name == "compare_by_identity" || method_name == "get_query_parameter" || method_name.end_with?("=") || method_name.end_with?("?") || method_name.end_with?("!") then - begin - key = q.get_query_parameter(method_name) - rescue => exception - key = method_name - end - value = eval("q.#{method_name}") - self.query_parameters[key] = value unless value.nil? + if method_name == 'compare_by_identity' || method_name == 'get_query_parameter' || method_name.end_with?('=') || method_name.end_with?('?') || method_name.end_with?('!') + next end - } - end + begin + key = q.get_query_parameter(method_name) + rescue StandardError + key = method_name + end + value = eval("q.#{method_name}") + query_parameters[key] = value unless value.nil? + end + end end end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/request_option.rb b/components/abstractions/lib/microsoft_kiota_abstractions/request_option.rb index ce47d69..43284da 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/request_option.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/request_option.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + module MicrosoftKiotaAbstractions - module RequestOption - def get_key() - raise NotImplementedError.new - end + module RequestOption + def get_key + raise NotImplementedError end -end \ No newline at end of file + end +end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/additional_data_holder.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/additional_data_holder.rb index 13cb1b9..7f819cb 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/additional_data_holder.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/additional_data_holder.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + module MicrosoftKiotaAbstractions - module AdditionalDataHolder - def additional_data - @additional_data ||= Hash.new - end + module AdditionalDataHolder + def additional_data + @additional_data ||= {} end + end end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/composed_type_wrapper.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/composed_type_wrapper.rb index 278b8c0..6880ba9 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/composed_type_wrapper.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/composed_type_wrapper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module MicrosoftKiotaAbstractions module ComposedTypeWrapper end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/iso_duration.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/iso_duration.rb index 74b49d5..d2a840a 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/iso_duration.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/iso_duration.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'iso8601' module MicrosoftKiotaAbstractions @@ -9,22 +10,22 @@ module MicrosoftKiotaAbstractions class ISODuration attr_reader :years, :months, :weeks, :days, :hours, :minutes, :seconds - UNITS = { :years => 'Y', - :months => 'M', - :weeks => 'W', - :days => 'D', - :hours => 'H', - :minutes => 'M', - :seconds => 'S'} + UNITS = { years: 'Y', + months: 'M', + weeks: 'W', + days: 'D', + hours: 'H', + minutes: 'M', + seconds: 'S' }.freeze CONVERSIONS = { - :ms_to_s => 1000, - :s_to_m => 60, - :m_to_h => 60, - :h_to_d => 24, - :d_to_w => 7, - :m_to_y => 12 - } + ms_to_s: 1000, + s_to_m: 60, + m_to_h: 60, + h_to_d: 24, + d_to_w: 7, + m_to_y: 12 + }.freeze def initialize(input) if input.is_a? String @duration_obj = ISO8601::Duration.new(input) @@ -38,16 +39,16 @@ def initialize(input) end def string - input = { :seconds => @seconds, :minutes => @minutes, :hours => @hours, - :days => @days, :weeks => @weeks, :months => @months, - :years => @years } + input = { seconds: @seconds, minutes: @minutes, hours: @hours, + days: @days, weeks: @weeks, months: @months, + years: @years } iso_str = 'P' UNITS.each do |unit, abrev| iso_str += input[unit].to_s + abrev unless input[unit].zero? iso_str += 'T' if unit == :days end iso_str = iso_str.strip - iso_str = iso_str.chomp('T') if (iso_str[-1]).eql? 'T' + iso_str = iso_str.chomp('T') if iso_str[-1].eql? 'T' iso_str end @@ -64,74 +65,74 @@ def normalize @days += (@hours / CONVERSIONS[:h_to_d]).floor @hours %= CONVERSIONS[:h_to_d] end - if @days >= CONVERSIONS[:d_to_w] && @months == 0 && @years == 0 + if @days >= CONVERSIONS[:d_to_w] && @months.zero? && @years.zero? @weeks += (@days / CONVERSIONS[:d_to_w]).floor @days %= CONVERSIONS[:d_to_w] end - if @months > CONVERSIONS[:m_to_y] - @years += (@months / CONVERSIONS[:m_to_y]).floor - @months %= CONVERSIONS[:m_to_y] - end + return unless @months > CONVERSIONS[:m_to_y] + + @years += (@months / CONVERSIONS[:m_to_y]).floor + @months %= CONVERSIONS[:m_to_y] end def seconds=(value) - input = { :seconds => value, :minutes => @minutes, :hours => @hours, - :days => @days, :weeks => @weeks, :months => @months, - :years => @years } + input = { seconds: value, minutes: @minutes, hours: @hours, + days: @days, weeks: @weeks, months: @months, + years: @years } @duration_obj = parse_hash(input) @seconds = value normalize end def minutes=(value) - input = { :seconds => @seconds, :minutes => value, :hours => @hours, - :days => @days, :weeks => @weeks, :months => @months, - :years => @years } + input = { seconds: @seconds, minutes: value, hours: @hours, + days: @days, weeks: @weeks, months: @months, + years: @years } @duration_obj = parse_hash(input) @minutes = value normalize end def hours=(value) - input = { :seconds => @seconds, :minutes => @minutes, :hours => value, - :days => @days, :weeks => @weeks, :months => @months, - :years => @years } + input = { seconds: @seconds, minutes: @minutes, hours: value, + days: @days, weeks: @weeks, months: @months, + years: @years } @duration_obj = parse_hash(input) @hours = value normalize end def days=(value) - input = { :seconds => @seconds, :minutes => @minutes, :hours => @hours, - :days => value, :weeks => @weeks, :months => @months, - :years => @years } + input = { seconds: @seconds, minutes: @minutes, hours: @hours, + days: value, weeks: @weeks, months: @months, + years: @years } @duration_obj = parse_hash(input) @days = value normalize end def weeks=(value) - input = { :seconds => @seconds, :minutes => @minutes, :hours => @hours, - :days => @days, :weeks => value, :months => @months, - :years => @years } + input = { seconds: @seconds, minutes: @minutes, hours: @hours, + days: @days, weeks: value, months: @months, + years: @years } @duration_obj = parse_hash(input) @weeks = value normalize end def months=(value) - input = { :seconds => @seconds, :minutes => @minutes, :hours => @hours, - :days => @days, :weeks => @weeks, :months => value, - :years => @years } + input = { seconds: @seconds, minutes: @minutes, hours: @hours, + days: @days, weeks: @weeks, months: value, + years: @years } @duration_obj = parse_hash(input) @months = value normalize end def years=(value) - input = { :seconds => @seconds, :minutes => @minutes, :hours => @hours, - :days => @days, :weeks => @weeks, :months => @months, - :years => value } + input = { seconds: @seconds, minutes: @minutes, hours: @hours, + days: @days, weeks: @weeks, months: @months, + years: value } @duration_obj = parse_hash(input) @years = value normalize @@ -140,16 +141,16 @@ def years=(value) def abs @duration_obj = @duration_obj.abs update_member_variables - return self + self end def +(other) - new_obj = self.duration_obj + other.duration_obj + new_obj = duration_obj + other.duration_obj MicrosoftKiotaAbstractions::ISODuration.new(dur_obj_to_hash(new_obj)) end def -(other) - new_obj = self.duration_obj - other.duration_obj + new_obj = duration_obj - other.duration_obj MicrosoftKiotaAbstractions::ISODuration.new(dur_obj_to_hash(new_obj)) end @@ -172,7 +173,7 @@ def eql?(other) def parse_hash(input) iso_str = 'P' - input.each do |keys, values| + input.each_key do |keys| raise StandardError, "The key #{keys} is not recognized" unless UNITS.key?(keys) end UNITS.each do |unit, abrev| @@ -180,29 +181,29 @@ def parse_hash(input) iso_str += 'T' if unit == :days end iso_str = iso_str.strip - iso_str = iso_str.chomp('T') if (iso_str[-1]).eql? 'T' + iso_str = iso_str.chomp('T') if iso_str[-1].eql? 'T' ISO8601::Duration.new(iso_str) end def update_member_variables - @seconds = @duration_obj.seconds.nil? ? 0 : ((@duration_obj.seconds.to_s).split('S')[0]).to_i - @minutes = @duration_obj.minutes.nil? ? 0 : ((@duration_obj.minutes.to_s).split('H')[0]).to_i - @hours = @duration_obj.hours.nil? ? 0 : ((@duration_obj.hours.to_s).split('H')[0]).to_i - @days = @duration_obj.days.nil? ? 0 : ((@duration_obj.days.to_s).split('D')[0]).to_i - @weeks = @duration_obj.weeks.nil? ? 0 : ((@duration_obj.weeks.to_s).split('W')[0]).to_i - @months = @duration_obj.months.nil? ? 0 : ((@duration_obj.months.to_s).split('M')[0]).to_i - @years = @duration_obj.years.nil? ? 0 : ((@duration_obj.years.to_s).split('Y')[0]).to_i + @seconds = @duration_obj.seconds.nil? ? 0 : @duration_obj.seconds.to_s.split('S')[0].to_i + @minutes = @duration_obj.minutes.nil? ? 0 : @duration_obj.minutes.to_s.split('H')[0].to_i + @hours = @duration_obj.hours.nil? ? 0 : @duration_obj.hours.to_s.split('H')[0].to_i + @days = @duration_obj.days.nil? ? 0 : @duration_obj.days.to_s.split('D')[0].to_i + @weeks = @duration_obj.weeks.nil? ? 0 : @duration_obj.weeks.to_s.split('W')[0].to_i + @months = @duration_obj.months.nil? ? 0 : @duration_obj.months.to_s.split('M')[0].to_i + @years = @duration_obj.years.nil? ? 0 : @duration_obj.years.to_s.split('Y')[0].to_i end def dur_obj_to_hash(dur_obj) result_hash = {} - result_hash[:seconds] = dur_obj.seconds.nil? ? 0 : ((dur_obj.seconds.to_s).split('S')[0]).to_i - result_hash[:minutes] = dur_obj.minutes.nil? ? 0 : ((dur_obj.minutes.to_s).split('H')[0]).to_i - result_hash[:hours] = dur_obj.hours.nil? ? 0 : ((dur_obj.hours.to_s).split('H')[0]).to_i - result_hash[:days] = dur_obj.days.nil? ? 0 : ((dur_obj.days.to_s).split('D')[0]).to_i - result_hash[:weeks] = dur_obj.weeks.nil? ? 0 : ((dur_obj.weeks.to_s).split('W')[0]).to_i - result_hash[:months] = dur_obj.months.nil? ? 0 : ((dur_obj.months.to_s).split('M')[0]).to_i - result_hash[:years] = dur_obj.years.nil? ? 0 : ((dur_obj.years.to_s).split('Y')[0]).to_i + result_hash[:seconds] = dur_obj.seconds.nil? ? 0 : dur_obj.seconds.to_s.split('S')[0].to_i + result_hash[:minutes] = dur_obj.minutes.nil? ? 0 : dur_obj.minutes.to_s.split('H')[0].to_i + result_hash[:hours] = dur_obj.hours.nil? ? 0 : dur_obj.hours.to_s.split('H')[0].to_i + result_hash[:days] = dur_obj.days.nil? ? 0 : dur_obj.days.to_s.split('D')[0].to_i + result_hash[:weeks] = dur_obj.weeks.nil? ? 0 : dur_obj.weeks.to_s.split('W')[0].to_i + result_hash[:months] = dur_obj.months.nil? ? 0 : dur_obj.months.to_s.split('M')[0].to_i + result_hash[:years] = dur_obj.years.nil? ? 0 : dur_obj.years.to_s.split('Y')[0].to_i result_hash end end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parsable.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parsable.rb index a5a6785..600101b 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parsable.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parsable.rb @@ -1,11 +1,13 @@ +# frozen_string_literal: true + module MicrosoftKiotaAbstractions module Parsable def get_field_deserializers - raise NotImplementedError.new + raise NotImplementedError end - def serialize(writer) - raise NotImplementedError.new + def serialize(_writer) + raise NotImplementedError end end end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node.rb index f3dacfb..028b821 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node.rb @@ -1,61 +1,61 @@ +# frozen_string_literal: true + module MicrosoftKiotaAbstractions module ParseNode - - def get_string_value() - raise NotImplementedError.new + def get_string_value + raise NotImplementedError end - def get_boolean_value() - raise NotImplementedError.new + def get_boolean_value + raise NotImplementedError end - def get_number_value() - raise NotImplementedError.new + def get_number_value + raise NotImplementedError end - def get_guid_value() - raise NotImplementedError.new + def get_guid_value + raise NotImplementedError end - def get_date_value() - raise NotImplementedError.new + def get_date_value + raise NotImplementedError end - def get_time_value() - raise NotImplementedError.new + def get_time_value + raise NotImplementedError end - def get_date_time_value() - raise NotImplementedError.new + def get_date_time_value + raise NotImplementedError end - def get_duration_value() - raise NotImplementedError.new + def get_duration_value + raise NotImplementedError end - def get_collection_of_primitive_values() - raise NotImplementedError.new + def get_collection_of_primitive_values + raise NotImplementedError end - def get_collection_of_object_values(factory) - raise NotImplementedError.new + def get_collection_of_object_values(_factory) + raise NotImplementedError end - def get_object_value(factory) - raise NotImplementedError.new + def get_object_value(_factory) + raise NotImplementedError end - def assign_field_values(item) - raise NotImplementedError.new + def assign_field_values(_item) + raise NotImplementedError end - def get_enum_value(type) - raise NotImplementedError.new + def get_enum_value(_type) + raise NotImplementedError end - def get_child_node(name) - raise NotImplementedError.new + def get_child_node(_name) + raise NotImplementedError end - end end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_factory.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_factory.rb index 78e22af..7b661c2 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_factory.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_factory.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + module MicrosoftKiotaAbstractions module ParseNodeFactory - def ParseNodeFactory.get_parse_node(content_type, content) - raise NotImplementedError.new + def self.get_parse_node(_content_type, _content) + raise NotImplementedError end end end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_factory_registry.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_factory_registry.rb index da4196c..2658147 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_factory_registry.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_factory_registry.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'parse_node_factory' module MicrosoftKiotaAbstractions @@ -5,38 +7,32 @@ class ParseNodeFactoryRegistry include ParseNodeFactory class << self - attr_accessor :default_instance - def default_instance; @default_instance ||= ParseNodeFactoryRegistry.new; end + attr_accessor :default_instance + + def default_instance = @default_instance ||= ParseNodeFactoryRegistry.new end def default_instance - self.class.default_instance + self.class.default_instance end def content_type_associated_factories - @content_type_associated_factories ||= Hash.new + @content_type_associated_factories ||= {} end def get_parse_node(content_type, content) - if !content_type - raise Exception.new 'content type cannot be undefined or empty' - end - if !content - raise Exception.new 'content cannot be undefined or empty' - end + raise StandardError, 'content type cannot be undefined or empty' unless content_type + raise StandardError, 'content cannot be undefined or empty' unless content + vendor_specific_content_type = content_type.split(';').first factory = @content_type_associated_factories[vendor_specific_content_type] - if factory - return factory.get_parse_node(vendor_specific_content_type, content) - end + return factory.get_parse_node(vendor_specific_content_type, content) if factory - clean_content_type = vendor_specific_content_type.gsub(/[^\/]+\+/i, '') + clean_content_type = vendor_specific_content_type.gsub(%r{[^/]+\+}i, '') factory = @content_type_associated_factories[clean_content_type] - if factory - return factory.get_parse_node(clean_content_type, content) - end - raise Exception.new "Content type #{contentType} does not have a factory to be parsed" + return factory.get_parse_node(clean_content_type, content) if factory + + raise StandardError, "Content type #{contentType} does not have a factory to be parsed" end - end end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_helper.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_helper.rb index 35e33c0..f695f83 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_helper.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module MicrosoftKiotaAbstractions class ParseNodeHelper def self.merge_deserializers_for_intersection_wrapper(*targets) diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer.rb index 3746f67..216eb4c 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer.rb @@ -1,73 +1,73 @@ +# frozen_string_literal: true + module MicrosoftKiotaAbstractions module SerializationWriter - - def write_string_value(key, value) - raise NotImplementedError.new + def write_string_value(_key, _value) + raise NotImplementedError end - def write_boolean_value(key, value) - raise NotImplementedError.new + def write_boolean_value(_key, _value) + raise NotImplementedError end - def write_number_value(key, value) - raise NotImplementedError.new + def write_number_value(_key, _value) + raise NotImplementedError end - def write_float_value(key, value) - raise NotImplementedError.new + def write_float_value(_key, _value) + raise NotImplementedError end - def get_date_value(key, value) - raise NotImplementedError.new + def get_date_value(_key, _value) + raise NotImplementedError end - def write_guid_value(key, value) - raise NotImplementedError.new + def write_guid_value(_key, _value) + raise NotImplementedError end - def write_date_value(key, value) - raise NotImplementedError.new - end - - def write_time_value(key, value) - raise NotImplementedError.new + def write_date_value(_key, _value) + raise NotImplementedError end - def write_date_time_value(key, value) - raise NotImplementedError.new + def write_time_value(_key, _value) + raise NotImplementedError end - def write_duration_value(key, value) - raise NotImplementedError.new + def write_date_time_value(_key, _value) + raise NotImplementedError end - def write_collection_of_primitive_values(key, value) - raise NotImplementedError.new + def write_duration_value(_key, _value) + raise NotImplementedError end - def write_collection_of_object_values(key, value) - raise NotImplementedError.new + def write_collection_of_primitive_values(_key, _value) + raise NotImplementedError end - def write_enum_value(key, value) - raise NotImplementedError.new + def write_collection_of_object_values(_key, _value) + raise NotImplementedError end - def get_serialized_content() - raise NotImplementedError.new + def write_enum_value(_key, _value) + raise NotImplementedError end - def write_additional_data(type) - raise NotImplementedError.new + def get_serialized_content + raise NotImplementedError end - def write_any_value(key, value) - raise NotImplementedError.new + def write_additional_data(_type) + raise NotImplementedError end - def write_object_value(key, value, *additional_values_to_merge) - raise NotImplementedError.new + def write_any_value(_key, _value) + raise NotImplementedError end + def write_object_value(_key, _value, *_additional_values_to_merge) + raise NotImplementedError + end end end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory.rb index 640ce59..b6ad0f3 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory.rb @@ -1,9 +1,9 @@ +# frozen_string_literal: true + module MicrosoftKiotaAbstractions module SerializationWriterFactory - - def get_serialization_writer(content_type) - raise NotImplementedError.new + def get_serialization_writer(_content_type) + raise NotImplementedError end - end end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory_registry.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory_registry.rb index 08a3365..c5e7865 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory_registry.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory_registry.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'serialization_writer_factory' module MicrosoftKiotaAbstractions @@ -6,7 +8,8 @@ class SerializationWriterFactoryRegistry class << self attr_accessor :default_instance - def default_instance; @default_instance ||= SerializationWriterFactoryRegistry.new; end + + def default_instance = @default_instance ||= SerializationWriterFactoryRegistry.new end def default_instance @@ -14,27 +17,21 @@ def default_instance end def content_type_associated_factories - @content_type_associated_factories ||= Hash.new + @content_type_associated_factories ||= {} end def get_serialization_writer(content_type) - if !content_type - raise Exception.new 'content type cannot be undefined or empty' - end + raise StandardError, 'content type cannot be undefined or empty' unless content_type + vendor_specific_content_type = content_type.split(';').first factory = @content_type_associated_factories[vendor_specific_content_type] - if factory - return factory.get_serialization_writer(vendor_specific_content_type) - end + return factory.get_serialization_writer(vendor_specific_content_type) if factory - clean_content_type = vendor_specific_content_type.gsub(/[^\/]+\+/i, '') + clean_content_type = vendor_specific_content_type.gsub(%r{[^/]+\+}i, '') factory = @content_type_associated_factories[clean_content_type] - if factory - return factory.get_serialization_writer(clean_content_type) - end + return factory.get_serialization_writer(clean_content_type) if factory - raise Exception.new "Content type #{contentType} does not have a factory to be serialized" + raise StandardError, "Content type #{contentType} does not have a factory to be serialized" end - end end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/version.rb b/components/abstractions/lib/microsoft_kiota_abstractions/version.rb index aa84da6..fc50b3a 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/version.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module MicrosoftKiotaAbstractions - VERSION = "0.17.0" + VERSION = '0.17.0' # x-release-please-version end diff --git a/components/abstractions/microsoft_kiota_abstractions.gemspec b/components/abstractions/microsoft_kiota_abstractions.gemspec index 10bcd9c..08becc6 100644 --- a/components/abstractions/microsoft_kiota_abstractions.gemspec +++ b/components/abstractions/microsoft_kiota_abstractions.gemspec @@ -13,23 +13,22 @@ Gem::Specification.new do |spec| spec.license = 'MIT' spec.metadata = { 'bug_tracker_uri' => 'https://github.com/microsoft/kiota-ruby/issues', - 'changelog_uri' => 'https://github.com/microsoft/kiota-ruby/blob/main/components/abstractions/CHANGELOG.md', - 'homepage_uri' => spec.homepage, + 'changelog_uri' => 'https://github.com/microsoft/kiota-ruby/blob/main/CHANGELOG.md', + 'homepage_uri' => spec.homepage, 'source_code_uri' => 'https://github.com/microsoft/kiota-ruby/tree/main/components/abstractions', - 'github_repo' => 'ssh://github.com/microsoft/kiota-ruby' + 'github_repo' => 'ssh://github.com/microsoft/kiota-ruby', + 'rubygems_mfa_required' => 'true' } spec.required_ruby_version = '>= 3.3.0' - # Specify which files should be added to the gem when it is released. - # The `git ls-files -z` loads the files in the RubyGem that have been added into git. spec.files = Dir.chdir(File.expand_path(__dir__)) do `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) } end spec.bindir = 'bin' spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.add_runtime_dependency 'stduritemplate', '>= 0.0.39', '< 1.1.0' - spec.add_runtime_dependency 'iso8601', '~> 0.13.0' + spec.add_dependency 'iso8601', '~> 0.13.0' + spec.add_dependency 'stduritemplate', '>= 0.0.39', '< 1.1.0' spec.add_development_dependency 'rake', '~> 13.0' spec.add_development_dependency 'rspec', '~> 3.0' spec.add_development_dependency 'rubocop' diff --git a/components/abstractions/spec/access_token_provider_mock.rb b/components/abstractions/spec/access_token_provider_mock.rb index 31e60f4..07546f5 100644 --- a/components/abstractions/spec/access_token_provider_mock.rb +++ b/components/abstractions/spec/access_token_provider_mock.rb @@ -1,12 +1,14 @@ +# frozen_string_literal: true + require 'microsoft_kiota_abstractions' class AccessTokenProviderMock extend MicrosoftKiotaAbstractions::AccessTokenProvider - - DUMMY_TOKEN = 'DummyToken' - def get_authorization_token(uri, additional_properties = {}) - Fiber.new do - DUMMY_TOKEN - end + + DUMMY_TOKEN = 'DummyToken' + def get_authorization_token(_uri, _additional_properties = {}) + Fiber.new do + DUMMY_TOKEN end -end \ No newline at end of file + end +end diff --git a/components/abstractions/spec/microsoft_kiota_abstractions_spec.rb b/components/abstractions/spec/microsoft_kiota_abstractions_spec.rb index d441520..2a4e562 100644 --- a/components/abstractions/spec/microsoft_kiota_abstractions_spec.rb +++ b/components/abstractions/spec/microsoft_kiota_abstractions_spec.rb @@ -1,110 +1,116 @@ # frozen_string_literal: true + require 'uri' require 'microsoft_kiota_abstractions' require_relative 'access_token_provider_mock' RSpec.describe MicrosoftKiotaAbstractions do - it "has a version number" do + it 'has a version number' do expect(MicrosoftKiotaAbstractions::VERSION).not_to be nil end - it "tests library method" do + it 'tests library method' do request_obj = MicrosoftKiotaAbstractions::RequestInformation.new expect(!request_obj).to eq(false) end - it "creates a anonymous token provider" do - token_provider = MicrosoftKiotaAbstractions::AnonymousAuthenticationProvider.new() + it 'creates a anonymous token provider' do + token_provider = MicrosoftKiotaAbstractions::AnonymousAuthenticationProvider.new expect(token_provider).not_to be nil # Authentication does nothing besides returning an empty Fiber token_provider.authenticate_request(nil).resume end - it "creates a token authentication provider with existing authorization header" do - access_token_provider = AccessTokenProviderMock.new() + it 'creates a token authentication provider with existing authorization header' do + access_token_provider = AccessTokenProviderMock.new token_provider = MicrosoftKiotaAbstractions::BaseBearerTokenAuthenticationProvider.new(access_token_provider) expect(token_provider).not_to be nil request_obj = MicrosoftKiotaAbstractions::RequestInformation.new - request_obj.headers.add(MicrosoftKiotaAbstractions::BaseBearerTokenAuthenticationProvider::AUTHORIZATION_HEADER_KEY, "SAMPLE") + request_obj.headers.add( + MicrosoftKiotaAbstractions::BaseBearerTokenAuthenticationProvider::AUTHORIZATION_HEADER_KEY, 'SAMPLE' + ) # Authentication does nothing besides returning an empty Fiber token_provider.authenticate_request(request_obj).resume # The request header should not have changed - expect(request_obj.headers.get(MicrosoftKiotaAbstractions::BaseBearerTokenAuthenticationProvider::AUTHORIZATION_HEADER_KEY).at(0)).to eq "SAMPLE" + expect(request_obj.headers.get(MicrosoftKiotaAbstractions::BaseBearerTokenAuthenticationProvider::AUTHORIZATION_HEADER_KEY).at(0)).to eq 'SAMPLE' end - it "creates a token authentication provider with mock access token" do - access_token_provider = AccessTokenProviderMock.new() + it 'creates a token authentication provider with mock access token' do + access_token_provider = AccessTokenProviderMock.new token_provider = MicrosoftKiotaAbstractions::BaseBearerTokenAuthenticationProvider.new(access_token_provider) expect(token_provider).not_to be nil request_obj = MicrosoftKiotaAbstractions::RequestInformation.new # We have to set a URI, otherwise the code will fail ("undefined method 'chars' for nil") - request_obj.uri = "http://sample.com" + request_obj.uri = 'http://sample.com' token_provider.authenticate_request(request_obj).resume # The request header should now contain the "DUMMY_TOKEN" value: expect(request_obj.headers.get(MicrosoftKiotaAbstractions::BaseBearerTokenAuthenticationProvider::AUTHORIZATION_HEADER_KEY).at(0)).to eq "Bearer #{AccessTokenProviderMock::DUMMY_TOKEN}" end - it "returns the raw URI when set via setter" do + it 'returns the raw URI when set via setter' do request_obj = MicrosoftKiotaAbstractions::RequestInformation.new - request_obj.path_parameters["term"] = "search" - request_obj.query_parameters["q1"] = "option1" - request_obj.uri = "https://www.bing.com" - expect(request_obj.uri).to eq(URI("https://www.bing.com")) + request_obj.path_parameters['term'] = 'search' + request_obj.query_parameters['q1'] = 'option1' + request_obj.uri = 'https://www.bing.com' + expect(request_obj.uri).to eq(URI('https://www.bing.com')) expect(request_obj.path_parameters).to eq({}) expect(request_obj.query_parameters).to eq({}) end - it "returns the raw URI when set via raw url parmeter" do + it 'returns the raw URI when set via raw url parmeter' do request_obj = MicrosoftKiotaAbstractions::RequestInformation.new - request_obj.path_parameters["request-raw-url"] = "https://www.bing.com" - expect(request_obj.path_parameters).to eq({ "request-raw-url" => "https://www.bing.com"}) - request_obj.path_parameters["term"] = "search" - request_obj.query_parameters["q1"] = "option1" - expect(request_obj.uri).to eq(URI("https://www.bing.com")) + request_obj.path_parameters['request-raw-url'] = 'https://www.bing.com' + expect(request_obj.path_parameters).to eq({ 'request-raw-url' => 'https://www.bing.com' }) + request_obj.path_parameters['term'] = 'search' + request_obj.query_parameters['q1'] = 'option1' + expect(request_obj.uri).to eq(URI('https://www.bing.com')) expect(request_obj.path_parameters).to eq({}) expect(request_obj.query_parameters).to eq({}) end - it "returns a templated url" do + it 'returns a templated url' do request_obj = MicrosoftKiotaAbstractions::RequestInformation.new - request_obj.url_template = "https://www.bing.com/{term}{?q1,q2}" - request_obj.path_parameters["term"] = "search" - request_obj.query_parameters["q1"] = "option1" - expect(request_obj.uri).to eq(URI("https://www.bing.com/search?q1=option1")) + request_obj.url_template = 'https://www.bing.com/{term}{?q1,q2}' + request_obj.path_parameters['term'] = 'search' + request_obj.query_parameters['q1'] = 'option1' + expect(request_obj.uri).to eq(URI('https://www.bing.com/search?q1=option1')) end - it "initializes a duration with ISO-formatted string or hash" do - time1 = MicrosoftKiotaAbstractions::ISODuration.new("P2Y1MT2H") - time2 = MicrosoftKiotaAbstractions::ISODuration.new({ :years => 2, :months => 1, :hours => 2 } ) + it 'initializes a duration with ISO-formatted string or hash' do + time1 = MicrosoftKiotaAbstractions::ISODuration.new('P2Y1MT2H') + time2 = MicrosoftKiotaAbstractions::ISODuration.new({ years: 2, months: 1, hours: 2 }) expect(time1).to eq(time2) end - it "fails on malformed string inputs" do - expect { MicrosoftKiotaAbstractions::ISODuration.new("P2Y1M3WT2H") }.to raise_error ISO8601::Errors::UnknownPattern + it 'fails on malformed string inputs' do + expect { MicrosoftKiotaAbstractions::ISODuration.new('P2Y1M3WT2H') }.to raise_error ISO8601::Errors::UnknownPattern end - it "fails on malformed hash inputs" do - expect { MicrosoftKiotaAbstractions::ISODuration.new({ :laughter => 2, :months => 1, :hours => 2 }) }.to raise_error('The key laughter is not recognized') + it 'fails on malformed hash inputs' do + expect do + MicrosoftKiotaAbstractions::ISODuration.new({ laughter: 2, months: 1, + hours: 2 }) + end.to raise_error('The key laughter is not recognized') end - it "handles addition" do - time1 = MicrosoftKiotaAbstractions::ISODuration.new("P2Y1MT2H") - time2 = MicrosoftKiotaAbstractions::ISODuration.new({ :years => 2, :months => 1, :hours => 2 } ) + it 'handles addition' do + time1 = MicrosoftKiotaAbstractions::ISODuration.new('P2Y1MT2H') + time2 = MicrosoftKiotaAbstractions::ISODuration.new({ years: 2, months: 1, hours: 2 }) time3 = time1 + time2 - expect(time3.string).to eq(MicrosoftKiotaAbstractions::ISODuration.new("P4Y2MT4H").string) + expect(time3.string).to eq(MicrosoftKiotaAbstractions::ISODuration.new('P4Y2MT4H').string) end - it "handles subtraction" do - time1 = MicrosoftKiotaAbstractions::ISODuration.new("P4Y2MT2H") - time2 = MicrosoftKiotaAbstractions::ISODuration.new({ :years => 1, :months => 1, :hours => 2 } ) + it 'handles subtraction' do + time1 = MicrosoftKiotaAbstractions::ISODuration.new('P4Y2MT2H') + time2 = MicrosoftKiotaAbstractions::ISODuration.new({ years: 1, months: 1, hours: 2 }) time3 = time1 - time2 - expect(time3.string).to eq(MicrosoftKiotaAbstractions::ISODuration.new("P3Y1M").string) + expect(time3.string).to eq(MicrosoftKiotaAbstractions::ISODuration.new('P3Y1M').string) end - it "handles equality comparisons" do - time1 = MicrosoftKiotaAbstractions::ISODuration.new("P4Y2MT2H") - time2 = MicrosoftKiotaAbstractions::ISODuration.new({ :years => 4, :months => 2, :hours => 2 } ) + it 'handles equality comparisons' do + time1 = MicrosoftKiotaAbstractions::ISODuration.new('P4Y2MT2H') + time2 = MicrosoftKiotaAbstractions::ISODuration.new({ years: 4, months: 2, hours: 2 }) expect(time1).to eq(time2) end @@ -114,24 +120,28 @@ end it 'initializes non-empty/cased allowed hosts properly' do - ahv = MicrosoftKiotaAbstractions::AllowedHostsValidator.new(['microsoft.com', 'Graph.microsoft.com', 'DOD-graph.microsoft.us']) + ahv = MicrosoftKiotaAbstractions::AllowedHostsValidator.new(['microsoft.com', 'Graph.microsoft.com', + 'DOD-graph.microsoft.us']) valid_hosts = ahv.allowed_hosts - expect(valid_hosts).to eq({'microsoft.com' => true, 'graph.microsoft.com' => true, 'dod-graph.microsoft.us' => true}) + expect(valid_hosts).to eq({ 'microsoft.com' => true, 'graph.microsoft.com' => true, + 'dod-graph.microsoft.us' => true }) end it 'tests the setter for allowed hosts on allowed hosts validator' do - ahv = MicrosoftKiotaAbstractions::AllowedHostsValidator.new(['microsoft.com', 'Graph.microsoft.com', 'DOD-graph.microsoft.us']) + ahv = MicrosoftKiotaAbstractions::AllowedHostsValidator.new(['microsoft.com', 'Graph.microsoft.com', + 'DOD-graph.microsoft.us']) ahv.allowed_hosts = ['MICROSOFT.com', 'GRAPH.microsoft.COM', 'DOD-graph.microsoft.us', 'graph.microsoft.de'] - expect(ahv.allowed_hosts).to eq({'microsoft.com' => true, 'graph.microsoft.com' => true, 'dod-graph.microsoft.us' => true, 'graph.microsoft.de' => true}) + expect(ahv.allowed_hosts).to eq({ 'microsoft.com' => true, 'graph.microsoft.com' => true, + 'dod-graph.microsoft.us' => true, 'graph.microsoft.de' => true }) end it 'tests url_host_valid? method on malformed and valid urls' do ahv = MicrosoftKiotaAbstractions::AllowedHostsValidator.new(['www.google.com', 'example.com', 'Graph.microsoft.com', - 'DOD-graph.microsoft.us', "cool/groovy/art"]) - url1 = ahv.url_host_valid?("https://www.google.com") - url2 = ahv.url_host_valid?("htts://google.com") - url3 = ahv.url_host_valid?("cool/groovy/art") - url4 = ahv.url_host_valid?("https://example.com") + 'DOD-graph.microsoft.us', 'cool/groovy/art']) + url1 = ahv.url_host_valid?('https://www.google.com') + url2 = ahv.url_host_valid?('htts://google.com') + url3 = ahv.url_host_valid?('cool/groovy/art') + url4 = ahv.url_host_valid?('https://example.com') url5 = ahv.url_host_valid?('https%3A%2F%2Fwww.example.com') url6 = ahv.url_host_valid?('%3A%2F%2F') expect(url1).to eq(true) diff --git a/components/abstractions/spec/parse_node_factory_mock.rb b/components/abstractions/spec/parse_node_factory_mock.rb index 37af7bb..35c7062 100644 --- a/components/abstractions/spec/parse_node_factory_mock.rb +++ b/components/abstractions/spec/parse_node_factory_mock.rb @@ -1,11 +1,14 @@ +# frozen_string_literal: true + require 'microsoft_kiota_abstractions' class ParseNodeFactoryMock - include MicrosoftKiotaAbstractions::ParseNodeFactory + include MicrosoftKiotaAbstractions::ParseNodeFactory + + def get_valid_content_type + 'application/json' + end - def get_valid_content_type - 'application/json' - end - def get_parse_node(clean_content_type, content) - return {} - end -end \ No newline at end of file + def get_parse_node(_clean_content_type, _content) + {} + end +end diff --git a/components/abstractions/spec/parse_node_factory_registry_spec.rb b/components/abstractions/spec/parse_node_factory_registry_spec.rb index 7b7732d..37af0b6 100644 --- a/components/abstractions/spec/parse_node_factory_registry_spec.rb +++ b/components/abstractions/spec/parse_node_factory_registry_spec.rb @@ -1,16 +1,20 @@ +# frozen_string_literal: true + require 'microsoft_kiota_abstractions' require_relative 'parse_node_factory_mock' RSpec.describe MicrosoftKiotaAbstractions do - values = [] - values << "application/json" - values << "application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8" - values << "application/vnd.github.mercy-preview+json" - values << "application/vnd.github.mercy-preview+json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8" - serialized_value = "[1]" - MicrosoftKiotaAbstractions::ParseNodeFactoryRegistry.default_instance.content_type_associated_factories["application/json"] = ParseNodeFactoryMock.new - it "gets the parse node" do - values.each do |value| - expect(MicrosoftKiotaAbstractions::ParseNodeFactoryRegistry.default_instance.get_parse_node(value, serialized_value)).not_to be nil - end + values = [] + values << 'application/json' + values << 'application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8' + values << 'application/vnd.github.mercy-preview+json' + values << 'application/vnd.github.mercy-preview+json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8' + serialized_value = '[1]' + MicrosoftKiotaAbstractions::ParseNodeFactoryRegistry.default_instance.content_type_associated_factories['application/json'] = + ParseNodeFactoryMock.new + it 'gets the parse node' do + values.each do |value| + expect(MicrosoftKiotaAbstractions::ParseNodeFactoryRegistry.default_instance.get_parse_node(value, + serialized_value)).not_to be nil end -end \ No newline at end of file + end +end diff --git a/components/abstractions/spec/query_parameters_mock.rb b/components/abstractions/spec/query_parameters_mock.rb index e4c3bbf..0c53acc 100644 --- a/components/abstractions/spec/query_parameters_mock.rb +++ b/components/abstractions/spec/query_parameters_mock.rb @@ -1,49 +1,51 @@ +# frozen_string_literal: true + class QueryParametersMock - - ## - # Include count of items - attr_accessor :count - ## - # Filter items by property values - attr_accessor :filter - ## - # Order items by property values - attr_accessor :orderby - ## - # Search items by search phrases - attr_accessor :search - ## - # Select properties to be returned - attr_accessor :select - ## - # Skip the first n items - attr_accessor :skip - ## - # Show only the first n items - attr_accessor :top - ## - ## Maps the query parameters names to their encoded names for the URI template parsing. - ## @param originalName The original query parameter name in the class. - ## @return a string - ## - def get_query_parameter(original_name) - case original_name - when "count" - return "%24count" - when "filter" - return "%24filter" - when "orderby" - return "%24orderby" - when "search" - return "%24search" - when "select" - return "%24select" - when "skip" - return "%24skip" - when "top" - return "%24top" - else - return originalName - end + ## + # Include count of items + attr_accessor :count + ## + # Filter items by property values + attr_accessor :filter + ## + # Order items by property values + attr_accessor :orderby + ## + # Search items by search phrases + attr_accessor :search + ## + # Select properties to be returned + attr_accessor :select + ## + # Skip the first n items + attr_accessor :skip + ## + # Show only the first n items + attr_accessor :top + + ## + ## Maps the query parameters names to their encoded names for the URI template parsing. + ## @param originalName The original query parameter name in the class. + ## @return a string + ## + def get_query_parameter(original_name) + case original_name + when 'count' + '%24count' + when 'filter' + '%24filter' + when 'orderby' + '%24orderby' + when 'search' + '%24search' + when 'select' + '%24select' + when 'skip' + '%24skip' + when 'top' + '%24top' + else + originalName end -end \ No newline at end of file + end +end diff --git a/components/abstractions/spec/request_headers_spec.rb b/components/abstractions/spec/request_headers_spec.rb index ea5dd17..6403803 100644 --- a/components/abstractions/spec/request_headers_spec.rb +++ b/components/abstractions/spec/request_headers_spec.rb @@ -1,53 +1,55 @@ +# frozen_string_literal: true + require 'microsoft_kiota_abstractions' RSpec.describe MicrosoftKiotaAbstractions do - it "adds a request header to the request information" do - request_info = MicrosoftKiotaAbstractions::RequestInformation.new - request_info.headers.add("key", "value") - expect(request_info.headers.get_all.length).to eq(1) - expect(request_info.headers.get("key").length).to eq(1) - expect(request_info.headers.get("key").first).to eq("value") - end + it 'adds a request header to the request information' do + request_info = MicrosoftKiotaAbstractions::RequestInformation.new + request_info.headers.add('key', 'value') + expect(request_info.headers.get_all.length).to eq(1) + expect(request_info.headers.get('key').length).to eq(1) + expect(request_info.headers.get('key').first).to eq('value') + end - it "adds a request header to the request information when one value is already present" do - request_info = MicrosoftKiotaAbstractions::RequestInformation.new - request_info.headers.add("key", "value") - request_info.headers.add("key", "value2") - expect(request_info.headers.get_all.length).to eq(1) - expect(request_info.headers.get("key").length).to eq(2) - expect(request_info.headers.get("key").first).to eq("value") - expect(request_info.headers.get("key").last).to eq("value2") - end + it 'adds a request header to the request information when one value is already present' do + request_info = MicrosoftKiotaAbstractions::RequestInformation.new + request_info.headers.add('key', 'value') + request_info.headers.add('key', 'value2') + expect(request_info.headers.get_all.length).to eq(1) + expect(request_info.headers.get('key').length).to eq(2) + expect(request_info.headers.get('key').first).to eq('value') + expect(request_info.headers.get('key').last).to eq('value2') + end - it "try to add a request header to the request information" do - request_info = MicrosoftKiotaAbstractions::RequestInformation.new - result1 = request_info.headers.try_add("key", "value") - result2 = request_info.headers.try_add("key", "value2") - expect(result1).to eq(true) - expect(result2).to eq(false) - expect(request_info.headers.get_all.length).to eq(1) - expect(request_info.headers.get("key").length).to eq(1) - expect(request_info.headers.get("key").first).to eq("value") - end + it 'try to add a request header to the request information' do + request_info = MicrosoftKiotaAbstractions::RequestInformation.new + result1 = request_info.headers.try_add('key', 'value') + result2 = request_info.headers.try_add('key', 'value2') + expect(result1).to eq(true) + expect(result2).to eq(false) + expect(request_info.headers.get_all.length).to eq(1) + expect(request_info.headers.get('key').length).to eq(1) + expect(request_info.headers.get('key').first).to eq('value') + end - it "removes a request header from the request information" do - request_info = MicrosoftKiotaAbstractions::RequestInformation.new - request_info.headers.add("key", "value") - expect(request_info.headers.get_all.length).to eq(1) - request_info.headers.remove("key") - expect(request_info.headers.get_all.length).to eq(0) - end + it 'removes a request header from the request information' do + request_info = MicrosoftKiotaAbstractions::RequestInformation.new + request_info.headers.add('key', 'value') + expect(request_info.headers.get_all.length).to eq(1) + request_info.headers.remove('key') + expect(request_info.headers.get_all.length).to eq(0) + end - it "doesnt fail when removing a value if none are present" do - request_info = MicrosoftKiotaAbstractions::RequestInformation.new - request_info.headers.remove("key") - expect(request_info.headers.get_all.length).to eq(0) - end + it 'doesnt fail when removing a value if none are present' do + request_info = MicrosoftKiotaAbstractions::RequestInformation.new + request_info.headers.remove('key') + expect(request_info.headers.get_all.length).to eq(0) + end - it "clears the request headers from the request information" do - request_info = MicrosoftKiotaAbstractions::RequestInformation.new - request_info.headers.add("key", "value") - expect(request_info.headers.get_all.length).to eq(1) - request_info.headers.clear - expect(request_info.headers.get_all.length).to eq(0) - end -end \ No newline at end of file + it 'clears the request headers from the request information' do + request_info = MicrosoftKiotaAbstractions::RequestInformation.new + request_info.headers.add('key', 'value') + expect(request_info.headers.get_all.length).to eq(1) + request_info.headers.clear + expect(request_info.headers.get_all.length).to eq(0) + end +end diff --git a/components/abstractions/spec/request_information_spec.rb b/components/abstractions/spec/request_information_spec.rb index 445bc85..3ad5c9c 100644 --- a/components/abstractions/spec/request_information_spec.rb +++ b/components/abstractions/spec/request_information_spec.rb @@ -1,45 +1,45 @@ +# frozen_string_literal: true + require 'microsoft_kiota_abstractions' require_relative 'request_option_mock' require_relative 'query_parameters_mock' RSpec.describe MicrosoftKiotaAbstractions do + it 'adds a request option to the request information' do + request_info = MicrosoftKiotaAbstractions::RequestInformation.new + mock_option = RequestOptionMock.new + mock_option.value = 'value' + request_info.add_request_options(mock_option) + expect(request_info.get_request_options.length).to eq(1) + expect(request_info.get_request_option('key')).to eq(mock_option) + end - it "adds a request option to the request information" do - request_info = MicrosoftKiotaAbstractions::RequestInformation.new - mock_option = RequestOptionMock.new - mock_option.value = "value" - request_info.add_request_options(mock_option) - expect(request_info.get_request_options().length).to eq(1) - expect(request_info.get_request_option("key")).to eq(mock_option) - end - - it "removes a request option from the request information" do - request_info = MicrosoftKiotaAbstractions::RequestInformation.new - mock_option = RequestOptionMock.new - mock_option.value = "value" - request_info.add_request_options(mock_option) - expect(request_info.get_request_options().length).to eq(1) - request_info.remove_request_options("key") - expect(request_info.get_request_options().length).to eq(0) - end - - it "adds query parameters with their escaped values" do - request_info = MicrosoftKiotaAbstractions::RequestInformation.new - query_parameters = QueryParametersMock.new - query_parameters.select = "foo,bar" - request_info.set_query_string_parameters_from_raw_object(query_parameters) - expect(request_info.query_parameters.length).to eq(1) - expect(request_info.query_parameters["%24select"]).to eq("foo,bar") - expect(request_info.query_parameters["select"]).to be_nil - end + it 'removes a request option from the request information' do + request_info = MicrosoftKiotaAbstractions::RequestInformation.new + mock_option = RequestOptionMock.new + mock_option.value = 'value' + request_info.add_request_options(mock_option) + expect(request_info.get_request_options.length).to eq(1) + request_info.remove_request_options('key') + expect(request_info.get_request_options.length).to eq(0) + end - it "doesn't fail adding query parameters with anonymous object" do - request_info = MicrosoftKiotaAbstractions::RequestInformation.new - query_parameters = { - select: "foo,bar" - } - request_info.set_query_string_parameters_from_raw_object(query_parameters) - expect(request_info.query_parameters.length).to eq(0) - end + it 'adds query parameters with their escaped values' do + request_info = MicrosoftKiotaAbstractions::RequestInformation.new + query_parameters = QueryParametersMock.new + query_parameters.select = 'foo,bar' + request_info.set_query_string_parameters_from_raw_object(query_parameters) + expect(request_info.query_parameters.length).to eq(1) + expect(request_info.query_parameters['%24select']).to eq('foo,bar') + expect(request_info.query_parameters['select']).to be_nil + end -end \ No newline at end of file + it "doesn't fail adding query parameters with anonymous object" do + request_info = MicrosoftKiotaAbstractions::RequestInformation.new + query_parameters = { + select: 'foo,bar' + } + request_info.set_query_string_parameters_from_raw_object(query_parameters) + expect(request_info.query_parameters.length).to eq(0) + end +end diff --git a/components/abstractions/spec/request_option_mock.rb b/components/abstractions/spec/request_option_mock.rb index 4b91552..49a28fb 100644 --- a/components/abstractions/spec/request_option_mock.rb +++ b/components/abstractions/spec/request_option_mock.rb @@ -1,8 +1,12 @@ +# frozen_string_literal: true + require 'microsoft_kiota_abstractions' class RequestOptionMock include MicrosoftKiotaAbstractions::RequestOption + attr_accessor :value - def get_key() - return "key" + + def get_key + 'key' end -end \ No newline at end of file +end diff --git a/components/abstractions/spec/serialization_writer_factory_mock.rb b/components/abstractions/spec/serialization_writer_factory_mock.rb index f48f32b..82d503d 100644 --- a/components/abstractions/spec/serialization_writer_factory_mock.rb +++ b/components/abstractions/spec/serialization_writer_factory_mock.rb @@ -1,11 +1,14 @@ +# frozen_string_literal: true + require 'microsoft_kiota_abstractions' class SerializationWriterFactoryMock - include MicrosoftKiotaAbstractions::SerializationWriterFactory + include MicrosoftKiotaAbstractions::SerializationWriterFactory + + def get_valid_content_type + 'application/json' + end - def get_valid_content_type - 'application/json' - end - def get_serialization_writer(clean_content) - return {} - end -end \ No newline at end of file + def get_serialization_writer(_clean_content) + {} + end +end diff --git a/components/abstractions/spec/serialization_writer_factory_registry_spec.rb b/components/abstractions/spec/serialization_writer_factory_registry_spec.rb index 0e3e165..c0ad9da 100644 --- a/components/abstractions/spec/serialization_writer_factory_registry_spec.rb +++ b/components/abstractions/spec/serialization_writer_factory_registry_spec.rb @@ -1,15 +1,18 @@ +# frozen_string_literal: true + require 'microsoft_kiota_abstractions' require_relative 'serialization_writer_factory_mock' RSpec.describe MicrosoftKiotaAbstractions do - values = [] - values << "application/json" - values << "application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8" - values << "application/vnd.github.mercy-preview+json" - values << "application/vnd.github.mercy-preview+json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8" - MicrosoftKiotaAbstractions::SerializationWriterFactoryRegistry.default_instance.content_type_associated_factories["application/json"] = SerializationWriterFactoryMock.new - it "gets the serialization writer" do - values.each do |value| - expect(MicrosoftKiotaAbstractions::SerializationWriterFactoryRegistry.default_instance.get_serialization_writer(value)).not_to be nil - end + values = [] + values << 'application/json' + values << 'application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8' + values << 'application/vnd.github.mercy-preview+json' + values << 'application/vnd.github.mercy-preview+json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8' + MicrosoftKiotaAbstractions::SerializationWriterFactoryRegistry.default_instance.content_type_associated_factories['application/json'] = + SerializationWriterFactoryMock.new + it 'gets the serialization writer' do + values.each do |value| + expect(MicrosoftKiotaAbstractions::SerializationWriterFactoryRegistry.default_instance.get_serialization_writer(value)).not_to be nil end -end \ No newline at end of file + end +end diff --git a/components/abstractions/spec/spec_helper.rb b/components/abstractions/spec/spec_helper.rb index b960d8c..7ee4005 100644 --- a/components/abstractions/spec/spec_helper.rb +++ b/components/abstractions/spec/spec_helper.rb @@ -2,7 +2,7 @@ RSpec.configure do |config| # Enable flags like --only-failures and --next-failure - config.example_status_persistence_file_path = ".rspec_status" + config.example_status_persistence_file_path = '.rspec_status' # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_patching! diff --git a/components/authentication/oauth/CHANGELOG.md b/components/authentication/oauth/CHANGELOG.md deleted file mode 100644 index 2ad597e..0000000 --- a/components/authentication/oauth/CHANGELOG.md +++ /dev/null @@ -1,52 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [0.9.0](https://github.com/microsoft/kiota-authentication-oauth-ruby/compare/v0.8.0...v0.9.0) (2026-04-23) - - -### Features - -* upgrade ruby CI matrix to 3.3, 3.4 and 4.0 ([11dcef4](https://github.com/microsoft/kiota-authentication-oauth-ruby/commit/11dcef469492e12d7f81a781818300aac080929f)) -* upgrade ruby CI matrix to 3.3, 3.4 and 4.0 ([d76fa2a](https://github.com/microsoft/kiota-authentication-oauth-ruby/commit/d76fa2a1889da1331ac0e0f17af8edd396736610)) - - -### Bug Fixes - -* update minimum required ruby version to 3.3.0 ([552f23f](https://github.com/microsoft/kiota-authentication-oauth-ruby/commit/552f23f8f80e37ada087c4b25faacf184dae869f)) -* update minimum required ruby version to 3.3.0 ([97d915c](https://github.com/microsoft/kiota-authentication-oauth-ruby/commit/97d915ca475600c2e26a85df79df6f538b99288f)) - -## [Unreleased] - -### Added - -### Changed - -## [0.8.0] - 2023-03-28 - -### Changed - -- Updated kiota abstractions reference -- Bumped minimum required ruby version to 3.0. - -## [0.7.0] - 2023-01-17 - -### Changed - -- Removed Microsoft Graph specific defaults. -- Fixed an issue where the access token provider would fail on return. - -## [0.6.0] - 2023-01-16 - -### Changed - -- Fixed a bug where the authentication provider would fail to load. - -## [0.5.0] - 2022-12-30 - -### Added - -- Initial public release of the package. diff --git a/components/authentication/oauth/Gemfile b/components/authentication/oauth/Gemfile index 37d7d74..f4859ea 100644 --- a/components/authentication/oauth/Gemfile +++ b/components/authentication/oauth/Gemfile @@ -1,7 +1,7 @@ # frozen_string_literal: true -source "https://rubygems.org" +source 'https://rubygems.org' -gem "microsoft_kiota_abstractions", path: "../../abstractions" +gem 'microsoft_kiota_abstractions', path: '../../abstractions' gemspec diff --git a/components/authentication/oauth/Rakefile b/components/authentication/oauth/Rakefile index 2856f1c..82bb534 100644 --- a/components/authentication/oauth/Rakefile +++ b/components/authentication/oauth/Rakefile @@ -1,6 +1,5 @@ # frozen_string_literal: true - require 'bundler/gem_tasks' require 'rspec/core/rake_task' diff --git a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth.rb b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth.rb index bafb08f..8af70d2 100644 --- a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth.rb +++ b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -require_relative "microsoft_kiota_authentication_oauth/version" -require_relative "microsoft_kiota_authentication_oauth/contexts/authorization_code_context" -require_relative "microsoft_kiota_authentication_oauth/contexts/client_credential_context" -require_relative "microsoft_kiota_authentication_oauth/contexts/on_behalf_of_context" -require_relative "microsoft_kiota_authentication_oauth/contexts/oauth_context" -require_relative "microsoft_kiota_authentication_oauth/contexts/oauth_custom_flow" -require_relative "microsoft_kiota_authentication_oauth/extensions/oauth2_ext" -require_relative "microsoft_kiota_authentication_oauth/oauth_access_token_provider" -require_relative "microsoft_kiota_authentication_oauth/oauth_authentication_provider" +require_relative 'microsoft_kiota_authentication_oauth/version' +require_relative 'microsoft_kiota_authentication_oauth/contexts/authorization_code_context' +require_relative 'microsoft_kiota_authentication_oauth/contexts/client_credential_context' +require_relative 'microsoft_kiota_authentication_oauth/contexts/on_behalf_of_context' +require_relative 'microsoft_kiota_authentication_oauth/contexts/oauth_context' +require_relative 'microsoft_kiota_authentication_oauth/contexts/oauth_custom_flow' +require_relative 'microsoft_kiota_authentication_oauth/extensions/oauth2_ext' +require_relative 'microsoft_kiota_authentication_oauth/oauth_access_token_provider' +require_relative 'microsoft_kiota_authentication_oauth/oauth_authentication_provider' module MicrosoftKiotaAuthenticationOAuth end diff --git a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_context.rb b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_context.rb index 433fc0e..43855d1 100644 --- a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_context.rb +++ b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_context.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'oauth2' -require_relative './oauth_context' +require_relative 'oauth_context' module MicrosoftKiotaAuthenticationOAuth # Token request context class for the authorization code grant type. @@ -11,10 +11,10 @@ class AuthorizationCodeContext < MicrosoftKiotaAuthenticationOAuth::OAuthContext attr_writer :scopes # This is the initializer for AuthorizationCodeContext, the token request context when - # using the authorization code grant flow. + # using the authorization code grant flow. # :params - # tenant_id: a string containing the tenant id - # client_id: a string containing the client id + # tenant_id: a string containing the tenant id + # client_id: a string containing the client id # client_secret: a string containing the client secret # redirect_uri: a string containing redirect_uri # auth_code: a string containting the auth code; default is nil, can be updated post-initialization @@ -49,11 +49,11 @@ def auth_code=(code) # default is empty hash def generate_authorize_url(scopes, additional_params = {}) @additional_params = additional_params - - self.initialize_scopes(scopes) - self.initialize_oauth_provider - parameters = { scope: @scopes, redirect_uri: @redirect_uri, access_type: 'offline', prompt: 'consent'} + initialize_scopes(scopes) + initialize_oauth_provider + + parameters = { scope: @scopes, redirect_uri: @redirect_uri, access_type: 'offline', prompt: 'consent' } parameters = parameters.merge(additional_params) @oauth_provider.auth_code.authorize_url(parameters) end @@ -71,10 +71,10 @@ def initialize_oauth_provider def initialize_scopes(scopes) scope_str = '' - scopes.each { |scope| scope_str += scope + ' '} + scopes.each { |scope| scope_str += "#{scope} " } raise StandardError, 'scopes cannot be empty/nil.' if scope_str.empty? - - scope_str = 'offline_access ' + scope_str + + scope_str = "offline_access #{scope_str}" @scopes = scope_str end diff --git a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb index c2ef8d7..c0f28aa 100644 --- a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb +++ b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb @@ -1,19 +1,19 @@ # frozen_string_literal: true require 'oauth2' -require_relative './oauth_context' +require_relative 'oauth_context' module MicrosoftKiotaAuthenticationOAuth # Token request context class for the client credential grant type. class ClientCredentialContext < MicrosoftKiotaAuthenticationOAuth::OAuthContext attr_reader :grant_type, :additional_params, :tenant_id, :client_id, :client_secret, :oauth_provider - attr_writer :scopes + attr_writer :scopes # This is the initializer for ClientCredentialContext, the token request context when - # using the client credential grant flow. + # using the client credential grant flow. # :params - # tenant_id: a string containing the tenant id - # client_id: a string containing the client id + # tenant_id: a string containing the tenant id + # client_id: a string containing the client id # client_secret: a string containing the client secret # additional_params: hash of symbols to string values, ie { response_mode: 'fragment', prompt: 'login' } # default is empty hash @@ -26,7 +26,6 @@ def initialize(tenant_id, client_id, client_secret, additional_params = {}) @oauth_provider = nil @grant_type = 'client credential' - if @tenant_id.nil? || @client_id.nil? || @client_secret.nil? || @tenant_id.empty? || @client_id.empty? || @client_secret.empty? raise StandardError, 'tenant_id, client_id and client_secret cannot be empty' end @@ -38,20 +37,19 @@ def get_token def initialize_oauth_provider @oauth_provider = OAuth2::Client.new(@client_id, @client_secret, - site: 'https://login.microsoftonline.com', - authorize_url: "/#{@tenant_id}/oauth2/v2.0/authorize", - token_url: "/#{@tenant_id}/oauth2/v2.0/token") + site: 'https://login.microsoftonline.com', + authorize_url: "/#{@tenant_id}/oauth2/v2.0/authorize", + token_url: "/#{@tenant_id}/oauth2/v2.0/token") end # Function to initialize the scope for the client credential context object. # Only a single scope is supported for this flow and it's expected to be schme://service/.default - def initialize_scopes(scopes = []) + def initialize_scopes(scopes = []) @scopes = scopes[0] unless scopes.empty? end - private - + attr_writer :grant_type, :additional_params, :tenant_id, :client_id, :client_secret, :oauth_provider end end diff --git a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/oauth_context.rb b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/oauth_context.rb index e9578f7..851cee2 100644 --- a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/oauth_context.rb +++ b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/oauth_context.rb @@ -1,30 +1,30 @@ # frozen_string_literal: true require 'oauth2' -require_relative './oauth_custom_flow' +require_relative 'oauth_custom_flow' module MicrosoftKiotaAuthenticationOAuth - # Base class for token request contexs. - class OAuthContext - attr_accessor :scopes - attr_reader :oauth_provider - include MicrosoftKiotaAuthenticationOAuth::OAuthCustomFlow + # Base class for token request contexs. + class OAuthContext + attr_accessor :scopes + attr_reader :oauth_provider - def get_token - OAuthCustomFlow.get_token - end + include MicrosoftKiotaAuthenticationOAuth::OAuthCustomFlow - def initialize_scopes(scopes = []) - @scopes = OAuthCustomFlow.get_scopes - end + def get_token + OAuthCustomFlow.get_token + end - def initialize_oauth_provider - @oauth_provider = OAuthCustomFlow.get_oauth_provider - end + def initialize_scopes(_scopes = []) + @scopes = OAuthCustomFlow.get_scopes + end - private + def initialize_oauth_provider + @oauth_provider = OAuthCustomFlow.get_oauth_provider + end - attr_writer :oauth_provider + private - end -end \ No newline at end of file + attr_writer :oauth_provider + end +end diff --git a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/oauth_custom_flow.rb b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/oauth_custom_flow.rb index 2d499d6..38090c1 100644 --- a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/oauth_custom_flow.rb +++ b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/oauth_custom_flow.rb @@ -3,25 +3,25 @@ require 'oauth2' module MicrosoftKiotaAuthenticationOAuth - # Module that can be optionally implemented for supporting custom token grant flows. - # To use a cutsom token grant flow, implement the functions below and - # use MicrosoftKiotaAuthenticationOAuth::OAuthContext.new as your token_request_context - # object for the use by the MicrosoftKiotaAuthenticationOAuth::OAuthAccessTokenProvider - module OAuthCustomFlow - # Function that returns an oauth client using the oauth2 gem - def self.get_oauth_provider - raise NotImplementedError.new - end + # Module that can be optionally implemented for supporting custom token grant flows. + # To use a cutsom token grant flow, implement the functions below and + # use MicrosoftKiotaAuthenticationOAuth::OAuthContext.new as your token_request_context + # object for the use by the MicrosoftKiotaAuthenticationOAuth::OAuthAccessTokenProvider + module OAuthCustomFlow + # Function that returns an oauth client using the oauth2 gem + def self.get_oauth_provider + raise NotImplementedError + end - # Function that returns a space seperated string of scopes, beginning with - # the offline_access scope if relevant - def self.get_scopes - raise NotImplementedError.new - end + # Function that returns a space seperated string of scopes, beginning with + # the offline_access scope if relevant + def self.get_scopes + raise NotImplementedError + end - # Function that returns the access token - def self.get_token - raise NotImplementedError.new - end + # Function that returns the access token + def self.get_token + raise NotImplementedError end -end \ No newline at end of file + end +end diff --git a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/on_behalf_of_context.rb b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/on_behalf_of_context.rb index 631bec1..bc8650b 100644 --- a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/on_behalf_of_context.rb +++ b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/on_behalf_of_context.rb @@ -1,72 +1,71 @@ # frozen_string_literal: true require 'oauth2' -require_relative './oauth_context' +require_relative 'oauth_context' module MicrosoftKiotaAuthenticationOAuth - # Token request context class for the on behlaf of grant type. - class OnBehalfOfContext < MicrosoftKiotaAuthenticationOAuth::OAuthContext - attr_reader :grant_type, :additional_params, :tenant_id, :client_id, :client_secret, :oauth_provider - attr_writer :scopes + # Token request context class for the on behlaf of grant type. + class OnBehalfOfContext < MicrosoftKiotaAuthenticationOAuth::OAuthContext + attr_reader :grant_type, :additional_params, :tenant_id, :client_id, :client_secret, :oauth_provider + attr_writer :scopes - # This is the initializer for OnBehalfOfContext, the token request context when - # using the client credential grant flow. - # :params - # tenant_id: a string containing the tenant id - # client_id: a string containing the client id - # client_secret: a string containing the client secret - # assertion: string containing assertion (access token used in the request) - # additional_params: hash of symbols to string values, ie { response_mode: 'fragment', prompt: 'login' } - # default is empty hash - def initialize(tenant_id, client_id, client_secret, assertion, additional_params = {}) - raise StandardError, 'assertion cannot be empty' if assertion.nil? || assertion.empty? + # This is the initializer for OnBehalfOfContext, the token request context when + # using the client credential grant flow. + # :params + # tenant_id: a string containing the tenant id + # client_id: a string containing the client id + # client_secret: a string containing the client secret + # assertion: string containing assertion (access token used in the request) + # additional_params: hash of symbols to string values, ie { response_mode: 'fragment', prompt: 'login' } + # default is empty hash + def initialize(tenant_id, client_id, client_secret, assertion, additional_params = {}) + raise StandardError, 'assertion cannot be empty' if assertion.nil? || assertion.empty? - @tenant_id = tenant_id - @client_id = client_id - @client_secret = client_secret - @assertion = assertion - @additional_params = additional_params - @scopes = nil - @oauth_provider = nil - @grant_type = 'urn:ietf:params:Oauth:grant-type:jwt-bearer' - - if @tenant_id.nil? || @client_id.nil? || @client_secret.nil? || @client_secret.empty? || @tenant_id.empty? || @client_id.empty? - raise StandardError, 'tenant_id, client_secret, and client_id cannot be empty' - end - end + @tenant_id = tenant_id + @client_id = client_id + @client_secret = client_secret + @assertion = assertion + @additional_params = additional_params + @scopes = nil + @oauth_provider = nil + @grant_type = 'urn:ietf:params:Oauth:grant-type:jwt-bearer' - def get_token - params = { - grant_type: @grant_type, - assertion: @assertion, - scope: @scopes, - requested_token_use: 'on_behalf_of' - } - @oauth_provider.on_behalf_of.get_token(params) - end + if @tenant_id.nil? || @client_id.nil? || @client_secret.nil? || @client_secret.empty? || @tenant_id.empty? || @client_id.empty? + raise StandardError, 'tenant_id, client_secret, and client_id cannot be empty' + end + end + + def get_token + params = { + grant_type: @grant_type, + assertion: @assertion, + scope: @scopes, + requested_token_use: 'on_behalf_of' + } + @oauth_provider.on_behalf_of.get_token(params) + end - def initialize_oauth_provider - @oauth_provider = OAuth2::Client.new(@client_id, @client_secret, - site: 'https://login.microsoftonline.com', - authorize_url: "/#{@tenant_id}/oauth2/v2.0/authorize", - token_url: "/#{@tenant_id}/oauth2/v2.0/token") - end + def initialize_oauth_provider + @oauth_provider = OAuth2::Client.new(@client_id, @client_secret, + site: 'https://login.microsoftonline.com', + authorize_url: "/#{@tenant_id}/oauth2/v2.0/authorize", + token_url: "/#{@tenant_id}/oauth2/v2.0/token") + end - def initialize_scopes(scopes) - scope_str = '' - scopes.each { |scope| scope_str += scope + ' '} - - raise StandardError, 'scopes cannot be empty/nil.' if scope_str.empty? - - scope_str = 'offline_access ' + scope_str - - @scopes = scope_str - end + def initialize_scopes(scopes) + scope_str = '' + scopes.each { |scope| scope_str += "#{scope} " } - private + raise StandardError, 'scopes cannot be empty/nil.' if scope_str.empty? - attr_writer :grant_type, :additional_params, :tenant_id, :client_id, - :client_secret, :oauth_provider - + scope_str = "offline_access #{scope_str}" + + @scopes = scope_str end + + private + + attr_writer :grant_type, :additional_params, :tenant_id, :client_id, + :client_secret, :oauth_provider + end end diff --git a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/extensions/oauth2_ext.rb b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/extensions/oauth2_ext.rb index 8597d26..db788a5 100644 --- a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/extensions/oauth2_ext.rb +++ b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/extensions/oauth2_ext.rb @@ -5,7 +5,7 @@ # Extension of Oauth2 Library to Include On Behalf Of Grant Type module OAuth2 module Strategy - class OnBehalfOf < Base + class OnBehalfOf < Base def get_token(params, response_opts = {}) @client.get_token(params, response_opts) end @@ -19,4 +19,4 @@ def on_behalf_of @on_behalf_of ||= OAuth2::Strategy::OnBehalfOf.new(self) end end -end \ No newline at end of file +end diff --git a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/oauth_access_token_provider.rb b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/oauth_access_token_provider.rb index fe18bd9..fbb3b60 100644 --- a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/oauth_access_token_provider.rb +++ b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/oauth_access_token_provider.rb @@ -16,50 +16,49 @@ class OAuthAccessTokenProvider # :params # token_request_context: a instance of one of our token request context or a custom implementation # allowed_hosts: an array of strings, where each string is an allowed host, default is empty - # scopes: an array of strings, where each string is a scope, default is empty array + # scopes: an array of strings, where each string is a scope, default is empty array def initialize(token_request_context, allowed_hosts = [], scopes = []) raise StandardError, 'Parameter token_request_context cannot be nil.' if token_request_context.nil? @token_request_context = token_request_context unless @token_request_context.is_a?(MicrosoftKiotaAuthenticationOAuth::OAuthContext) - raise StandardError, 'Parameter token_request_context must be an instance of one of our grant flow context classes.' + raise StandardError, + 'Parameter token_request_context must be an instance of one of our grant flow context classes.' end @cached_token = nil - @host_validator = if allowed_hosts.nil? || allowed_hosts.size.zero? + @host_validator = if allowed_hosts.nil? || allowed_hosts.empty? MicrosoftKiotaAbstractions::AllowedHostsValidator.new([]) else MicrosoftKiotaAbstractions::AllowedHostsValidator.new(allowed_hosts) end @token_request_context.initialize_oauth_provider - if scopes.nil? - @scopes = [] - else - @scopes = scopes - end + @scopes = if scopes.nil? + [] + else + scopes + end end # This function obtains the authorization token. # :params - # uri: a string containing the uri + # uri: a string containing the uri # additional_params: hash of symbols to string values, ie { response_mode: 'fragment', prompt: 'login' } # default is empty hash - def get_authorization_token(uri, additional_properties = {}) + def get_authorization_token(uri, _additional_properties = {}) nil if !uri || !@host_validator.url_host_valid?(uri) parsed_url = URI(uri) raise StandardError, 'Only https is supported' if parsed_url.scheme != 'https' - if @scopes.empty? - @scopes << "#{parsed_url.scheme}://#{parsed_url.host}/.default" - end + @scopes << "#{parsed_url.scheme}://#{parsed_url.host}/.default" if @scopes.empty? @token_request_context.initialize_scopes(@scopes) Fiber.new do if @cached_token - token = OAuth2::AccessToken.from_hash(@token_request_context.oauth_provider, @cached_token) + token = OAuth2::AccessToken.from_hash(@token_request_context.oauth_provider, @cached_token) token.token unless token.nil? || token.expired? if token.expired? @@ -69,23 +68,20 @@ def get_authorization_token(uri, additional_properties = {}) end end - token = nil + nil token = @token_request_context.get_token - if !token.nil? + unless token.nil? @cached_token = token.to_hash token.token - else - nil end end end attr_reader :scopes, :host_validator - + protected attr_writer :host_validator, :token_credential, :scopes, :cached_token - end end diff --git a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/oauth_authentication_provider.rb b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/oauth_authentication_provider.rb index 00487de..e7cfb95 100644 --- a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/oauth_authentication_provider.rb +++ b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/oauth_authentication_provider.rb @@ -1,10 +1,13 @@ +# frozen_string_literal: true + require 'microsoft_kiota_abstractions' -require_relative './oauth_access_token_provider' +require_relative 'oauth_access_token_provider' module MicrosoftKiotaAuthenticationOAuth class OAuthAuthenticationProvider < MicrosoftKiotaAbstractions::BaseBearerTokenAuthenticationProvider def initialize(token_request_context, allowed_hosts, scopes) - super(MicrosoftKiotaAuthenticationOAuth::OAuthAccessTokenProvider.new(token_request_context, allowed_hosts, scopes)) + super(MicrosoftKiotaAuthenticationOAuth::OAuthAccessTokenProvider.new(token_request_context, allowed_hosts, + scopes)) end end end diff --git a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/version.rb b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/version.rb index 28c5900..f9c45a3 100644 --- a/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/version.rb +++ b/components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module MicrosoftKiotaAuthenticationOAuth - VERSION = "0.17.0" + VERSION = '0.17.0' # x-release-please-version end diff --git a/components/authentication/oauth/microsoft_kiota_authentication_oauth.gemspec b/components/authentication/oauth/microsoft_kiota_authentication_oauth.gemspec index f65cdfb..839ca6f 100644 --- a/components/authentication/oauth/microsoft_kiota_authentication_oauth.gemspec +++ b/components/authentication/oauth/microsoft_kiota_authentication_oauth.gemspec @@ -1,37 +1,34 @@ # frozen_string_literal: true -require_relative "lib/microsoft_kiota_authentication_oauth/version" +require_relative 'lib/microsoft_kiota_authentication_oauth/version' Gem::Specification.new do |spec| - spec.name = "microsoft_kiota_authentication_oauth" - spec.version = MicrosoftKiotaAuthenticationOAuth::VERSION - spec.authors = 'Microsoft Corporation' - spec.email = 'graphsdkpub+ruby@microsoft.com' + spec.name = 'microsoft_kiota_authentication_oauth' + spec.version = MicrosoftKiotaAuthenticationOAuth::VERSION + spec.authors = 'Microsoft Corporation' + spec.email = 'graphsdkpub+ruby@microsoft.com' spec.description = 'Kiota Authentication implementation with oauth2' spec.summary = 'Microsoft Kiota Authentication OAuth - Kiota Ruby Authentication OAuth library' spec.homepage = 'https://microsoft.github.io/kiota/' spec.license = 'MIT' spec.metadata = { 'bug_tracker_uri' => 'https://github.com/microsoft/kiota-ruby/issues', - 'changelog_uri' => 'https://github.com/microsoft/kiota-ruby/blob/main/components/authentication/oauth/CHANGELOG.md', - 'homepage_uri' => spec.homepage, + 'changelog_uri' => 'https://github.com/microsoft/kiota-ruby/blob/main/CHANGELOG.md', + 'homepage_uri' => spec.homepage, 'source_code_uri' => 'https://github.com/microsoft/kiota-ruby/tree/main/components/authentication/oauth', - 'github_repo' => 'ssh://github.com/microsoft/kiota-ruby' + 'github_repo' => 'ssh://github.com/microsoft/kiota-ruby', + 'rubygems_mfa_required' => 'true' } - spec.required_ruby_version = ">= 3.3.0" + spec.required_ruby_version = '>= 3.3.0' - # Specify which files should be added to the gem when it is released. - # The `git ls-files -z` loads the files in the RubyGem that have been added into git. spec.files = Dir.chdir(File.expand_path(__dir__)) do `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) } end - - spec.bindir = 'bin' + 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.17', '< 0.18' - spec.add_runtime_dependency 'oauth2', '~> 2.0' + spec.add_dependency 'microsoft_kiota_abstractions', '>= 0.17', '< 0.18' + spec.add_dependency 'oauth2', '~> 2.0' spec.add_development_dependency 'rake', '~> 13.0' spec.add_development_dependency 'rspec', '~> 3.0' spec.add_development_dependency 'rubocop' diff --git a/components/authentication/oauth/spec/microsoft_kiota_authentication_oauth_spec.rb b/components/authentication/oauth/spec/microsoft_kiota_authentication_oauth_spec.rb index 2c4693f..82032d5 100644 --- a/components/authentication/oauth/spec/microsoft_kiota_authentication_oauth_spec.rb +++ b/components/authentication/oauth/spec/microsoft_kiota_authentication_oauth_spec.rb @@ -5,30 +5,77 @@ RSpec.describe MicrosoftKiotaAuthenticationOAuth do it '(client credential context) throws when tenant_id/client_secret is nil/empty' do - expect { MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new(nil, nil, nil, {}) }.to raise_error(StandardError) - expect { MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new('tenant_id', 'client_id', 'client_secret', {}) }.not_to raise_error - expect { MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new('', 'client_id', 'client_secret', {}) }.to raise_error(StandardError) - expect { MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new('tenant_id', '', 'client_secret', {}) }.to raise_error(StandardError) - expect { MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new('tenant_id', 'client_id', '', {}) }.to raise_error(StandardError) + expect do + MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new(nil, nil, nil, {}) + end.to raise_error(StandardError) + expect do + MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new('tenant_id', 'client_id', 'client_secret', + {}) + end.not_to raise_error + expect do + MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new('', 'client_id', 'client_secret', + {}) + end.to raise_error(StandardError) + expect do + MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new('tenant_id', '', 'client_secret', + {}) + end.to raise_error(StandardError) + expect do + MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new('tenant_id', 'client_id', '', + {}) + end.to raise_error(StandardError) end it '(auth code context) throws when tenant_id/client_secret is nil/empty' do - expect { MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new(nil, nil, nil, nil) }.to raise_error(StandardError) - expect { MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('tenant_id', 'client_id', 'client_secret', 'redirect_uri') }.not_to raise_error - expect { MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('', 'client_id', 'client_secret', 'redirect_uri', 'code') }.to raise_error(StandardError) - expect { MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('tenant_id', '', 'client_secret', '') }.to raise_error(StandardError) - expect { MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('tenant_id', 'client_id', '', 'redirect_uri') }.to raise_error(StandardError) - expect { MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('tenant_id', '', 'client_secret', 'redirect_uri') }.to raise_error(StandardError) + expect do + MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new(nil, nil, nil, nil) + end.to raise_error(StandardError) + expect do + MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('tenant_id', 'client_id', 'client_secret', + 'redirect_uri') + end.not_to raise_error + expect do + MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('', 'client_id', 'client_secret', 'redirect_uri', + 'code') + end.to raise_error(StandardError) + expect do + MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('tenant_id', '', 'client_secret', + '') + end.to raise_error(StandardError) + expect do + MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('tenant_id', 'client_id', '', + 'redirect_uri') + end.to raise_error(StandardError) + expect do + MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('tenant_id', '', 'client_secret', + 'redirect_uri') + end.to raise_error(StandardError) end - it '(on behalf of) throws when tenant_id/client_secret is nil/empty' do - expect { MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new(nil, nil, nil, nil) }.to raise_error(StandardError) - expect { MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('tenant_id', 'client_id', 'client_secret', 'assertion') }.not_to raise_error - expect { MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('', 'client_id', 'client_secret', 'assertion') }.to raise_error(StandardError) - expect { MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('tenant_id', '', 'client_secret', 'assertion') }.to raise_error(StandardError) - expect { MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('tenant_id', 'client_id', '', 'assertion') }.to raise_error(StandardError) - expect { MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('tenant_id', 'client_id', 'client_secret', '') }.to raise_error(StandardError) + expect do + MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new(nil, nil, nil, nil) + end.to raise_error(StandardError) + expect do + MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('tenant_id', 'client_id', 'client_secret', + 'assertion') + end.not_to raise_error + expect do + MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('', 'client_id', 'client_secret', + 'assertion') + end.to raise_error(StandardError) + expect do + MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('tenant_id', '', 'client_secret', + 'assertion') + end.to raise_error(StandardError) + expect do + MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('tenant_id', 'client_id', '', + 'assertion') + end.to raise_error(StandardError) + expect do + MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('tenant_id', 'client_id', 'client_secret', + '') + end.to raise_error(StandardError) end it 'throws when OAuthContext is used, but a custom flow is not implemented' do @@ -36,8 +83,11 @@ end it 'recognizes contexts as an OAuthContext' do - expect(MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new('tenant_id', 'client_id', 'client_secret', {}).is_a? MicrosoftKiotaAuthenticationOAuth::OAuthContext).to eq(true) - expect(MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('tenant_id', 'client_id', 'client_secret', 'assertion').is_a? MicrosoftKiotaAuthenticationOAuth::OAuthContext).to eq(true) - expect(MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('tenant_id', 'client_id', 'client_secret', 'redirect_uri').is_a? MicrosoftKiotaAuthenticationOAuth::OAuthContext).to eq(true) + expect(MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new('tenant_id', 'client_id', 'client_secret', + {}).is_a?(MicrosoftKiotaAuthenticationOAuth::OAuthContext)).to eq(true) + expect(MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('tenant_id', 'client_id', 'client_secret', + 'assertion').is_a?(MicrosoftKiotaAuthenticationOAuth::OAuthContext)).to eq(true) + expect(MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('tenant_id', 'client_id', 'client_secret', + 'redirect_uri').is_a?(MicrosoftKiotaAuthenticationOAuth::OAuthContext)).to eq(true) end end diff --git a/components/authentication/oauth/spec/spec_helper.rb b/components/authentication/oauth/spec/spec_helper.rb index fac733c..d105438 100644 --- a/components/authentication/oauth/spec/spec_helper.rb +++ b/components/authentication/oauth/spec/spec_helper.rb @@ -12,9 +12,8 @@ RSpec.configure do |config| # Enable flags like --only-failures and --next-failure - config.example_status_persistence_file_path = ".rspec_status" + config.example_status_persistence_file_path = '.rspec_status' # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_patching! - end diff --git a/components/http/CHANGELOG.md b/components/http/CHANGELOG.md deleted file mode 100644 index a7e49cb..0000000 --- a/components/http/CHANGELOG.md +++ /dev/null @@ -1,69 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [0.16.0](https://github.com/microsoft/kiota-http-ruby/compare/v0.15.0...v0.16.0) (2026-04-23) - - -### Features - -* upgrade ruby CI matrix to 3.3, 3.4 and 4.0 ([7bf4976](https://github.com/microsoft/kiota-http-ruby/commit/7bf497603ae5106b57e7b1baf5b51b902049d17c)) -* upgrade ruby CI matrix to 3.3, 3.4 and 4.0 ([278f84d](https://github.com/microsoft/kiota-http-ruby/commit/278f84dd0fd8f2d9d13927089b8c09fcc51b5402)) - - -### Bug Fixes - -* update minimum required ruby version to 3.3.0 ([fa6e13f](https://github.com/microsoft/kiota-http-ruby/commit/fa6e13fbd422c508a690a29e678ebc1ca3d7f33a)) -* update minimum required ruby version to 3.3.0 ([f867d27](https://github.com/microsoft/kiota-http-ruby/commit/f867d270aa008881650af6470428cc19b29d2abd)) - -## [Unreleased] - -### Added - -### Changed - -## [0.15.0] - 2024-02-16 - -### Changed - -- Ensure get_parse_node does not fail when response body is empty. [#27](https://github.com/microsoft/kiota-http-ruby/pull/28) - -## [0.14.0] - 2024-02-14 - -### Changed - -- Make sure the base_url is set when calling authenticate_request. [#27](https://github.com/microsoft/kiota-http-ruby/pull/27) - -## [0.13.0] - 2024-02-05 - -### Changed - -- Added support for error mapping deduplication to reduce generated code. [#20](https://github.com/microsoft/kiota-http-ruby/issues/20) - -## [0.12.0] - 2023-03-28 - -### Changed - -- Updated kiota abstractions reference -- Bumped minimum required ruby version to 3.0. - -## [0.11.0] - 2023-01-10 - -### Added - -- Added a method to convert abstract requests to native requests in the request adapter interface. - -## [0.10.0] - 2023-01-06 - -### Added - -- Added a user agent handler to add the product to the request header. - -## [0.9.0] - 2022-12-30 - -### Added - -- Initial public release of the package. diff --git a/components/http/Gemfile b/components/http/Gemfile index 961a5eb..efe05f1 100644 --- a/components/http/Gemfile +++ b/components/http/Gemfile @@ -1,7 +1,7 @@ # frozen_string_literal: true -source "https://rubygems.org" +source 'https://rubygems.org' -gem "microsoft_kiota_abstractions", path: "../abstractions" +gem 'microsoft_kiota_abstractions', path: '../abstractions' gemspec diff --git a/components/http/Rakefile b/components/http/Rakefile index 0a44f59..82bb534 100644 --- a/components/http/Rakefile +++ b/components/http/Rakefile @@ -1,7 +1,5 @@ # frozen_string_literal: true -# frozen_string_literal: true - require 'bundler/gem_tasks' require 'rspec/core/rake_task' diff --git a/components/http/lib/microsoft_kiota_faraday/faraday_request_adapter.rb b/components/http/lib/microsoft_kiota_faraday/faraday_request_adapter.rb index 85cee2e..1f426b2 100644 --- a/components/http/lib/microsoft_kiota_faraday/faraday_request_adapter.rb +++ b/components/http/lib/microsoft_kiota_faraday/faraday_request_adapter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'microsoft_kiota_abstractions' require 'faraday' require 'net/http' @@ -8,13 +10,13 @@ module MicrosoftKiotaFaraday class FaradayRequestAdapter include MicrosoftKiotaAbstractions::RequestAdapter - attr_accessor :authentication_provider, :content_type_header_key, :parse_node_factory, :serialization_writer_factory, :client + attr_accessor :authentication_provider, :content_type_header_key, :parse_node_factory, + :serialization_writer_factory, :client - def initialize(authentication_provider, parse_node_factory=MicrosoftKiotaAbstractions::ParseNodeFactoryRegistry.default_instance, serialization_writer_factory=MicrosoftKiotaAbstractions::SerializationWriterFactoryRegistry.default_instance, client = KiotaClientFactory::get_default_http_client) + def initialize(authentication_provider, + parse_node_factory = MicrosoftKiotaAbstractions::ParseNodeFactoryRegistry.default_instance, serialization_writer_factory = MicrosoftKiotaAbstractions::SerializationWriterFactoryRegistry.default_instance, client = KiotaClientFactory.get_default_http_client) + raise StandardError, 'authentication provider cannot be null' unless authentication_provider - if !authentication_provider - raise StandardError , 'authentication provider cannot be null' - end @authentication_provider = authentication_provider @content_type_header_key = 'Content-Type' @parse_node_factory = parse_node_factory @@ -26,9 +28,7 @@ def initialize(authentication_provider, parse_node_factory=MicrosoftKiotaAbstrac @serialization_writer_factory = MicrosoftKiotaAbstractions::SerializationWriterFactoryRegistry.default_instance end @client = client - if @client.nil? - @client = KiotaClientFactory::get_default_http_client - end + @client = KiotaClientFactory.get_default_http_client if @client.nil? @base_url = '' end @@ -36,11 +36,11 @@ def set_base_url(base_url) @base_url = base_url end - def get_base_url() + def get_base_url @base_url end - def get_serialization_writer_factory() + def get_serialization_writer_factory @serialization_writer_factory end @@ -51,89 +51,101 @@ def send_async(request_info, factory, errors_mapping) Fiber.new do set_base_url_for_request_information(request_info) @authentication_provider.authenticate_request(request_info).resume - request = self.get_request_from_request_info(request_info) + request = get_request_from_request_info(request_info) response = @client.run_request(request.http_method, request.path, request.body, request.headers) - 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) + response_handler = get_response_handler(request_info) + response_handler&.call(response)&.resume + throw_if_failed_reponse(response, errors_mapping) + root_node = 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? + unless request_info.nil? + option = request_info.get_request_option(MicrosoftKiotaFaraday::Middleware::ResponseHandlerOption::RESPONSE_HANDLER_KEY) + end + 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); + + response_content_type = get_response_content_type(response) raise StandardError, 'no response content type found for deserialization' unless response_content_type return if response.body.nil? || response.body.empty? - return @parse_node_factory.get_parse_node(response_content_type, response.body) + + @parse_node_factory.get_parse_node(response_content_type, response.body) end def throw_if_failed_reponse(response, errors_mapping) raise StandardError, 'response cannot be null' unless response - status_code = response.status; - if status_code < 400 then - return - end + status_code = response.status + return if status_code < 400 + error_factory = errors_mapping[status_code] unless errors_mapping.nil? error_factory = errors_mapping['4XX'] unless !error_factory.nil? || errors_mapping.nil? || status_code > 500 - error_factory = errors_mapping['5XX'] unless !error_factory.nil? || errors_mapping.nil? || status_code < 500 || status_code > 600 - error_factory = errors_mapping['XXX'] unless !error_factory.nil? || errors_mapping.nil? || status_code < 400 || status_code > 600 - raise MicrosoftKiotaAbstractions::ApiError, 'The server returned an unexpected status code and no error factory is registered for this code:' + status_code.to_s if error_factory.nil? - root_node = self.get_root_parse_node(response) + unless !error_factory.nil? || errors_mapping.nil? || status_code < 500 || status_code > 600 + error_factory = errors_mapping['5XX'] + end + unless !error_factory.nil? || errors_mapping.nil? || status_code < 400 || status_code > 600 + error_factory = errors_mapping['XXX'] + end + if error_factory.nil? + raise MicrosoftKiotaAbstractions::ApiError, + "The server returned an unexpected status code and no error factory is registered for this code:#{status_code}" + end + + root_node = get_root_parse_node(response) error = root_node.get_object_value(error_factory) unless root_node.nil? raise error unless error.nil? - raise MicrosoftKiotaAbstractions::ApiError, 'The server returned an unexpected status code:' + status_code.to_s + + raise MicrosoftKiotaAbstractions::ApiError, "The server returned an unexpected status code:#{status_code}" end def get_request_from_request_info(request_info) set_base_url_for_request_information(request_info) case request_info.http_method - when :GET - request = @client.build_request(:get) - when :POST - request = @client.build_request(:post) - when :PATCH - request = @client.build_request(:patch) - when :DELETE - request = @client.build_request(:delete) - when :OPTIONS - request = @client.build_request(:options) - when :CONNECT - request = @client.build_request(:connect) - when :PUT - request = @client.build_request(:put) - when :TRACE - request = @client.build_request(:trace) - when :HEAD - request = @client.build_request(:head) - else - raise StandardError, 'unsupported http method' + when :GET + request = @client.build_request(:get) + when :POST + request = @client.build_request(:post) + when :PATCH + request = @client.build_request(:patch) + when :DELETE + request = @client.build_request(:delete) + when :OPTIONS + request = @client.build_request(:options) + when :CONNECT + request = @client.build_request(:connect) + when :PUT + request = @client.build_request(:put) + when :TRACE + request = @client.build_request(:trace) + when :HEAD + request = @client.build_request(:head) + else + raise StandardError, 'unsupported http method' end request.path = request_info.uri - unless request_info.headers.nil? then + unless request_info.headers.nil? request.headers = Faraday::Utils::Headers.new - request_info.headers.get_all.select{|k,v| - if v.kind_of? Array then - request.headers[k] = v.join(',') - elsif v.kind_of? String then - request.headers[k] = v - else - request.headers[k] = v.to_s - end - } + request_info.headers.get_all.select do |k, v| + request.headers[k] = if v.is_a? Array + v.join(',') + elsif v.is_a? String + v + else + v.to_s + end + end end request.body = request_info.content unless request_info.content.nil? || request_info.content.empty? - # TODO the json serialization writer returns a string at the moment, change to body_stream when this is fixed + # TODO: the json serialization writer returns a string at the moment, change to body_stream when this is fixed request_options = request_info.get_request_options - if !request_options.nil? && !request_options.empty? then + if !request_options.nil? && !request_options.empty? request.options = Faraday::RequestOptions.new if request.options.nil? request_options.each do |value| request.options.context[value.get_key] = value @@ -143,19 +155,18 @@ def get_request_from_request_info(request_info) end def get_response_content_type(response) - begin - response.headers['content-type'].split(';')[0].downcase() - rescue - return nil - end + response.headers['content-type'].split(';')[0].downcase + rescue StandardError + nil end def convert_to_native_request_async(request_info) raise StandardError, 'request_info cannot be null' unless request_info - return Fiber.new do + + Fiber.new do set_base_url_for_request_information(request_info) @authentication_provider.authenticate_request(request_info).resume - return self.get_request_from_request_info(request_info) + return get_request_from_request_info(request_info) end end diff --git a/components/http/lib/microsoft_kiota_faraday/kiota_client_factory.rb b/components/http/lib/microsoft_kiota_faraday/kiota_client_factory.rb index 9024ff9..f19e091 100644 --- a/components/http/lib/microsoft_kiota_faraday/kiota_client_factory.rb +++ b/components/http/lib/microsoft_kiota_faraday/kiota_client_factory.rb @@ -1,37 +1,38 @@ +# frozen_string_literal: true + require 'net/https' require 'faraday' require_relative 'middleware/parameters_name_decoding_handler' require_relative 'middleware/user_agent_handler' module MicrosoftKiotaFaraday - class KiotaClientFactory - def self.get_default_middleware() - return [ - MicrosoftKiotaFaraday::Middleware::ParametersNameDecodingHandler, - MicrosoftKiotaFaraday::Middleware::UserAgentHandler - ] - end + class KiotaClientFactory + def self.get_default_middleware + [ + MicrosoftKiotaFaraday::Middleware::ParametersNameDecodingHandler, + MicrosoftKiotaFaraday::Middleware::UserAgentHandler + ] + end - def self.get_default_http_client(middleware=nil, default_middleware_options=Array.new) - if middleware.nil? #empty is fine in case the user doesn't want to use any middleware - middleware = self.get_default_middleware() - end - connection_options = Hash.new - connection_options[:request] = Hash.new - connection_options[:request][:context] = Hash.new - unless default_middleware_options.nil? || default_middleware_options.empty? then - default_middleware_options.each do |value| - connection_options[:request][:context][value.get_key] = value - end - end - conn = Faraday::Connection.new(nil, connection_options) do |builder| - builder.adapter Faraday.default_adapter - builder.ssl.verify = true - builder.ssl.verify_mode = OpenSSL::SSL::VERIFY_PEER - middleware.each do |handler| - builder.use handler - end - end - conn + def self.get_default_http_client(middleware = nil, default_middleware_options = []) + if middleware.nil? # empty is fine in case the user doesn't want to use any middleware + middleware = get_default_middleware + end + connection_options = {} + connection_options[:request] = {} + connection_options[:request][:context] = {} + unless default_middleware_options.nil? || default_middleware_options.empty? + default_middleware_options.each do |value| + connection_options[:request][:context][value.get_key] = value + end + end + Faraday::Connection.new(nil, connection_options) do |builder| + builder.adapter Faraday.default_adapter + builder.ssl.verify = true + builder.ssl.verify_mode = OpenSSL::SSL::VERIFY_PEER + middleware.each do |handler| + builder.use handler end + end end -end \ No newline at end of file + end +end diff --git a/components/http/lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_handler.rb b/components/http/lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_handler.rb index a73e1ac..0933189 100644 --- a/components/http/lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_handler.rb +++ b/components/http/lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_handler.rb @@ -1,29 +1,31 @@ +# frozen_string_literal: true + require 'faraday' require_relative 'parameters_name_decoding_option' module MicrosoftKiotaFaraday - module Middleware - class ParametersNameDecodingHandler < Faraday::Middleware - @@default_option = ParametersNameDecodingOption.new - def call(request_env) - request_option = request_env[:request][:context][@@default_option.get_key] unless request_env[:request].nil? || request_env[:request][:context].nil? - request_option = @@default_option if request_option.nil? - unless request_env[:url].nil? || !request_option.enabled || request_option.characters_to_decode.nil? || request_option.characters_to_decode.empty? then - request_url = request_env[:url].to_s - request_option.characters_to_decode.each do |character| - request_url = request_url.gsub(get_regex_for_character(character), character) - end - request_env[:url] = URI.parse(request_url) - end - @app.call(request_env) unless @app.nil? - end - - def get_regex_for_character(character) - @regex_cache ||= Hash.new - if @regex_cache[character].nil? then - @regex_cache[character] = Regexp.new("%#{character.ord.to_s(16)}", true) - end - return @regex_cache[character] - end + module Middleware + class ParametersNameDecodingHandler < Faraday::Middleware + @@default_option = ParametersNameDecodingOption.new + def call(request_env) + unless request_env[:request].nil? || request_env[:request][:context].nil? + request_option = request_env[:request][:context][@@default_option.get_key] end + request_option = @@default_option if request_option.nil? + unless request_env[:url].nil? || !request_option.enabled || request_option.characters_to_decode.nil? || request_option.characters_to_decode.empty? + request_url = request_env[:url].to_s + request_option.characters_to_decode.each do |character| + request_url = request_url.gsub(get_regex_for_character(character), character) + end + request_env[:url] = URI.parse(request_url) + end + @app&.call(request_env) + end + + def get_regex_for_character(character) + @regex_cache ||= {} + @regex_cache[character] = Regexp.new("%#{character.ord.to_s(16)}", true) if @regex_cache[character].nil? + @regex_cache[character] + end end -end \ No newline at end of file + end +end diff --git a/components/http/lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_option.rb b/components/http/lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_option.rb index 4c971e4..c9ed3e5 100644 --- a/components/http/lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_option.rb +++ b/components/http/lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_option.rb @@ -1,19 +1,21 @@ # frozen_string_literal: true + require 'microsoft_kiota_abstractions' module MicrosoftKiotaFaraday - module Middleware - class ParametersNameDecodingOption - include MicrosoftKiotaAbstractions::RequestOption - attr_accessor :enabled, :characters_to_decode + module Middleware + class ParametersNameDecodingOption + include MicrosoftKiotaAbstractions::RequestOption + + attr_accessor :enabled, :characters_to_decode - def initialize(enabled = true, characters_to_decode = ['$', '.', '-', '~']) - @enabled = enabled - @characters_to_decode = characters_to_decode - end + def initialize(enabled = true, characters_to_decode = ['$', '.', '-', '~']) + @enabled = enabled + @characters_to_decode = characters_to_decode + end - def get_key() - "parametersNameDecoding" - end - end + def get_key + 'parametersNameDecoding' + end end -end \ No newline at end of file + end +end diff --git a/components/http/lib/microsoft_kiota_faraday/middleware/response_handler_option.rb b/components/http/lib/microsoft_kiota_faraday/middleware/response_handler_option.rb index d183d7e..555227b 100644 --- a/components/http/lib/microsoft_kiota_faraday/middleware/response_handler_option.rb +++ b/components/http/lib/microsoft_kiota_faraday/middleware/response_handler_option.rb @@ -1,14 +1,16 @@ # 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 + 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 diff --git a/components/http/lib/microsoft_kiota_faraday/middleware/user_agent_handler.rb b/components/http/lib/microsoft_kiota_faraday/middleware/user_agent_handler.rb index f105c46..964bf4e 100644 --- a/components/http/lib/microsoft_kiota_faraday/middleware/user_agent_handler.rb +++ b/components/http/lib/microsoft_kiota_faraday/middleware/user_agent_handler.rb @@ -1,24 +1,28 @@ +# frozen_string_literal: true + require 'faraday' require_relative 'user_agent_option' module MicrosoftKiotaFaraday - module Middleware - class UserAgentHandler < Faraday::Middleware - @@default_option = UserAgentOption.new - @@user_agent_key = "User-Agent" - def call(request_env) - request_option = request_env[:request][:context][@@default_option.get_key] unless request_env[:request].nil? || request_env[:request][:context].nil? - request_option = @@default_option if request_option.nil? - unless request_env[:request_headers].nil? || !request_option.enabled || request_option.product_name.nil? || request_option.product_name.empty? || request_option.product_version.nil? || request_option.product_version.empty? then - existing_value = request_env[:request_headers][@@user_agent_key] - additional_value = "#{request_option.product_name}/#{request_option.product_version}" - if !existing_value || existing_value.empty? then - request_env[:request_headers][@@user_agent_key] = additional_value - elsif !existing_value.include? additional_value then - request_env[:request_headers][@@user_agent_key] = "#{existing_value} #{additional_value}" - end - end - @app.call(request_env) unless @app.nil? - end - end - end -end \ No newline at end of file + module Middleware + class UserAgentHandler < Faraday::Middleware + @@default_option = UserAgentOption.new + @@user_agent_key = 'User-Agent' + def call(request_env) + unless request_env[:request].nil? || request_env[:request][:context].nil? + request_option = request_env[:request][:context][@@default_option.get_key] + end + request_option = @@default_option if request_option.nil? + unless request_env[:request_headers].nil? || !request_option.enabled || request_option.product_name.nil? || request_option.product_name.empty? || request_option.product_version.nil? || request_option.product_version.empty? + existing_value = request_env[:request_headers][@@user_agent_key] + additional_value = "#{request_option.product_name}/#{request_option.product_version}" + if !existing_value || existing_value.empty? + request_env[:request_headers][@@user_agent_key] = additional_value + elsif !existing_value.include? additional_value + request_env[:request_headers][@@user_agent_key] = "#{existing_value} #{additional_value}" + end + end + @app&.call(request_env) + end + end + end +end diff --git a/components/http/lib/microsoft_kiota_faraday/middleware/user_agent_option.rb b/components/http/lib/microsoft_kiota_faraday/middleware/user_agent_option.rb index fb903cb..d93beb1 100644 --- a/components/http/lib/microsoft_kiota_faraday/middleware/user_agent_option.rb +++ b/components/http/lib/microsoft_kiota_faraday/middleware/user_agent_option.rb @@ -1,20 +1,23 @@ # frozen_string_literal: true + require 'microsoft_kiota_abstractions' -require_relative '../version.rb' +require_relative '../version' module MicrosoftKiotaFaraday - module Middleware - class UserAgentOption - include MicrosoftKiotaAbstractions::RequestOption - attr_accessor :enabled, :product_name, :product_version - def initialize() - @enabled = true - @product_name = "kiota-ruby" - @product_version = MicrosoftKiotaFaraday::VERSION - end + module Middleware + class UserAgentOption + include MicrosoftKiotaAbstractions::RequestOption + + attr_accessor :enabled, :product_name, :product_version + + def initialize + @enabled = true + @product_name = 'kiota-ruby' + @product_version = MicrosoftKiotaFaraday::VERSION + end - def get_key() - "userAgent" - end - end - end + def get_key + 'userAgent' + end + end + end end diff --git a/components/http/lib/microsoft_kiota_faraday/version.rb b/components/http/lib/microsoft_kiota_faraday/version.rb index 475bf63..51cc640 100644 --- a/components/http/lib/microsoft_kiota_faraday/version.rb +++ b/components/http/lib/microsoft_kiota_faraday/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module MicrosoftKiotaFaraday - VERSION = '0.17.0' + VERSION = '0.17.0' # x-release-please-version end diff --git a/components/http/microsoft_kiota_faraday.gemspec b/components/http/microsoft_kiota_faraday.gemspec index 9610fcb..e2c7de8 100644 --- a/components/http/microsoft_kiota_faraday.gemspec +++ b/components/http/microsoft_kiota_faraday.gemspec @@ -1,35 +1,34 @@ # frozen_string_literal: true -require_relative "lib/microsoft_kiota_faraday/version" +require_relative 'lib/microsoft_kiota_faraday/version' Gem::Specification.new do |spec| - spec.name = "microsoft_kiota_faraday" + spec.name = 'microsoft_kiota_faraday' spec.version = MicrosoftKiotaFaraday::VERSION spec.authors = 'Microsoft Corporation' spec.email = 'graphsdkpub+ruby@microsoft.com' spec.description = 'Kiota HttpCore implementation with Faraday' - spec.summary = "Microsoft Kiota Faraday - Kiota Ruby http request adapter for running requests" + spec.summary = 'Microsoft Kiota Faraday - Kiota Ruby http request adapter for running requests' spec.homepage = 'https://microsoft.github.io/kiota/' spec.license = 'MIT' spec.metadata = { 'bug_tracker_uri' => 'https://github.com/microsoft/kiota-ruby/issues', - 'changelog_uri' => 'https://github.com/microsoft/kiota-ruby/blob/main/components/http/CHANGELOG.md', - 'homepage_uri' => spec.homepage, + 'changelog_uri' => 'https://github.com/microsoft/kiota-ruby/blob/main/CHANGELOG.md', + 'homepage_uri' => spec.homepage, 'source_code_uri' => 'https://github.com/microsoft/kiota-ruby/tree/main/components/http', - 'github_repo' => 'ssh://github.com/microsoft/kiota-ruby' + 'github_repo' => 'ssh://github.com/microsoft/kiota-ruby', + 'rubygems_mfa_required' => 'true' } - spec.required_ruby_version = ">= 3.3.0" + spec.required_ruby_version = '>= 3.3.0' - # Specify which files should be added to the gem when it is released. - # The `git ls-files -z` loads the files in the RubyGem that have been added into git. spec.files = Dir.chdir(File.expand_path(__dir__)) do `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) } end 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.17', '< 0.18' - spec.add_runtime_dependency 'faraday', '~> 2.7', '>= 2.7.2' + spec.add_dependency 'faraday', '~> 2.7', '>= 2.7.2' + spec.add_dependency 'microsoft_kiota_abstractions', '>= 0.17', '< 0.18' spec.add_development_dependency 'rake', '~> 13.0' spec.add_development_dependency 'rspec', '~> 3.0' spec.add_development_dependency 'rubocop' diff --git a/components/http/spec/authentication_provider.rb b/components/http/spec/authentication_provider.rb index 0a65a84..b4af8a1 100644 --- a/components/http/spec/authentication_provider.rb +++ b/components/http/spec/authentication_provider.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + require 'microsoft_kiota_abstractions' class AuthenticationProvider - include MicrosoftKiotaAbstractions::AuthenticationProvider -end \ No newline at end of file + include MicrosoftKiotaAbstractions::AuthenticationProvider +end diff --git a/components/http/spec/microsoft_kiota_faraday.rb b/components/http/spec/microsoft_kiota_faraday.rb index c3479b2..eca567c 100644 --- a/components/http/spec/microsoft_kiota_faraday.rb +++ b/components/http/spec/microsoft_kiota_faraday.rb @@ -1,17 +1,18 @@ # frozen_string_literal: true + require_relative 'authentication_provider' RSpec.describe MicrosoftKiotaFaraday do - it "has a version number" do + it 'has a version number' do expect(MicrosoftKiotaFaraday::VERSION).not_to be nil end - it "does something useful" do + it 'does something useful' do expect(true).to eq(true) end - it "can instantiate a request adapter" do - auth_provider = AuthenticationProvider.new() + it 'can instantiate a request adapter' do + auth_provider = AuthenticationProvider.new adapter = MicrosoftKiotaFaraday::FaradayRequestAdapter.new(auth_provider) expect(adapter).to_not be nil end diff --git a/components/http/spec/microsoft_kiota_faraday/faraday_request_adapter_spec.rb b/components/http/spec/microsoft_kiota_faraday/faraday_request_adapter_spec.rb index 289fefb..12a8863 100644 --- a/components/http/spec/microsoft_kiota_faraday/faraday_request_adapter_spec.rb +++ b/components/http/spec/microsoft_kiota_faraday/faraday_request_adapter_spec.rb @@ -1,54 +1,58 @@ # frozen_string_literal: true + RSpec.describe MicrosoftKiotaFaraday::FaradayRequestAdapter do subject(:adapter) { described_class.new(authentication_provider) } - let(:authentication_provider) { double("authentication_provider") } + let(:authentication_provider) { double('authentication_provider') } let(:headers) { { 'content-type' => 'application/json' } } - let(:body) { { key: "value" }.to_json } + let(:body) { { key: 'value' }.to_json } - describe "#get_root_parse_node" do - context "when response is null" do - it "raises an error" do + describe '#get_root_parse_node' do + context 'when response is null' do + it 'raises an error' do expect { adapter.get_root_parse_node(nil) }.to raise_error(StandardError, 'response cannot be null') end end - context "when response content type is not found" do + context 'when response content type is not found' do let(:response) { instance_double(Faraday::Response, body:, headers: {}) } - it "raises an error" do - expect { adapter.get_root_parse_node(response) }.to raise_error(StandardError, 'no response content type found for deserialization') + it 'raises an error' do + expect do + adapter.get_root_parse_node(response) + end.to raise_error(StandardError, + 'no response content type found for deserialization') end end - context "when response body is nil" do + context 'when response body is nil' do let(:response) { instance_double(Faraday::Response, body: nil, headers:) } - it "returns nil" do + it 'returns nil' do expect(adapter.get_root_parse_node(response)).to be_nil end end - context "when response body is empty" do - let(:response) { instance_double(Faraday::Response, body: "", headers:) } + context 'when response body is empty' do + let(:response) { instance_double(Faraday::Response, body: '', headers:) } - it "returns nil" do + it 'returns nil' do expect(adapter.get_root_parse_node(response)).to be_nil end end - context "when response body is not nil" do + context 'when response body is not nil' do subject(:adapter) { described_class.new(authentication_provider, parse_node_factory) } let(:response) { instance_double(Faraday::Response, body:, headers:) } - let(:parse_node_factory) { double("parse_node_factory") } - let(:parse_node) { double("parse_node") } + let(:parse_node_factory) { double('parse_node_factory') } + let(:parse_node) { double('parse_node') } before do - allow(parse_node_factory).to receive(:get_parse_node).with("application/json", body).and_return(parse_node) + allow(parse_node_factory).to receive(:get_parse_node).with('application/json', body).and_return(parse_node) end - it "returns the parse node" do + it 'returns the parse node' do expect(adapter.get_root_parse_node(response)).to eq(parse_node) end end diff --git a/components/http/spec/parameters_name_decoding_handler_spec.rb b/components/http/spec/parameters_name_decoding_handler_spec.rb index b61d492..3869e2d 100644 --- a/components/http/spec/parameters_name_decoding_handler_spec.rb +++ b/components/http/spec/parameters_name_decoding_handler_spec.rb @@ -1,46 +1,49 @@ +# frozen_string_literal: true + require 'faraday' # frozen_string_literal: true RSpec.describe MicrosoftKiotaFaraday do - it "decodes encoded query parameters" do - values = Hash.new - values["?%24select=diplayName&api%2Dversion=2"] = "?$select=diplayName&api-version=2" - values["?%24select=diplayName&api%7Eversion=2"] = "?$select=diplayName&api~version=2" - values["?%24select=diplayName&api%2Eversion=2"] = "?$select=diplayName&api.version=2" - values["/api-version/?%24select=diplayName&api%2Eversion=2"] = "/api-version/?$select=diplayName&api.version=2" - values[""] = "" + it 'decodes encoded query parameters' do + values = {} + values['?%24select=diplayName&api%2Dversion=2'] = '?$select=diplayName&api-version=2' + values['?%24select=diplayName&api%7Eversion=2'] = '?$select=diplayName&api~version=2' + values['?%24select=diplayName&api%2Eversion=2'] = '?$select=diplayName&api.version=2' + values['/api-version/?%24select=diplayName&api%2Eversion=2'] = '/api-version/?$select=diplayName&api.version=2' + values[''] = '' - handler = MicrosoftKiotaFaraday::Middleware::ParametersNameDecodingHandler.new() - values.each do |key, value| - env = { - url: URI.parse("https://graph.microsoft.com/v1.0/users#{key}") - } - handler.call(env) - expect(env[:url].to_s).to eq("https://graph.microsoft.com/v1.0/users#{value}") - end + handler = MicrosoftKiotaFaraday::Middleware::ParametersNameDecodingHandler.new + values.each do |key, value| + env = { + url: URI.parse("https://graph.microsoft.com/v1.0/users#{key}") + } + handler.call(env) + expect(env[:url].to_s).to eq("https://graph.microsoft.com/v1.0/users#{value}") end + end - it "doesn't decode when disabled on request" do - values = Hash.new - values["?%24select=diplayName&api%2Dversion=2"] = "?%24select=diplayName&api%2Dversion=2" - values["?%24select=diplayName&api%7Eversion=2"] = "?%24select=diplayName&api%7Eversion=2" - values["?%24select=diplayName&api%2Eversion=2"] = "?%24select=diplayName&api%2Eversion=2" - values["/api-version/?%24select=diplayName&api%2Eversion=2"] = "/api-version/?%24select=diplayName&api%2Eversion=2" - values[""] = "" + it "doesn't decode when disabled on request" do + values = {} + values['?%24select=diplayName&api%2Dversion=2'] = '?%24select=diplayName&api%2Dversion=2' + values['?%24select=diplayName&api%7Eversion=2'] = '?%24select=diplayName&api%7Eversion=2' + values['?%24select=diplayName&api%2Eversion=2'] = '?%24select=diplayName&api%2Eversion=2' + values['/api-version/?%24select=diplayName&api%2Eversion=2'] = + '/api-version/?%24select=diplayName&api%2Eversion=2' + values[''] = '' - option = MicrosoftKiotaFaraday::Middleware::ParametersNameDecodingOption.new(false) - handler = MicrosoftKiotaFaraday::Middleware::ParametersNameDecodingHandler.new() - values.each do |key, value| - env = { - url: URI.parse("https://graph.microsoft.com/v1.0/users#{key}"), - request: { - context: { - option.get_key => option - } - } - } - handler.call(env) - expect(env[:url].to_s).to eq("https://graph.microsoft.com/v1.0/users#{value}") - end + option = MicrosoftKiotaFaraday::Middleware::ParametersNameDecodingOption.new(false) + handler = MicrosoftKiotaFaraday::Middleware::ParametersNameDecodingHandler.new + values.each do |key, value| + env = { + url: URI.parse("https://graph.microsoft.com/v1.0/users#{key}"), + request: { + context: { + option.get_key => option + } + } + } + handler.call(env) + expect(env[:url].to_s).to eq("https://graph.microsoft.com/v1.0/users#{value}") end + end end diff --git a/components/http/spec/spec_helper.rb b/components/http/spec/spec_helper.rb index 3f2bbab..227d8c8 100644 --- a/components/http/spec/spec_helper.rb +++ b/components/http/spec/spec_helper.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require "microsoft_kiota_faraday" +require 'microsoft_kiota_faraday' Dir["#{File.dirname(__FILE__)}/./../lib/*.rb"].each { |f| load(f) } RSpec.configure do |config| # Enable flags like --only-failures and --next-failure - config.example_status_persistence_file_path = ".rspec_status" + config.example_status_persistence_file_path = '.rspec_status' # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_patching! diff --git a/components/http/spec/user_agent_handler_spec.rb b/components/http/spec/user_agent_handler_spec.rb index d3f30f2..6d40ea8 100644 --- a/components/http/spec/user_agent_handler_spec.rb +++ b/components/http/spec/user_agent_handler_spec.rb @@ -1,44 +1,46 @@ +# frozen_string_literal: true + require 'faraday' # frozen_string_literal: true RSpec.describe MicrosoftKiotaFaraday do - user_agent_key = "User-Agent" - url = "https://graph.microsoft.com/v1.0/users" - it "adds the user agent product" do - handler = MicrosoftKiotaFaraday::Middleware::UserAgentHandler.new() - env = { - url: URI.parse(url), - request_headers: {} - } - handler.call(env) - expect(env[:request_headers][user_agent_key].split("/")[0]).to eq("kiota-ruby") - end + user_agent_key = 'User-Agent' + url = 'https://graph.microsoft.com/v1.0/users' + it 'adds the user agent product' do + handler = MicrosoftKiotaFaraday::Middleware::UserAgentHandler.new + env = { + url: URI.parse(url), + request_headers: {} + } + handler.call(env) + expect(env[:request_headers][user_agent_key].split('/')[0]).to eq('kiota-ruby') + end - it "adds the user agent product once" do - handler = MicrosoftKiotaFaraday::Middleware::UserAgentHandler.new() - env = { - url: URI.parse(url), - request_headers: {} - } - handler.call(env) - handler.call(env) - expect(env[:request_headers][user_agent_key].split("kiota-ruby").length).to eq(2) - end - it "doesnt add the header when disabled" do - handler = MicrosoftKiotaFaraday::Middleware::UserAgentHandler.new() - opt = MicrosoftKiotaFaraday::Middleware::UserAgentOption.new() - opt.enabled = false - env = { - url: URI.parse(url), - request_headers: {}, - request: { - context: { - opt.get_key => opt - } - } + it 'adds the user agent product once' do + handler = MicrosoftKiotaFaraday::Middleware::UserAgentHandler.new + env = { + url: URI.parse(url), + request_headers: {} + } + handler.call(env) + handler.call(env) + expect(env[:request_headers][user_agent_key].split('kiota-ruby').length).to eq(2) + end + it 'doesnt add the header when disabled' do + handler = MicrosoftKiotaFaraday::Middleware::UserAgentHandler.new + opt = MicrosoftKiotaFaraday::Middleware::UserAgentOption.new + opt.enabled = false + env = { + url: URI.parse(url), + request_headers: {}, + request: { + context: { + opt.get_key => opt } - handler.call(env) - handler.call(env) - expect(env[:request_headers][user_agent_key]).to be_nil - end + } + } + handler.call(env) + handler.call(env) + expect(env[:request_headers][user_agent_key]).to be_nil + end end diff --git a/components/serialization/json/CHANGELOG.md b/components/serialization/json/CHANGELOG.md deleted file mode 100644 index 3cb0dc3..0000000 --- a/components/serialization/json/CHANGELOG.md +++ /dev/null @@ -1,57 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [0.10.0](https://github.com/microsoft/kiota-serialization-json-ruby/compare/v0.9.2...v0.10.0) (2026-04-23) - - -### Features - -* upgrade ruby CI matrix to 3.3, 3.4 and 4.0 ([d5cdcbe](https://github.com/microsoft/kiota-serialization-json-ruby/commit/d5cdcbe3cba93c669c0a2070092c223e0fe07ea5)) -* upgrade ruby CI matrix to 3.3, 3.4 and 4.0 ([d3ae6c7](https://github.com/microsoft/kiota-serialization-json-ruby/commit/d3ae6c703a86b90ab65140ef02d9f1ef329c0e6b)) - - -### Bug Fixes - -* update minimum required ruby version to 3.3.0 ([9f270ae](https://github.com/microsoft/kiota-serialization-json-ruby/commit/9f270aeb873d1e420ff766c7de90100753bec8cb)) -* update minimum required ruby version to 3.3.0 ([ec00107](https://github.com/microsoft/kiota-serialization-json-ruby/commit/ec001079bedb0d5c3cd65dedf0ac4b31fe901076)) - -## [Unreleased] - -### Added - -### Changed - -## [0.9.2] - 2025-03-11 - -### Changed - -- Updated dependencies including JSON. - -## [0.9.1] - 2023-08-18 - -### Changed - -- Improve handling of null values (#13) - -## [0.9.0] - 2023-03-28 - -### Changed - -- Updated kiota abstractions reference -- Bumped minimum required ruby version to 3.0. - -## [0.8.0] - 2023-01-18 - -### Changed - -- Fixed a version misalignment with abstractions dependencies. - -## [0.7.0] - 2022-12-30 - -### Added - -- Initial public release of the package. diff --git a/components/serialization/json/Gemfile b/components/serialization/json/Gemfile index 37d7d74..f4859ea 100644 --- a/components/serialization/json/Gemfile +++ b/components/serialization/json/Gemfile @@ -1,7 +1,7 @@ # frozen_string_literal: true -source "https://rubygems.org" +source 'https://rubygems.org' -gem "microsoft_kiota_abstractions", path: "../../abstractions" +gem 'microsoft_kiota_abstractions', path: '../../abstractions' gemspec diff --git a/components/serialization/json/Rakefile b/components/serialization/json/Rakefile index b6ae734..82bb534 100644 --- a/components/serialization/json/Rakefile +++ b/components/serialization/json/Rakefile @@ -1,7 +1,7 @@ # frozen_string_literal: true -require "bundler/gem_tasks" -require "rspec/core/rake_task" +require 'bundler/gem_tasks' +require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) diff --git a/components/serialization/json/lib/microsoft_kiota_serialization_json.rb b/components/serialization/json/lib/microsoft_kiota_serialization_json.rb index 83bd6f3..128b3e6 100644 --- a/components/serialization/json/lib/microsoft_kiota_serialization_json.rb +++ b/components/serialization/json/lib/microsoft_kiota_serialization_json.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require_relative "microsoft_kiota_serialization_json/json_parse_node" -require_relative "microsoft_kiota_serialization_json/json_parse_node_factory" -require_relative "microsoft_kiota_serialization_json/json_serialization_writer" -require_relative "microsoft_kiota_serialization_json/json_serialization_writer_factory" -require_relative "microsoft_kiota_serialization_json/version" +require_relative 'microsoft_kiota_serialization_json/json_parse_node' +require_relative 'microsoft_kiota_serialization_json/json_parse_node_factory' +require_relative 'microsoft_kiota_serialization_json/json_serialization_writer' +require_relative 'microsoft_kiota_serialization_json/json_serialization_writer_factory' +require_relative 'microsoft_kiota_serialization_json/version' module MicrosoftKiotaSerializationJson end diff --git a/components/serialization/json/lib/microsoft_kiota_serialization_json/json_parse_node.rb b/components/serialization/json/lib/microsoft_kiota_serialization_json/json_parse_node.rb index 5b0bc94..b1a8ca0 100644 --- a/components/serialization/json/lib/microsoft_kiota_serialization_json/json_parse_node.rb +++ b/components/serialization/json/lib/microsoft_kiota_serialization_json/json_parse_node.rb @@ -1,13 +1,15 @@ +# frozen_string_literal: true + require 'time' require 'date' require 'json' require 'uuidtools' require 'microsoft_kiota_abstractions' - module MicrosoftKiotaSerializationJson class JsonParseNode include MicrosoftKiotaAbstractions::ParseNode + def initialize(node) @current_node = node end @@ -36,15 +38,15 @@ def get_date_value Date.parse(@current_node) end - def get_time_value() + def get_time_value Time.parse(@current_node) end - def get_date_time_value() + def get_date_time_value DateTime.parse(@current_node) end - def get_duration_value() + def get_duration_value MicrosoftKiotaAbstractions::ISODuration.new(@current_node) end @@ -60,7 +62,7 @@ def get_collection_of_primitive_values(type) current_parse_node.get_float_value when Integer current_parse_node.get_float_value - when "Boolean" + when 'Boolean' current_parse_node.get_float_value when DateTime current_parse_node.get_date_time_value @@ -82,6 +84,7 @@ def get_collection_of_primitive_values(type) def get_collection_of_object_values(factory) raise StandardError, 'Factory cannot be null' if factory.nil? + @current_node.map do |object| next if object.nil? @@ -92,6 +95,7 @@ def get_collection_of_object_values(factory) def get_object_value(factory) raise StandardError, 'Factory cannot be null' if factory.nil? + item = factory.call(self) assign_field_values(item) item @@ -110,7 +114,7 @@ def assign_field_values(item) elsif item.additional_data item.additional_data[k] = v else - item.additional_data = Hash.new(k => v) + item.additional_data = Hash.new({ k => v }) end end end @@ -127,8 +131,9 @@ def get_enum_value(type) def get_child_node(name) raise StandardError, 'Name cannot be null' if name.nil? || name.empty? + raw_value = @current_node[name] - return JsonParseNode.new(raw_value) if raw_value + JsonParseNode.new(raw_value) if raw_value end end end diff --git a/components/serialization/json/lib/microsoft_kiota_serialization_json/json_parse_node_factory.rb b/components/serialization/json/lib/microsoft_kiota_serialization_json/json_parse_node_factory.rb index 6556ff0..b96f805 100644 --- a/components/serialization/json/lib/microsoft_kiota_serialization_json/json_parse_node_factory.rb +++ b/components/serialization/json/lib/microsoft_kiota_serialization_json/json_parse_node_factory.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'json' require 'microsoft_kiota_abstractions' diff --git a/components/serialization/json/lib/microsoft_kiota_serialization_json/json_serialization_writer.rb b/components/serialization/json/lib/microsoft_kiota_serialization_json/json_serialization_writer.rb index 5856f8c..f354d89 100644 --- a/components/serialization/json/lib/microsoft_kiota_serialization_json/json_serialization_writer.rb +++ b/components/serialization/json/lib/microsoft_kiota_serialization_json/json_serialization_writer.rb @@ -1,183 +1,127 @@ +# frozen_string_literal: true + require 'time' require 'date' require 'json' -require "uuidtools" +require 'uuidtools' require 'microsoft_kiota_abstractions' module MicrosoftKiotaSerializationJson class JsonSerializationWriter include MicrosoftKiotaAbstractions::SerializationWriter - @writer - def initialize() - @writer = Hash.new() + def initialize + @writer = {} end - def writer - @writer - end + attr_reader :writer def write_string_value(key, value) - if !key && !value - raise StandardError, "no key or value included in write_string_value(key, value)" - end - if !key - return value.to_s - end - if !value - @writer[key] = nil - else - @writer[key] = value - end + raise StandardError, 'no key or value included in write_string_value(key, value)' if !key && !value + return value.to_s unless key + + @writer[key] = (value || nil) end def write_boolean_value(key, value) - if !key && !value - raise StandardError, "no key or value included in write_boolean_value(key, value)" - end - if !key - return value - end + raise StandardError, 'no key or value included in write_boolean_value(key, value)' if !key && !value + return value unless key + @writer[key] = value end def write_number_value(key, value) - if !key && !value - raise StandardError, "no key or value included in write_number_value(key, value)" - end - if !key - return value - end + raise StandardError, 'no key or value included in write_number_value(key, value)' if !key && !value + return value unless key + @writer[key] = value end def write_float_value(key, value) - if !key && !value - raise StandardError, "no key or value included in write_float_value(key, value)" - end - if !key - return value - end + raise StandardError, 'no key or value included in write_float_value(key, value)' if !key && !value + return value unless key + @writer[key] = value end def write_guid_value(key, value) - if !key && !value - raise StandardError, "no key or value included in write_guid_value(key, value)" - end - if !key - return value.to_s - end - if !value - @writer[key] = nil - else - @writer[key] = value.to_s - end + raise StandardError, 'no key or value included in write_guid_value(key, value)' if !key && !value + return value.to_s unless key + + @writer[key] = (value.to_s if value) end def write_date_value(key, value) - if !key && !value - raise StandardError, "no key or value included in write_date_value(key, value)" - end - if !key - return value.strftime("%Y-%m-%d") - end - if !value - @writer[key] = nil - else - @writer[key] = value.strftime("%Y-%m-%d") - end + raise StandardError, 'no key or value included in write_date_value(key, value)' if !key && !value + return value.strftime('%Y-%m-%d') unless key + + @writer[key] = (value.strftime('%Y-%m-%d') if value) end def write_time_value(key, value) - if !key && !value - raise StandardError, "no key or value included in write_time_value(key, value)" - end - if !key - return value.strftime("%H:%M:%S%Z") - end - if !value - @writer[key] = nil - else - @writer[key] = value.strftime("%H:%M:%S%Z") - end + raise StandardError, 'no key or value included in write_time_value(key, value)' if !key && !value + return value.strftime('%H:%M:%S%Z') unless key + + @writer[key] = (value.strftime('%H:%M:%S%Z') if value) end def write_date_time_value(key, value) - if !key && !value - raise StandardError, "no key or value included in write_date_time_value(key, value)" - end - if !key - return value.strftime("%Y-%m-%dT%H:%M:%S%Z") - end - if !value - @writer[key] = nil - else - @writer[key] = value.strftime("%Y-%m-%dT%H:%M:%S%Z") - end + raise StandardError, 'no key or value included in write_date_time_value(key, value)' if !key && !value + return value.strftime('%Y-%m-%dT%H:%M:%S%Z') unless key + + @writer[key] = (value.strftime('%Y-%m-%dT%H:%M:%S%Z') if value) end def write_duration_value(key, value) - if !key && !value - raise StandardError, "no key or value included in write_duration_value(key, value)" - end - if !key - return value.string - end - if !value - @writer[key] = nil - else - @writer[key] = value.string - end + raise StandardError, 'no key or value included in write_duration_value(key, value)' if !key && !value + return value.string unless key + + @writer[key] = (value.string if value) end def write_collection_of_primitive_values(key, values) - if values - if !key - return values.map do |v| - self.write_any_value(nil, v) - end - end - @writer[key] = values.map do |v| - self.write_any_value(key, v) + return unless values + unless key + return values.map do |v| + write_any_value(nil, v) end end + @writer[key] = values.map do |v| + write_any_value(key, v) + end end def write_collection_of_object_values(key, values) - if values - if !key - return values.map { |v| write_object_value(nil, v) } - end - @writer[key] = values.map { |v| object_value_hash(v) } - end + return unless values + return values.map { |v| write_object_value(nil, v) } unless key + + @writer[key] = values.map { |v| object_value_hash(v) } end def write_object_value(key, value, *additional_values_to_merge) - if value - if key - @writer[key] = object_value_hash(value, *additional_values_to_merge) - else - value.serialize(self) - additional_values_to_merge.each { |v| v.serialize(self) unless v.nil? } - end + return unless value + + if key + @writer[key] = object_value_hash(value, *additional_values_to_merge) + else + value.serialize(self) + additional_values_to_merge.each { |v| v&.serialize(self) } end end def write_enum_value(key, values) - self.write_string_value(key, values.to_s) + write_string_value(key, values.to_s) end - def get_serialized_content() - return @writer.to_json #TODO encode to byte array to stay content type agnostic + def get_serialized_content + @writer.to_json # TODO: encode to byte array to stay content type agnostic end def write_additional_data(value) - if !value - return - end + return unless value + value.each do |x, y| - self.write_any_value(x,y) + write_any_value(x, y) end end @@ -186,7 +130,7 @@ def write_additional_data(value) def object_value_hash(value, *additional_values_to_merge) temp = JsonSerializationWriter.new value.serialize(temp) - additional_values_to_merge.each { |v| v.serialize(temp) unless v.nil? } + additional_values_to_merge.each { |v| v&.serialize(temp) } temp.writer end @@ -194,35 +138,34 @@ def object_value_hash(value, *additional_values_to_merge) def write_any_value(key, value) if value - if !!value == value - return value + if !value.nil? == value + value elsif value.instance_of? String - return self.write_string_value(key, value) + write_string_value(key, value) elsif value.instance_of? Integer - return self.write_number_value(key, value) + write_number_value(key, value) elsif value.instance_of? Float - return self.write_float_value(key, value) + write_float_value(key, value) elsif value.instance_of? DateTime - return self.write_date_time_value(key, value) + write_date_time_value(key, value) elsif value.instance_of? Time - return self.write_time_value(key, value) + write_time_value(key, value) elsif value.instance_of? Date - return self.write_date_value(key, value) + write_date_value(key, value) elsif value.instance_of? MicrosoftKiotaAbstractions::ISODuration - return self.write_duration_value(key, value) + write_duration_value(key, value) elsif value.instance_of? Array - return self.write_collection_of_primitive_values(key, value) + write_collection_of_primitive_values(key, value) elsif value.is_a? Object - return value.to_s + value.to_s else - raise StandardError, "encountered unknown value type during serialization #{value.to_s}" + raise StandardError, "encountered unknown value type during serialization #{value}" end else - if key - @writer[key] = nil - else - raise StandardError, "no key included when writing json property" - end + raise StandardError, 'no key included when writing json property' unless key + + @writer[key] = nil + end end end diff --git a/components/serialization/json/lib/microsoft_kiota_serialization_json/json_serialization_writer_factory.rb b/components/serialization/json/lib/microsoft_kiota_serialization_json/json_serialization_writer_factory.rb index 3432d7f..01f77fb 100644 --- a/components/serialization/json/lib/microsoft_kiota_serialization_json/json_serialization_writer_factory.rb +++ b/components/serialization/json/lib/microsoft_kiota_serialization_json/json_serialization_writer_factory.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'microsoft_kiota_abstractions' module MicrosoftKiotaSerializationJson diff --git a/components/serialization/json/lib/microsoft_kiota_serialization_json/version.rb b/components/serialization/json/lib/microsoft_kiota_serialization_json/version.rb index 93f54d5..9e0816e 100644 --- a/components/serialization/json/lib/microsoft_kiota_serialization_json/version.rb +++ b/components/serialization/json/lib/microsoft_kiota_serialization_json/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module MicrosoftKiotaSerializationJson - VERSION = "0.17.0" + VERSION = '0.17.0' # x-release-please-version end diff --git a/components/serialization/json/microsoft_kiota_serialization_json.gemspec b/components/serialization/json/microsoft_kiota_serialization_json.gemspec index 1a343ea..f58201f 100644 --- a/components/serialization/json/microsoft_kiota_serialization_json.gemspec +++ b/components/serialization/json/microsoft_kiota_serialization_json.gemspec @@ -1,38 +1,35 @@ # frozen_string_literal: true -require_relative "lib/microsoft_kiota_serialization_json/version" +require_relative 'lib/microsoft_kiota_serialization_json/version' Gem::Specification.new do |spec| - spec.name = "microsoft_kiota_serialization_json" + spec.name = 'microsoft_kiota_serialization_json' spec.version = MicrosoftKiotaSerializationJson::VERSION spec.authors = 'Microsoft Corporation' - spec.email = 'graphsdkpub@microsoft.com' + spec.email = 'graphsdkpub+ruby@microsoft.com' spec.description = 'Implementation of Kiota Serialization interfaces for JSON' spec.summary = 'Microsoft Kiota Serialization - Ruby serialization for building library agnostic http client' spec.homepage = 'https://microsoft.github.io/kiota/' spec.license = 'MIT' spec.metadata = { 'bug_tracker_uri' => 'https://github.com/microsoft/kiota-ruby/issues', - 'changelog_uri' => 'https://github.com/microsoft/kiota-ruby/blob/main/components/serialization/json/CHANGELOG.md', - 'homepage_uri' => spec.homepage, + 'changelog_uri' => 'https://github.com/microsoft/kiota-ruby/blob/main/CHANGELOG.md', + 'homepage_uri' => spec.homepage, 'source_code_uri' => 'https://github.com/microsoft/kiota-ruby/tree/main/components/serialization/json', - 'github_repo' => 'ssh://github.com/microsoft/kiota-ruby' + 'github_repo' => 'ssh://github.com/microsoft/kiota-ruby', + 'rubygems_mfa_required' => 'true' } - spec.required_ruby_version = ">= 3.3.0" + spec.required_ruby_version = '>= 3.3.0' - # Specify which files should be added to the gem when it is released. - # The `git ls-files -z` loads the files in the RubyGem that have been added into git. spec.files = Dir.chdir(File.expand_path(__dir__)) do `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) } end - 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.17', '< 0.18' - spec.add_runtime_dependency 'uuidtools', '>= 2.2', '< 3.1' - spec.add_runtime_dependency 'json', '>= 2.6.3', '< 2.22.0' + spec.add_dependency 'json', '>= 2.6.3', '< 2.22.0' + spec.add_dependency 'microsoft_kiota_abstractions', '>= 0.17', '< 0.18' + spec.add_dependency 'uuidtools', '>= 2.2', '< 3.1' spec.add_development_dependency 'rake', '~> 13.0' spec.add_development_dependency 'rspec', '~> 3.0' spec.add_development_dependency 'rubocop' diff --git a/components/serialization/json/spec/files/body_type.rb b/components/serialization/json/spec/files/body_type.rb index 8409dc2..9480e68 100644 --- a/components/serialization/json/spec/files/body_type.rb +++ b/components/serialization/json/spec/files/body_type.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + module Files - BodyType = { - Text: :Text, - Html: :Html, - } + BodyType = { + Text: :Text, + Html: :Html + }.freeze end diff --git a/components/serialization/json/spec/files/email_address.rb b/components/serialization/json/spec/files/email_address.rb index 5e1b057..06492d8 100644 --- a/components/serialization/json/spec/files/email_address.rb +++ b/components/serialization/json/spec/files/email_address.rb @@ -1,98 +1,95 @@ +# frozen_string_literal: true + require 'microsoft_kiota_abstractions' module Files - class EmailAddress - include MicrosoftKiotaAbstractions::AdditionalDataHolder, MicrosoftKiotaAbstractions::Parsable - ## - # Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. - @additional_data - ## - # The email address of the person or entity. - @address - ## - # The display name of the person or entity. - @name - ## - ## Gets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. - ## @return a i_dictionary - ## - def additional_data - return @additional_data - end - ## - ## Sets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. - ## @param value Value to set for the AdditionalData property. - ## @return a void - ## - def additional_data=(value) - @additional_data = value - end - ## - ## Gets the address property value. The email address of the person or entity. - ## @return a string - ## - def address - return @address - end - ## - ## Sets the address property value. The email address of the person or entity. - ## @param value Value to set for the address property. - ## @return a void - ## - def address=(value) - @address = value - end - ## - ## Instantiates a new emailAddress and sets the default values. - ## @return a void - ## - def initialize() - @additional_data = Hash.new - end - ## - ## Creates a new instance of the appropriate class based on discriminator value - ## @param parseNode The parse node to use to read the discriminator value and create the object - ## @return a email_address - ## - def self.create_from_discriminator_value(parse_node) - raise StandardError, 'parse_node cannot be null' if parse_node.nil? - return EmailAddress.new - end - ## - ## The deserialization information for the current model - ## @return a i_dictionary - ## - def get_field_deserializers() - return { - "address" => lambda {|n| @address = n.get_string_value() }, - "name" => lambda {|n| @name = n.get_string_value() }, - } - end - ## - ## Gets the name property value. The display name of the person or entity. - ## @return a string - ## - def name - return @name - end - ## - ## Sets the name property value. The display name of the person or entity. - ## @param value Value to set for the name property. - ## @return a void - ## - def name=(value) - @name = value - end - ## - ## Serializes information the current object - ## @param writer Serialization writer to use to serialize this model - ## @return a void - ## - def serialize(writer) - raise StandardError, 'writer cannot be null' if writer.nil? - writer.write_string_value("address", @address) - writer.write_string_value("name", @name) - writer.write_additional_data(@additional_data) - end + class EmailAddress + include MicrosoftKiotaAbstractions::Parsable + include MicrosoftKiotaAbstractions::AdditionalDataHolder + + ## + # Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## + # The email address of the person or entity. + ## + # The display name of the person or entity. + ## + ## Gets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## @return a i_dictionary + ## + attr_accessor :additional_data + + ## + ## Sets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## @param value Value to set for the AdditionalData property. + ## @return a void + ## + + ## + ## Gets the address property value. The email address of the person or entity. + ## @return a string + ## + attr_accessor :address + + ## + ## Sets the address property value. The email address of the person or entity. + ## @param value Value to set for the address property. + ## @return a void + ## + + ## + ## Instantiates a new emailAddress and sets the default values. + ## @return a void + ## + def initialize + @additional_data = {} + end + + ## + ## Creates a new instance of the appropriate class based on discriminator value + ## @param parseNode The parse node to use to read the discriminator value and create the object + ## @return a email_address + ## + def self.create_from_discriminator_value(parse_node) + raise StandardError, 'parse_node cannot be null' if parse_node.nil? + + EmailAddress.new + end + + ## + ## The deserialization information for the current model + ## @return a i_dictionary + ## + def get_field_deserializers + { + 'address' => ->(n) { @address = n.get_string_value }, + 'name' => ->(n) { @name = n.get_string_value } + } + end + + ## + ## Gets the name property value. The display name of the person or entity. + ## @return a string + ## + attr_accessor :name + + ## + ## Sets the name property value. The display name of the person or entity. + ## @param value Value to set for the name property. + ## @return a void + ## + + ## + ## Serializes information the current object + ## @param writer Serialization writer to use to serialize this model + ## @return a void + ## + def serialize(writer) + raise StandardError, 'writer cannot be null' if writer.nil? + + writer.write_string_value('address', @address) + writer.write_string_value('name', @name) + writer.write_additional_data(@additional_data) end + end end diff --git a/components/serialization/json/spec/files/entity.rb b/components/serialization/json/spec/files/entity.rb index 8b3c9eb..6b25dbe 100644 --- a/components/serialization/json/spec/files/entity.rb +++ b/components/serialization/json/spec/files/entity.rb @@ -1,78 +1,79 @@ +# frozen_string_literal: true + require 'microsoft_kiota_abstractions' module Files - class Entity - include MicrosoftKiotaAbstractions::AdditionalDataHolder, MicrosoftKiotaAbstractions::Parsable - ## - # Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. - @additional_data - ## - # The unique idenfier for an entity. Read-only. - @id - ## - ## Gets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. - ## @return a i_dictionary - ## - def additional_data - return @additional_data - end - ## - ## Sets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. - ## @param value Value to set for the AdditionalData property. - ## @return a void - ## - def additional_data=(value) - @additional_data = value - end - ## - ## Instantiates a new entity and sets the default values. - ## @return a void - ## - def initialize() - @additional_data = Hash.new - end - ## - ## Creates a new instance of the appropriate class based on discriminator value - ## @param parseNode The parse node to use to read the discriminator value and create the object - ## @return a entity - ## - def self.create_from_discriminator_value(parse_node) - raise StandardError, 'parse_node cannot be null' if parse_node.nil? - return Entity.new - end - ## - ## The deserialization information for the current model - ## @return a i_dictionary - ## - def get_field_deserializers() - return { - "id" => lambda {|n| @id = n.get_string_value() }, - } - end - ## - ## Gets the id property value. The unique idenfier for an entity. Read-only. - ## @return a string - ## - def id - return @id - end - ## - ## Sets the id property value. The unique idenfier for an entity. Read-only. - ## @param value Value to set for the id property. - ## @return a void - ## - def id=(value) - @id = value - end - ## - ## Serializes information the current object - ## @param writer Serialization writer to use to serialize this model - ## @return a void - ## - def serialize(writer) - raise StandardError, 'writer cannot be null' if writer.nil? - writer.write_string_value("id", @id) - writer.write_additional_data(@additional_data) - end + class Entity + include MicrosoftKiotaAbstractions::Parsable + include MicrosoftKiotaAbstractions::AdditionalDataHolder + + ## + # Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## + # The unique idenfier for an entity. Read-only. + ## + ## Gets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## @return a i_dictionary + ## + attr_accessor :additional_data + + ## + ## Sets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## @param value Value to set for the AdditionalData property. + ## @return a void + ## + + ## + ## Instantiates a new entity and sets the default values. + ## @return a void + ## + def initialize + @additional_data = {} + end + + ## + ## Creates a new instance of the appropriate class based on discriminator value + ## @param parseNode The parse node to use to read the discriminator value and create the object + ## @return a entity + ## + def self.create_from_discriminator_value(parse_node) + raise StandardError, 'parse_node cannot be null' if parse_node.nil? + + Entity.new + end + + ## + ## The deserialization information for the current model + ## @return a i_dictionary + ## + def get_field_deserializers + { + 'id' => ->(n) { @id = n.get_string_value } + } + end + + ## + ## Gets the id property value. The unique idenfier for an entity. Read-only. + ## @return a string + ## + attr_accessor :id + + ## + ## Sets the id property value. The unique idenfier for an entity. Read-only. + ## @param value Value to set for the id property. + ## @return a void + ## + + ## + ## Serializes information the current object + ## @param writer Serialization writer to use to serialize this model + ## @return a void + ## + def serialize(writer) + raise StandardError, 'writer cannot be null' if writer.nil? + + writer.write_string_value('id', @id) + writer.write_additional_data(@additional_data) end + end end diff --git a/components/serialization/json/spec/files/files.rb b/components/serialization/json/spec/files/files.rb index 868ff5a..b742b32 100644 --- a/components/serialization/json/spec/files/files.rb +++ b/components/serialization/json/spec/files/files.rb @@ -1,12 +1,14 @@ +# frozen_string_literal: true + require 'microsoft_kiota_abstractions' -require_relative './body_type' -require_relative './email_address' -require_relative './entity' -require_relative './item_body' -require_relative './message' -require_relative './messages_response' -require_relative './outlook_item' -require_relative './recipient' +require_relative 'body_type' +require_relative 'email_address' +require_relative 'entity' +require_relative 'item_body' +require_relative 'message' +require_relative 'messages_response' +require_relative 'outlook_item' +require_relative 'recipient' -module Files -end \ No newline at end of file +module Files +end diff --git a/components/serialization/json/spec/files/item_body.rb b/components/serialization/json/spec/files/item_body.rb index b557597..79d8f3f 100644 --- a/components/serialization/json/spec/files/item_body.rb +++ b/components/serialization/json/spec/files/item_body.rb @@ -1,98 +1,95 @@ +# frozen_string_literal: true + require 'microsoft_kiota_abstractions' module Files - class ItemBody - include MicrosoftKiotaAbstractions::AdditionalDataHolder, MicrosoftKiotaAbstractions::Parsable - ## - # Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. - @additional_data - ## - # The content of the item. - @content - ## - # The contentType property - @content_type - ## - ## Gets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. - ## @return a i_dictionary - ## - def additional_data - return @additional_data - end - ## - ## Sets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. - ## @param value Value to set for the AdditionalData property. - ## @return a void - ## - def additional_data=(value) - @additional_data = value - end - ## - ## Instantiates a new itemBody and sets the default values. - ## @return a void - ## - def initialize() - @additional_data = Hash.new - end - ## - ## Gets the content property value. The content of the item. - ## @return a string - ## - def content - return @content - end - ## - ## Sets the content property value. The content of the item. - ## @param value Value to set for the content property. - ## @return a void - ## - def content=(value) - @content = value - end - ## - ## Gets the contentType property value. The contentType property - ## @return a body_type - ## - def content_type - return @content_type - end - ## - ## Sets the contentType property value. The contentType property - ## @param value Value to set for the contentType property. - ## @return a void - ## - def content_type=(value) - @content_type = value - end - ## - ## Creates a new instance of the appropriate class based on discriminator value - ## @param parseNode The parse node to use to read the discriminator value and create the object - ## @return a item_body - ## - def self.create_from_discriminator_value(parse_node) - raise StandardError, 'parse_node cannot be null' if parse_node.nil? - return ItemBody.new - end - ## - ## The deserialization information for the current model - ## @return a i_dictionary - ## - def get_field_deserializers() - return { - "content" => lambda {|n| @content = n.get_string_value() }, - "contentType" => lambda {|n| @content_type = n.get_enum_value(Files::BodyType) }, - } - end - ## - ## Serializes information the current object - ## @param writer Serialization writer to use to serialize this model - ## @return a void - ## - def serialize(writer) - raise StandardError, 'writer cannot be null' if writer.nil? - writer.write_string_value("content", @content) - writer.write_enum_value("contentType", @content_type) - writer.write_additional_data(@additional_data) - end + class ItemBody + include MicrosoftKiotaAbstractions::Parsable + include MicrosoftKiotaAbstractions::AdditionalDataHolder + + ## + # Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## + # The content of the item. + ## + # The contentType property + ## + ## Gets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## @return a i_dictionary + ## + attr_accessor :additional_data + + ## + ## Sets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## @param value Value to set for the AdditionalData property. + ## @return a void + ## + + ## + ## Instantiates a new itemBody and sets the default values. + ## @return a void + ## + def initialize + @additional_data = {} + end + + ## + ## Gets the content property value. The content of the item. + ## @return a string + ## + attr_accessor :content + + ## + ## Sets the content property value. The content of the item. + ## @param value Value to set for the content property. + ## @return a void + ## + + ## + ## Gets the contentType property value. The contentType property + ## @return a body_type + ## + attr_accessor :content_type + + ## + ## Sets the contentType property value. The contentType property + ## @param value Value to set for the contentType property. + ## @return a void + ## + + ## + ## Creates a new instance of the appropriate class based on discriminator value + ## @param parseNode The parse node to use to read the discriminator value and create the object + ## @return a item_body + ## + def self.create_from_discriminator_value(parse_node) + raise StandardError, 'parse_node cannot be null' if parse_node.nil? + + ItemBody.new + end + + ## + ## The deserialization information for the current model + ## @return a i_dictionary + ## + def get_field_deserializers + { + 'content' => ->(n) { @content = n.get_string_value }, + 'contentType' => ->(n) { @content_type = n.get_enum_value(Files::BodyType) } + } + end + + ## + ## Serializes information the current object + ## @param writer Serialization writer to use to serialize this model + ## @return a void + ## + def serialize(writer) + raise StandardError, 'writer cannot be null' if writer.nil? + + writer.write_string_value('content', @content) + writer.write_enum_value('contentType', @content_type) + writer.write_additional_data(@additional_data) end + end end diff --git a/components/serialization/json/spec/files/message.rb b/components/serialization/json/spec/files/message.rb index fad72a5..b84bb63 100644 --- a/components/serialization/json/spec/files/message.rb +++ b/components/serialization/json/spec/files/message.rb @@ -1,643 +1,559 @@ +# frozen_string_literal: true + require 'date' require 'microsoft_kiota_abstractions' -require_relative './outlook_item' +require_relative 'outlook_item' module Files - class Message < Files::OutlookItem - include MicrosoftKiotaAbstractions::Parsable - @guid_id - def guid_id=(guid_id) - @guid_id = guid_id - end - def guid_id - return @guid_id - end - ## - # The fileAttachment and itemAttachment attachments for the message. - @attachments - ## - # The Bcc: recipients for the message. - @bcc_recipients - ## - # The body property - @body - ## - # The first 255 characters of the message body. It is in text format. - @body_preview - ## - # The Cc: recipients for the message. - @cc_recipients - ## - # The ID of the conversation the email belongs to. - @conversation_id - ## - # Indicates the position of the message within the conversation. - @conversation_index - ## - # The collection of open extensions defined for the message. Nullable. - @extensions - ## - # The flag property - @flag - ## - # The from property - @from - ## - # Indicates whether the message has attachments. This property doesn't include inline attachments, so if a message contains only inline attachments, this property is false. To verify the existence of inline attachments, parse the body property to look for a src attribute, such as . - @has_attachments - ## - # The importance property - @importance - ## - # The inferenceClassification property - @inference_classification - ## - # The internetMessageHeaders property - @internet_message_headers - ## - # The internetMessageId property - @internet_message_id - ## - # The isDeliveryReceiptRequested property - @is_delivery_receipt_requested - ## - # The isDraft property - @is_draft - ## - # The isRead property - @is_read - ## - # The isReadReceiptRequested property - @is_read_receipt_requested - ## - # The collection of multi-value extended properties defined for the message. Nullable. - @multi_value_extended_properties - ## - # The parentFolderId property - @parent_folder_id - ## - # The receivedDateTime property - @received_date_time - ## - # The replyTo property - @reply_to - ## - # The sender property - @sender - ## - # The sentDateTime property - @sent_date_time - ## - # The collection of single-value extended properties defined for the message. Nullable. - @single_value_extended_properties - ## - # The subject property - @subject - ## - # The toRecipients property - @to_recipients - ## - # The uniqueBody property - @unique_body - ## - # The webLink property - @web_link - ## - ## Gets the attachments property value. The fileAttachment and itemAttachment attachments for the message. - ## @return a attachment - ## - def attachments - return @attachments - end - ## - ## Sets the attachments property value. The fileAttachment and itemAttachment attachments for the message. - ## @param value Value to set for the attachments property. - ## @return a void - ## - def attachments=(value) - @attachments = value - end - ## - ## Gets the bccRecipients property value. The Bcc: recipients for the message. - ## @return a recipient - ## - def bcc_recipients - return @bcc_recipients - end - ## - ## Sets the bccRecipients property value. The Bcc: recipients for the message. - ## @param value Value to set for the bccRecipients property. - ## @return a void - ## - def bcc_recipients=(value) - @bcc_recipients = value - end - ## - ## Gets the body property value. The body property - ## @return a item_body - ## - def body - return @body - end - ## - ## Sets the body property value. The body property - ## @param value Value to set for the body property. - ## @return a void - ## - def body=(value) - @body = value - end - ## - ## Gets the bodyPreview property value. The first 255 characters of the message body. It is in text format. - ## @return a string - ## - def body_preview - return @body_preview - end - ## - ## Sets the bodyPreview property value. The first 255 characters of the message body. It is in text format. - ## @param value Value to set for the bodyPreview property. - ## @return a void - ## - def body_preview=(value) - @body_preview = value - end - ## - ## Gets the ccRecipients property value. The Cc: recipients for the message. - ## @return a recipient - ## - def cc_recipients - return @cc_recipients - end - ## - ## Sets the ccRecipients property value. The Cc: recipients for the message. - ## @param value Value to set for the ccRecipients property. - ## @return a void - ## - def cc_recipients=(value) - @cc_recipients = value - end - ## - ## Instantiates a new message and sets the default values. - ## @return a void - ## - def initialize() - super - end - ## - ## Gets the conversationId property value. The ID of the conversation the email belongs to. - ## @return a string - ## - def conversation_id - return @conversation_id - end - ## - ## Sets the conversationId property value. The ID of the conversation the email belongs to. - ## @param value Value to set for the conversationId property. - ## @return a void - ## - def conversation_id=(value) - @conversation_id = value - end - ## - ## Gets the conversationIndex property value. Indicates the position of the message within the conversation. - ## @return a binary - ## - def conversation_index - return @conversation_index - end - ## - ## Sets the conversationIndex property value. Indicates the position of the message within the conversation. - ## @param value Value to set for the conversationIndex property. - ## @return a void - ## - def conversation_index=(value) - @conversation_index = value - end - ## - ## Creates a new instance of the appropriate class based on discriminator value - ## @param parseNode The parse node to use to read the discriminator value and create the object - ## @return a message - ## - def self.create_from_discriminator_value(parse_node) - raise StandardError, 'parse_node cannot be null' if parse_node.nil? - return Message.new - end - ## - ## Gets the extensions property value. The collection of open extensions defined for the message. Nullable. - ## @return a extension - ## - def extensions - return @extensions - end - ## - ## Sets the extensions property value. The collection of open extensions defined for the message. Nullable. - ## @param value Value to set for the extensions property. - ## @return a void - ## - def extensions=(value) - @extensions = value - end - ## - ## Gets the flag property value. The flag property - ## @return a followup_flag - ## - def flag - return @flag - end - ## - ## Sets the flag property value. The flag property - ## @param value Value to set for the flag property. - ## @return a void - ## - def flag=(value) - @flag = value - end - ## - ## Gets the from property value. The from property - ## @return a recipient - ## - def from - return @from - end - ## - ## Sets the from property value. The from property - ## @param value Value to set for the from property. - ## @return a void - ## - def from=(value) - @from = value - end - ## - ## The deserialization information for the current model - ## @return a i_dictionary - ## - def get_field_deserializers() - return super.merge({ - "guidId" => lambda {|n| @guid_id = n.get_guid_value() }, - "bccRecipients" => lambda {|n| @bcc_recipients = n.get_collection_of_object_values(lambda {|pn| Files::Recipient.create_from_discriminator_value(pn) }) }, - "body" => lambda {|n| @body = n.get_object_value(lambda {|pn| Files::ItemBody.create_from_discriminator_value(pn) }) }, - "bodyPreview" => lambda {|n| @body_preview = n.get_string_value() }, - "ccRecipients" => lambda {|n| @cc_recipients = n.get_collection_of_object_values(lambda {|pn| Files::Recipient.create_from_discriminator_value(pn) }) }, - "conversationId" => lambda {|n| @conversation_id = n.get_string_value() }, - "conversationIndex" => lambda {|n| @conversation_index = n.get_string_value() }, - "from" => lambda {|n| @from = n.get_object_value(lambda {|pn| Files::Recipient.create_from_discriminator_value(pn) }) }, - "hasAttachments" => lambda {|n| @has_attachments = n.get_boolean_value() }, - "internetMessageId" => lambda {|n| @internet_message_id = n.get_string_value() }, - "isDeliveryReceiptRequested" => lambda {|n| @is_delivery_receipt_requested = n.get_boolean_value() }, - "isDraft" => lambda {|n| @is_draft = n.get_boolean_value() }, - "isRead" => lambda {|n| @is_read = n.get_boolean_value() }, - "isReadReceiptRequested" => lambda {|n| @is_read_receipt_requested = n.get_boolean_value() }, - "parentFolderId" => lambda {|n| @parent_folder_id = n.get_string_value() }, - "receivedDateTime" => lambda {|n| @received_date_time = n.get_date_time_value() }, - "replyTo" => lambda {|n| @reply_to = n.get_collection_of_object_values(lambda {|pn| Files::Recipient.create_from_discriminator_value(pn) }) }, - "sender" => lambda {|n| @sender = n.get_object_value(lambda {|pn| Files::Recipient.create_from_discriminator_value(pn) }) }, - "sentDateTime" => lambda {|n| @sent_date_time = n.get_date_time_value() }, - "subject" => lambda {|n| @subject = n.get_string_value() }, - "toRecipients" => lambda {|n| @to_recipients = n.get_collection_of_object_values(lambda {|pn| Files::Recipient.create_from_discriminator_value(pn) }) }, - "uniqueBody" => lambda {|n| @unique_body = n.get_object_value(lambda {|pn| Files::ItemBody.create_from_discriminator_value(pn) }) }, - "webLink" => lambda {|n| @web_link = n.get_string_value() }, - }) - end - ## - ## Gets the hasAttachments property value. Indicates whether the message has attachments. This property doesn't include inline attachments, so if a message contains only inline attachments, this property is false. To verify the existence of inline attachments, parse the body property to look for a src attribute, such as . - ## @return a boolean - ## - def has_attachments - return @has_attachments - end - ## - ## Sets the hasAttachments property value. Indicates whether the message has attachments. This property doesn't include inline attachments, so if a message contains only inline attachments, this property is false. To verify the existence of inline attachments, parse the body property to look for a src attribute, such as . - ## @param value Value to set for the hasAttachments property. - ## @return a void - ## - def has_attachments=(value) - @has_attachments = value - end - ## - ## Gets the importance property value. The importance property - ## @return a importance - ## - def importance - return @importance - end - ## - ## Sets the importance property value. The importance property - ## @param value Value to set for the importance property. - ## @return a void - ## - def importance=(value) - @importance = value - end - ## - ## Gets the inferenceClassification property value. The inferenceClassification property - ## @return a inference_classification_type - ## - def inference_classification - return @inference_classification - end - ## - ## Sets the inferenceClassification property value. The inferenceClassification property - ## @param value Value to set for the inferenceClassification property. - ## @return a void - ## - def inference_classification=(value) - @inference_classification = value - end - ## - ## Gets the internetMessageHeaders property value. The internetMessageHeaders property - ## @return a internet_message_header - ## - def internet_message_headers - return @internet_message_headers - end - ## - ## Sets the internetMessageHeaders property value. The internetMessageHeaders property - ## @param value Value to set for the internetMessageHeaders property. - ## @return a void - ## - def internet_message_headers=(value) - @internet_message_headers = value - end - ## - ## Gets the internetMessageId property value. The internetMessageId property - ## @return a string - ## - def internet_message_id - return @internet_message_id - end - ## - ## Sets the internetMessageId property value. The internetMessageId property - ## @param value Value to set for the internetMessageId property. - ## @return a void - ## - def internet_message_id=(value) - @internet_message_id = value - end - ## - ## Gets the isDeliveryReceiptRequested property value. The isDeliveryReceiptRequested property - ## @return a boolean - ## - def is_delivery_receipt_requested - return @is_delivery_receipt_requested - end - ## - ## Sets the isDeliveryReceiptRequested property value. The isDeliveryReceiptRequested property - ## @param value Value to set for the isDeliveryReceiptRequested property. - ## @return a void - ## - def is_delivery_receipt_requested=(value) - @is_delivery_receipt_requested = value - end - ## - ## Gets the isDraft property value. The isDraft property - ## @return a boolean - ## - def is_draft - return @is_draft - end - ## - ## Sets the isDraft property value. The isDraft property - ## @param value Value to set for the isDraft property. - ## @return a void - ## - def is_draft=(value) - @is_draft = value - end - ## - ## Gets the isRead property value. The isRead property - ## @return a boolean - ## - def is_read - return @is_read - end - ## - ## Sets the isRead property value. The isRead property - ## @param value Value to set for the isRead property. - ## @return a void - ## - def is_read=(value) - @is_read = value - end - ## - ## Gets the isReadReceiptRequested property value. The isReadReceiptRequested property - ## @return a boolean - ## - def is_read_receipt_requested - return @is_read_receipt_requested - end - ## - ## Sets the isReadReceiptRequested property value. The isReadReceiptRequested property - ## @param value Value to set for the isReadReceiptRequested property. - ## @return a void - ## - def is_read_receipt_requested=(value) - @is_read_receipt_requested = value - end - ## - ## Gets the multiValueExtendedProperties property value. The collection of multi-value extended properties defined for the message. Nullable. - ## @return a multi_value_legacy_extended_property - ## - def multi_value_extended_properties - return @multi_value_extended_properties - end - ## - ## Sets the multiValueExtendedProperties property value. The collection of multi-value extended properties defined for the message. Nullable. - ## @param value Value to set for the multiValueExtendedProperties property. - ## @return a void - ## - def multi_value_extended_properties=(value) - @multi_value_extended_properties = value - end - ## - ## Gets the parentFolderId property value. The parentFolderId property - ## @return a string - ## - def parent_folder_id - return @parent_folder_id - end - ## - ## Sets the parentFolderId property value. The parentFolderId property - ## @param value Value to set for the parentFolderId property. - ## @return a void - ## - def parent_folder_id=(value) - @parent_folder_id = value - end - ## - ## Gets the receivedDateTime property value. The receivedDateTime property - ## @return a date_time - ## - def received_date_time - return @received_date_time - end - ## - ## Sets the receivedDateTime property value. The receivedDateTime property - ## @param value Value to set for the receivedDateTime property. - ## @return a void - ## - def received_date_time=(value) - @received_date_time = value - end - ## - ## Gets the replyTo property value. The replyTo property - ## @return a recipient - ## - def reply_to - return @reply_to - end - ## - ## Sets the replyTo property value. The replyTo property - ## @param value Value to set for the replyTo property. - ## @return a void - ## - def reply_to=(value) - @reply_to = value - end - ## - ## Gets the sender property value. The sender property - ## @return a recipient - ## - def sender - return @sender - end - ## - ## Sets the sender property value. The sender property - ## @param value Value to set for the sender property. - ## @return a void - ## - def sender=(value) - @sender = value - end - ## - ## Gets the sentDateTime property value. The sentDateTime property - ## @return a date_time - ## - def sent_date_time - return @sent_date_time - end - ## - ## Sets the sentDateTime property value. The sentDateTime property - ## @param value Value to set for the sentDateTime property. - ## @return a void - ## - def sent_date_time=(value) - @sent_date_time = value - end - ## - ## Serializes information the current object - ## @param writer Serialization writer to use to serialize this model - ## @return a void - ## - def serialize(writer) - raise StandardError, 'writer cannot be null' if writer.nil? - super - writer.write_guid_value("guidId", @guid_id) - writer.write_collection_of_object_values("attachments", @attachments) - writer.write_collection_of_object_values("bccRecipients", @bcc_recipients) - writer.write_object_value("body", @body) - writer.write_string_value("bodyPreview", @body_preview) - writer.write_collection_of_object_values("ccRecipients", @cc_recipients) - writer.write_string_value("conversationId", @conversation_id) - # writer.write_object_value("conversationIndex", @conversation_index) byte array is not supported yet - writer.write_collection_of_object_values("extensions", @extensions) - writer.write_object_value("flag", @flag) - writer.write_object_value("from", @from) - writer.write_boolean_value("hasAttachments", @has_attachments) - writer.write_enum_value("importance", @importance) - writer.write_enum_value("inferenceClassification", @inference_classification) - writer.write_collection_of_object_values("internetMessageHeaders", @internet_message_headers) - writer.write_string_value("internetMessageId", @internet_message_id) - writer.write_boolean_value("isDeliveryReceiptRequested", @is_delivery_receipt_requested) - writer.write_boolean_value("isDraft", @is_draft) - writer.write_boolean_value("isRead", @is_read) - writer.write_boolean_value("isReadReceiptRequested", @is_read_receipt_requested) - writer.write_collection_of_object_values("multiValueExtendedProperties", @multi_value_extended_properties) - writer.write_string_value("parentFolderId", @parent_folder_id) - writer.write_date_time_value("receivedDateTime", @received_date_time) - writer.write_collection_of_object_values("replyTo", @reply_to) - writer.write_object_value("sender", @sender) - writer.write_date_time_value("sentDateTime", @sent_date_time) - writer.write_collection_of_object_values("singleValueExtendedProperties", @single_value_extended_properties) - writer.write_string_value("subject", @subject) - writer.write_collection_of_object_values("toRecipients", @to_recipients) - writer.write_object_value("uniqueBody", @unique_body) - writer.write_string_value("webLink", @web_link) - end - ## - ## Gets the singleValueExtendedProperties property value. The collection of single-value extended properties defined for the message. Nullable. - ## @return a single_value_legacy_extended_property - ## - def single_value_extended_properties - return @single_value_extended_properties - end - ## - ## Sets the singleValueExtendedProperties property value. The collection of single-value extended properties defined for the message. Nullable. - ## @param value Value to set for the singleValueExtendedProperties property. - ## @return a void - ## - def single_value_extended_properties=(value) - @single_value_extended_properties = value - end - ## - ## Gets the subject property value. The subject property - ## @return a string - ## - def subject - return @subject - end - ## - ## Sets the subject property value. The subject property - ## @param value Value to set for the subject property. - ## @return a void - ## - def subject=(value) - @subject = value - end - ## - ## Gets the toRecipients property value. The toRecipients property - ## @return a recipient - ## - def to_recipients - return @to_recipients - end - ## - ## Sets the toRecipients property value. The toRecipients property - ## @param value Value to set for the toRecipients property. - ## @return a void - ## - def to_recipients=(value) - @to_recipients = value - end - ## - ## Gets the uniqueBody property value. The uniqueBody property - ## @return a item_body - ## - def unique_body - return @unique_body - end - ## - ## Sets the uniqueBody property value. The uniqueBody property - ## @param value Value to set for the uniqueBody property. - ## @return a void - ## - def unique_body=(value) - @unique_body = value - end - ## - ## Gets the webLink property value. The webLink property - ## @return a string - ## - def web_link - return @web_link - end - ## - ## Sets the webLink property value. The webLink property - ## @param value Value to set for the webLink property. - ## @return a void - ## - def web_link=(value) - @web_link = value - end + class Message < Files::OutlookItem + include MicrosoftKiotaAbstractions::Parsable + + attr_accessor :guid_id + + ## + # The fileAttachment and itemAttachment attachments for the message. + ## + # The Bcc: recipients for the message. + ## + # The body property + ## + # The first 255 characters of the message body. It is in text format. + ## + # The Cc: recipients for the message. + ## + # The ID of the conversation the email belongs to. + ## + # Indicates the position of the message within the conversation. + ## + # The collection of open extensions defined for the message. Nullable. + ## + # The flag property + ## + # The from property + ## + # Indicates whether the message has attachments. This property doesn't include inline attachments, so if a message contains only inline attachments, this property is false. To verify the existence of inline attachments, parse the body property to look for a src attribute, such as . + ## + # The importance property + ## + # The inferenceClassification property + ## + # The internetMessageHeaders property + ## + # The internetMessageId property + ## + # The isDeliveryReceiptRequested property + ## + # The isDraft property + ## + # The isRead property + ## + # The isReadReceiptRequested property + ## + # The collection of multi-value extended properties defined for the message. Nullable. + ## + # The parentFolderId property + ## + # The receivedDateTime property + ## + # The replyTo property + ## + # The sender property + ## + # The sentDateTime property + ## + # The collection of single-value extended properties defined for the message. Nullable. + ## + # The subject property + ## + # The toRecipients property + ## + # The uniqueBody property + ## + # The webLink property + ## + ## Gets the attachments property value. The fileAttachment and itemAttachment attachments for the message. + ## @return a attachment + ## + attr_accessor :attachments + + ## + ## Sets the attachments property value. The fileAttachment and itemAttachment attachments for the message. + ## @param value Value to set for the attachments property. + ## @return a void + ## + + ## + ## Gets the bccRecipients property value. The Bcc: recipients for the message. + ## @return a recipient + ## + attr_accessor :bcc_recipients + + ## + ## Sets the bccRecipients property value. The Bcc: recipients for the message. + ## @param value Value to set for the bccRecipients property. + ## @return a void + ## + + ## + ## Gets the body property value. The body property + ## @return a item_body + ## + attr_accessor :body + + ## + ## Sets the body property value. The body property + ## @param value Value to set for the body property. + ## @return a void + ## + + ## + ## Gets the bodyPreview property value. The first 255 characters of the message body. It is in text format. + ## @return a string + ## + attr_accessor :body_preview + + ## + ## Sets the bodyPreview property value. The first 255 characters of the message body. It is in text format. + ## @param value Value to set for the bodyPreview property. + ## @return a void + ## + + ## + ## Gets the ccRecipients property value. The Cc: recipients for the message. + ## @return a recipient + ## + attr_accessor :cc_recipients + + ## + ## Sets the ccRecipients property value. The Cc: recipients for the message. + ## @param value Value to set for the ccRecipients property. + ## @return a void + ## + + ## + ## Instantiates a new message and sets the default values. + ## @return a void + ## + + ## + ## Gets the conversationId property value. The ID of the conversation the email belongs to. + ## @return a string + ## + attr_accessor :conversation_id + + ## + ## Sets the conversationId property value. The ID of the conversation the email belongs to. + ## @param value Value to set for the conversationId property. + ## @return a void + ## + + ## + ## Gets the conversationIndex property value. Indicates the position of the message within the conversation. + ## @return a binary + ## + attr_accessor :conversation_index + + ## + ## Sets the conversationIndex property value. Indicates the position of the message within the conversation. + ## @param value Value to set for the conversationIndex property. + ## @return a void + ## + + ## + ## Creates a new instance of the appropriate class based on discriminator value + ## @param parseNode The parse node to use to read the discriminator value and create the object + ## @return a message + ## + def self.create_from_discriminator_value(parse_node) + raise StandardError, 'parse_node cannot be null' if parse_node.nil? + + Message.new + end + + ## + ## Gets the extensions property value. The collection of open extensions defined for the message. Nullable. + ## @return a extension + ## + attr_accessor :extensions + + ## + ## Sets the extensions property value. The collection of open extensions defined for the message. Nullable. + ## @param value Value to set for the extensions property. + ## @return a void + ## + + ## + ## Gets the flag property value. The flag property + ## @return a followup_flag + ## + attr_accessor :flag + + ## + ## Sets the flag property value. The flag property + ## @param value Value to set for the flag property. + ## @return a void + ## + + ## + ## Gets the from property value. The from property + ## @return a recipient + ## + attr_accessor :from + + ## + ## Sets the from property value. The from property + ## @param value Value to set for the from property. + ## @return a void + ## + + ## + ## The deserialization information for the current model + ## @return a i_dictionary + ## + def get_field_deserializers + super.merge({ + 'guidId' => ->(n) { @guid_id = n.get_guid_value }, + 'bccRecipients' => lambda { |n| + @bcc_recipients = n.get_collection_of_object_values(lambda { |pn| + Files::Recipient.create_from_discriminator_value(pn) + }) + }, + 'body' => lambda { |n| + @body = n.get_object_value(lambda { |pn| + Files::ItemBody.create_from_discriminator_value(pn) + }) + }, + 'bodyPreview' => ->(n) { @body_preview = n.get_string_value }, + 'ccRecipients' => lambda { |n| + @cc_recipients = n.get_collection_of_object_values(lambda { |pn| + Files::Recipient.create_from_discriminator_value(pn) + }) + }, + 'conversationId' => ->(n) { @conversation_id = n.get_string_value }, + 'conversationIndex' => ->(n) { @conversation_index = n.get_string_value }, + 'from' => lambda { |n| + @from = n.get_object_value(lambda { |pn| + Files::Recipient.create_from_discriminator_value(pn) + }) + }, + 'hasAttachments' => ->(n) { @has_attachments = n.get_boolean_value }, + 'internetMessageId' => ->(n) { @internet_message_id = n.get_string_value }, + 'isDeliveryReceiptRequested' => lambda { |n| + @is_delivery_receipt_requested = n.get_boolean_value + }, + 'isDraft' => ->(n) { @is_draft = n.get_boolean_value }, + 'isRead' => ->(n) { @is_read = n.get_boolean_value }, + 'isReadReceiptRequested' => lambda { |n| + @is_read_receipt_requested = n.get_boolean_value + }, + 'parentFolderId' => ->(n) { @parent_folder_id = n.get_string_value }, + 'receivedDateTime' => ->(n) { @received_date_time = n.get_date_time_value }, + 'replyTo' => lambda { |n| + @reply_to = n.get_collection_of_object_values(lambda { |pn| + Files::Recipient.create_from_discriminator_value(pn) + }) + }, + 'sender' => lambda { |n| + @sender = n.get_object_value(lambda { |pn| + Files::Recipient.create_from_discriminator_value(pn) + }) + }, + 'sentDateTime' => ->(n) { @sent_date_time = n.get_date_time_value }, + 'subject' => ->(n) { @subject = n.get_string_value }, + 'toRecipients' => lambda { |n| + @to_recipients = n.get_collection_of_object_values(lambda { |pn| + Files::Recipient.create_from_discriminator_value(pn) + }) + }, + 'uniqueBody' => lambda { |n| + @unique_body = n.get_object_value(lambda { |pn| + Files::ItemBody.create_from_discriminator_value(pn) + }) + }, + 'webLink' => ->(n) { @web_link = n.get_string_value } + }) + end + + ## + ## Gets the hasAttachments property value. Indicates whether the message has attachments. This property doesn't include inline attachments, so if a message contains only inline attachments, this property is false. To verify the existence of inline attachments, parse the body property to look for a src attribute, such as . + ## @return a boolean + ## + attr_accessor :has_attachments + + ## + ## Sets the hasAttachments property value. Indicates whether the message has attachments. This property doesn't include inline attachments, so if a message contains only inline attachments, this property is false. To verify the existence of inline attachments, parse the body property to look for a src attribute, such as . + ## @param value Value to set for the hasAttachments property. + ## @return a void + ## + + ## + ## Gets the importance property value. The importance property + ## @return a importance + ## + attr_accessor :importance + + ## + ## Sets the importance property value. The importance property + ## @param value Value to set for the importance property. + ## @return a void + ## + + ## + ## Gets the inferenceClassification property value. The inferenceClassification property + ## @return a inference_classification_type + ## + attr_accessor :inference_classification + + ## + ## Sets the inferenceClassification property value. The inferenceClassification property + ## @param value Value to set for the inferenceClassification property. + ## @return a void + ## + + ## + ## Gets the internetMessageHeaders property value. The internetMessageHeaders property + ## @return a internet_message_header + ## + attr_accessor :internet_message_headers + + ## + ## Sets the internetMessageHeaders property value. The internetMessageHeaders property + ## @param value Value to set for the internetMessageHeaders property. + ## @return a void + ## + + ## + ## Gets the internetMessageId property value. The internetMessageId property + ## @return a string + ## + attr_accessor :internet_message_id + + ## + ## Sets the internetMessageId property value. The internetMessageId property + ## @param value Value to set for the internetMessageId property. + ## @return a void + ## + + ## + ## Gets the isDeliveryReceiptRequested property value. The isDeliveryReceiptRequested property + ## @return a boolean + ## + attr_accessor :is_delivery_receipt_requested + + ## + ## Sets the isDeliveryReceiptRequested property value. The isDeliveryReceiptRequested property + ## @param value Value to set for the isDeliveryReceiptRequested property. + ## @return a void + ## + + ## + ## Gets the isDraft property value. The isDraft property + ## @return a boolean + ## + attr_accessor :is_draft + + ## + ## Sets the isDraft property value. The isDraft property + ## @param value Value to set for the isDraft property. + ## @return a void + ## + + ## + ## Gets the isRead property value. The isRead property + ## @return a boolean + ## + attr_accessor :is_read + + ## + ## Sets the isRead property value. The isRead property + ## @param value Value to set for the isRead property. + ## @return a void + ## + + ## + ## Gets the isReadReceiptRequested property value. The isReadReceiptRequested property + ## @return a boolean + ## + attr_accessor :is_read_receipt_requested + + ## + ## Sets the isReadReceiptRequested property value. The isReadReceiptRequested property + ## @param value Value to set for the isReadReceiptRequested property. + ## @return a void + ## + + ## + ## Gets the multiValueExtendedProperties property value. The collection of multi-value extended properties defined for the message. Nullable. + ## @return a multi_value_legacy_extended_property + ## + attr_accessor :multi_value_extended_properties + + ## + ## Sets the multiValueExtendedProperties property value. The collection of multi-value extended properties defined for the message. Nullable. + ## @param value Value to set for the multiValueExtendedProperties property. + ## @return a void + ## + + ## + ## Gets the parentFolderId property value. The parentFolderId property + ## @return a string + ## + attr_accessor :parent_folder_id + + ## + ## Sets the parentFolderId property value. The parentFolderId property + ## @param value Value to set for the parentFolderId property. + ## @return a void + ## + + ## + ## Gets the receivedDateTime property value. The receivedDateTime property + ## @return a date_time + ## + attr_accessor :received_date_time + + ## + ## Sets the receivedDateTime property value. The receivedDateTime property + ## @param value Value to set for the receivedDateTime property. + ## @return a void + ## + + ## + ## Gets the replyTo property value. The replyTo property + ## @return a recipient + ## + attr_accessor :reply_to + + ## + ## Sets the replyTo property value. The replyTo property + ## @param value Value to set for the replyTo property. + ## @return a void + ## + + ## + ## Gets the sender property value. The sender property + ## @return a recipient + ## + attr_accessor :sender + + ## + ## Sets the sender property value. The sender property + ## @param value Value to set for the sender property. + ## @return a void + ## + + ## + ## Gets the sentDateTime property value. The sentDateTime property + ## @return a date_time + ## + attr_accessor :sent_date_time + + ## + ## Sets the sentDateTime property value. The sentDateTime property + ## @param value Value to set for the sentDateTime property. + ## @return a void + ## + + ## + ## Serializes information the current object + ## @param writer Serialization writer to use to serialize this model + ## @return a void + ## + def serialize(writer) + raise StandardError, 'writer cannot be null' if writer.nil? + + super + writer.write_guid_value('guidId', @guid_id) + writer.write_collection_of_object_values('attachments', @attachments) + writer.write_collection_of_object_values('bccRecipients', @bcc_recipients) + writer.write_object_value('body', @body) + writer.write_string_value('bodyPreview', @body_preview) + writer.write_collection_of_object_values('ccRecipients', @cc_recipients) + writer.write_string_value('conversationId', @conversation_id) + # writer.write_object_value("conversationIndex", @conversation_index) byte array is not supported yet + writer.write_collection_of_object_values('extensions', @extensions) + writer.write_object_value('flag', @flag) + writer.write_object_value('from', @from) + writer.write_boolean_value('hasAttachments', @has_attachments) + writer.write_enum_value('importance', @importance) + writer.write_enum_value('inferenceClassification', @inference_classification) + writer.write_collection_of_object_values('internetMessageHeaders', @internet_message_headers) + writer.write_string_value('internetMessageId', @internet_message_id) + writer.write_boolean_value('isDeliveryReceiptRequested', @is_delivery_receipt_requested) + writer.write_boolean_value('isDraft', @is_draft) + writer.write_boolean_value('isRead', @is_read) + writer.write_boolean_value('isReadReceiptRequested', @is_read_receipt_requested) + writer.write_collection_of_object_values('multiValueExtendedProperties', @multi_value_extended_properties) + writer.write_string_value('parentFolderId', @parent_folder_id) + writer.write_date_time_value('receivedDateTime', @received_date_time) + writer.write_collection_of_object_values('replyTo', @reply_to) + writer.write_object_value('sender', @sender) + writer.write_date_time_value('sentDateTime', @sent_date_time) + writer.write_collection_of_object_values('singleValueExtendedProperties', @single_value_extended_properties) + writer.write_string_value('subject', @subject) + writer.write_collection_of_object_values('toRecipients', @to_recipients) + writer.write_object_value('uniqueBody', @unique_body) + writer.write_string_value('webLink', @web_link) end + + ## + ## Gets the singleValueExtendedProperties property value. The collection of single-value extended properties defined for the message. Nullable. + ## @return a single_value_legacy_extended_property + ## + attr_accessor :single_value_extended_properties + + ## + ## Sets the singleValueExtendedProperties property value. The collection of single-value extended properties defined for the message. Nullable. + ## @param value Value to set for the singleValueExtendedProperties property. + ## @return a void + ## + + ## + ## Gets the subject property value. The subject property + ## @return a string + ## + attr_accessor :subject + + ## + ## Sets the subject property value. The subject property + ## @param value Value to set for the subject property. + ## @return a void + ## + + ## + ## Gets the toRecipients property value. The toRecipients property + ## @return a recipient + ## + attr_accessor :to_recipients + + ## + ## Sets the toRecipients property value. The toRecipients property + ## @param value Value to set for the toRecipients property. + ## @return a void + ## + + ## + ## Gets the uniqueBody property value. The uniqueBody property + ## @return a item_body + ## + attr_accessor :unique_body + + ## + ## Sets the uniqueBody property value. The uniqueBody property + ## @param value Value to set for the uniqueBody property. + ## @return a void + ## + + ## + ## Gets the webLink property value. The webLink property + ## @return a string + ## + attr_accessor :web_link + + ## + ## Sets the webLink property value. The webLink property + ## @param value Value to set for the webLink property. + ## @return a void + ## + end end diff --git a/components/serialization/json/spec/files/messages_response.rb b/components/serialization/json/spec/files/messages_response.rb index f90f0af..50e6815 100644 --- a/components/serialization/json/spec/files/messages_response.rb +++ b/components/serialization/json/spec/files/messages_response.rb @@ -1,98 +1,99 @@ +# frozen_string_literal: true + require 'microsoft_kiota_abstractions' module Files - class MessageCollectionResponse - include MicrosoftKiotaAbstractions::AdditionalDataHolder, MicrosoftKiotaAbstractions::Parsable - ## - # Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. - @additional_data - ## - # The OdataNextLink property - @odata_next_link - ## - # The value property - @value - ## - ## Gets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. - ## @return a i_dictionary - ## - def additional_data - return @additional_data - end - ## - ## Sets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. - ## @param value Value to set for the AdditionalData property. - ## @return a void - ## - def additional_data=(value) - @additional_data = value - end - ## - ## Instantiates a new MessageCollectionResponse and sets the default values. - ## @return a void - ## - def initialize() - @additional_data = Hash.new - end - ## - ## Creates a new instance of the appropriate class based on discriminator value - ## @param parseNode The parse node to use to read the discriminator value and create the object - ## @return a message_collection_response - ## - def self.create_from_discriminator_value(parse_node) - raise StandardError, 'parse_node cannot be null' if parse_node.nil? - return MessageCollectionResponse.new - end - ## - ## The deserialization information for the current model - ## @return a i_dictionary - ## - def get_field_deserializers() - return { - "@odata.nextLink" => lambda {|n| @odata_next_link = n.get_string_value() }, - "value" => lambda {|n| @value = n.get_collection_of_object_values(lambda {|pn| Files::Message.create_from_discriminator_value(pn) }) }, - } - end - ## - ## Gets the @odata.nextLink property value. The OdataNextLink property - ## @return a string - ## - def odata_next_link - return @odata_next_link - end - ## - ## Sets the @odata.nextLink property value. The OdataNextLink property - ## @param value Value to set for the OdataNextLink property. - ## @return a void - ## - def odata_next_link=(value) - @odata_next_link = value - end - ## - ## Serializes information the current object - ## @param writer Serialization writer to use to serialize this model - ## @return a void - ## - def serialize(writer) - raise StandardError, 'writer cannot be null' if writer.nil? - writer.write_string_value("@odata.nextLink", @odata_next_link) - writer.write_collection_of_object_values("value", @value) - writer.write_additional_data(@additional_data) - end - ## - ## Gets the value property value. The value property - ## @return a message - ## - def value - return @value - end - ## - ## Sets the value property value. The value property - ## @param value Value to set for the value property. - ## @return a void - ## - def value=(value) - @value = value - end + class MessageCollectionResponse + include MicrosoftKiotaAbstractions::Parsable + include MicrosoftKiotaAbstractions::AdditionalDataHolder + + ## + # Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## + # The OdataNextLink property + ## + # The value property + ## + ## Gets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## @return a i_dictionary + ## + attr_accessor :additional_data + + ## + ## Sets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## @param value Value to set for the AdditionalData property. + ## @return a void + ## + + ## + ## Instantiates a new MessageCollectionResponse and sets the default values. + ## @return a void + ## + def initialize + @additional_data = {} + end + + ## + ## Creates a new instance of the appropriate class based on discriminator value + ## @param parseNode The parse node to use to read the discriminator value and create the object + ## @return a message_collection_response + ## + def self.create_from_discriminator_value(parse_node) + raise StandardError, 'parse_node cannot be null' if parse_node.nil? + + MessageCollectionResponse.new + end + + ## + ## The deserialization information for the current model + ## @return a i_dictionary + ## + def get_field_deserializers + { + '@odata.nextLink' => ->(n) { @odata_next_link = n.get_string_value }, + 'value' => lambda { |n| + @value = n.get_collection_of_object_values(lambda { |pn| + Files::Message.create_from_discriminator_value(pn) + }) + } + } + end + + ## + ## Gets the @odata.nextLink property value. The OdataNextLink property + ## @return a string + ## + attr_accessor :odata_next_link + + ## + ## Sets the @odata.nextLink property value. The OdataNextLink property + ## @param value Value to set for the OdataNextLink property. + ## @return a void + ## + + ## + ## Serializes information the current object + ## @param writer Serialization writer to use to serialize this model + ## @return a void + ## + def serialize(writer) + raise StandardError, 'writer cannot be null' if writer.nil? + + writer.write_string_value('@odata.nextLink', @odata_next_link) + writer.write_collection_of_object_values('value', @value) + writer.write_additional_data(@additional_data) end + + ## + ## Gets the value property value. The value property + ## @return a message + ## + attr_accessor :value + + ## + ## Sets the value property value. The value property + ## @param value Value to set for the value property. + ## @return a void + ## + end end diff --git a/components/serialization/json/spec/files/outlook_item.rb b/components/serialization/json/spec/files/outlook_item.rb index 1ee373b..088daee 100644 --- a/components/serialization/json/spec/files/outlook_item.rb +++ b/components/serialization/json/spec/files/outlook_item.rb @@ -1,122 +1,113 @@ +# frozen_string_literal: true + require 'date' require 'microsoft_kiota_abstractions' -require_relative './entity' +require_relative 'entity' module Files - class OutlookItem < Files::Entity - include MicrosoftKiotaAbstractions::Parsable - ## - # The categories associated with the item - @categories - ## - # Identifies the version of the item. Every time the item is changed, changeKey changes as well. This allows Exchange to apply changes to the correct version of the object. Read-only. - @change_key - ## - # The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z - @created_date_time - ## - # The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z - @last_modified_date_time - ## - ## Gets the categories property value. The categories associated with the item - ## @return a string - ## - def categories - return @categories - end - ## - ## Sets the categories property value. The categories associated with the item - ## @param value Value to set for the categories property. - ## @return a void - ## - def categories=(value) - @categories = value - end - ## - ## Gets the changeKey property value. Identifies the version of the item. Every time the item is changed, changeKey changes as well. This allows Exchange to apply changes to the correct version of the object. Read-only. - ## @return a string - ## - def change_key - return @change_key - end - ## - ## Sets the changeKey property value. Identifies the version of the item. Every time the item is changed, changeKey changes as well. This allows Exchange to apply changes to the correct version of the object. Read-only. - ## @param value Value to set for the changeKey property. - ## @return a void - ## - def change_key=(value) - @change_key = value - end - ## - ## Instantiates a new outlookItem and sets the default values. - ## @return a void - ## - def initialize() - super - end - ## - ## Gets the createdDateTime property value. The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z - ## @return a date_time - ## - def created_date_time - return @created_date_time - end - ## - ## Sets the createdDateTime property value. The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z - ## @param value Value to set for the createdDateTime property. - ## @return a void - ## - def created_date_time=(value) - @created_date_time = value - end - ## - ## Creates a new instance of the appropriate class based on discriminator value - ## @param parseNode The parse node to use to read the discriminator value and create the object - ## @return a outlook_item - ## - def self.create_from_discriminator_value(parse_node) - raise StandardError, 'parse_node cannot be null' if parse_node.nil? - return OutlookItem.new - end - ## - ## The deserialization information for the current model - ## @return a i_dictionary - ## - def get_field_deserializers() - return super.merge({ - "categories" => lambda {|n| @categories = n.get_collection_of_primitive_values(String) }, - "changeKey" => lambda {|n| @change_key = n.get_string_value() }, - "createdDateTime" => lambda {|n| @created_date_time = n.get_date_time_value() }, - "lastModifiedDateTime" => lambda {|n| @last_modified_date_time = n.get_date_time_value() }, - }) - end - ## - ## Gets the lastModifiedDateTime property value. The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z - ## @return a date_time - ## - def last_modified_date_time - return @last_modified_date_time - end - ## - ## Sets the lastModifiedDateTime property value. The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z - ## @param value Value to set for the lastModifiedDateTime property. - ## @return a void - ## - def last_modified_date_time=(value) - @last_modified_date_time = value - end - ## - ## Serializes information the current object - ## @param writer Serialization writer to use to serialize this model - ## @return a void - ## - def serialize(writer) - raise StandardError, 'writer cannot be null' if writer.nil? - super - writer.write_collection_of_primitive_values("categories", @categories) - writer.write_string_value("changeKey", @change_key) - writer.write_date_time_value("createdDateTime", @created_date_time) - writer.write_date_time_value("lastModifiedDateTime", @last_modified_date_time) - end + class OutlookItem < Files::Entity + include MicrosoftKiotaAbstractions::Parsable + + ## + # The categories associated with the item + ## + # Identifies the version of the item. Every time the item is changed, changeKey changes as well. This allows Exchange to apply changes to the correct version of the object. Read-only. + ## + # The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z + ## + # The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z + ## + ## Gets the categories property value. The categories associated with the item + ## @return a string + ## + attr_accessor :categories + + ## + ## Sets the categories property value. The categories associated with the item + ## @param value Value to set for the categories property. + ## @return a void + ## + + ## + ## Gets the changeKey property value. Identifies the version of the item. Every time the item is changed, changeKey changes as well. This allows Exchange to apply changes to the correct version of the object. Read-only. + ## @return a string + ## + attr_accessor :change_key + + ## + ## Sets the changeKey property value. Identifies the version of the item. Every time the item is changed, changeKey changes as well. This allows Exchange to apply changes to the correct version of the object. Read-only. + ## @param value Value to set for the changeKey property. + ## @return a void + ## + + ## + ## Instantiates a new outlookItem and sets the default values. + ## @return a void + ## + + ## + ## Gets the createdDateTime property value. The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z + ## @return a date_time + ## + attr_accessor :created_date_time + + ## + ## Sets the createdDateTime property value. The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z + ## @param value Value to set for the createdDateTime property. + ## @return a void + ## + + ## + ## Creates a new instance of the appropriate class based on discriminator value + ## @param parseNode The parse node to use to read the discriminator value and create the object + ## @return a outlook_item + ## + def self.create_from_discriminator_value(parse_node) + raise StandardError, 'parse_node cannot be null' if parse_node.nil? + + OutlookItem.new + end + + ## + ## The deserialization information for the current model + ## @return a i_dictionary + ## + def get_field_deserializers + super.merge({ + 'categories' => lambda { |n| + @categories = n.get_collection_of_primitive_values(String) + }, + 'changeKey' => ->(n) { @change_key = n.get_string_value }, + 'createdDateTime' => ->(n) { @created_date_time = n.get_date_time_value }, + 'lastModifiedDateTime' => ->(n) { @last_modified_date_time = n.get_date_time_value } + }) + end + + ## + ## Gets the lastModifiedDateTime property value. The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z + ## @return a date_time + ## + attr_accessor :last_modified_date_time + + ## + ## Sets the lastModifiedDateTime property value. The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z + ## @param value Value to set for the lastModifiedDateTime property. + ## @return a void + ## + + ## + ## Serializes information the current object + ## @param writer Serialization writer to use to serialize this model + ## @return a void + ## + def serialize(writer) + raise StandardError, 'writer cannot be null' if writer.nil? + + super + writer.write_collection_of_primitive_values('categories', @categories) + writer.write_string_value('changeKey', @change_key) + writer.write_date_time_value('createdDateTime', @created_date_time) + writer.write_date_time_value('lastModifiedDateTime', @last_modified_date_time) end + end end diff --git a/components/serialization/json/spec/files/recipient.rb b/components/serialization/json/spec/files/recipient.rb index cbfb18b..506bbfc 100644 --- a/components/serialization/json/spec/files/recipient.rb +++ b/components/serialization/json/spec/files/recipient.rb @@ -1,78 +1,83 @@ +# frozen_string_literal: true + require 'microsoft_kiota_abstractions' module Files - class Recipient - include MicrosoftKiotaAbstractions::AdditionalDataHolder, MicrosoftKiotaAbstractions::Parsable - ## - # Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. - @additional_data - ## - # The emailAddress property - @email_address - ## - ## Gets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. - ## @return a i_dictionary - ## - def additional_data - return @additional_data - end - ## - ## Sets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. - ## @param value Value to set for the AdditionalData property. - ## @return a void - ## - def additional_data=(value) - @additional_data = value - end - ## - ## Instantiates a new recipient and sets the default values. - ## @return a void - ## - def initialize() - @additional_data = Hash.new - end - ## - ## Creates a new instance of the appropriate class based on discriminator value - ## @param parseNode The parse node to use to read the discriminator value and create the object - ## @return a recipient - ## - def self.create_from_discriminator_value(parse_node) - raise StandardError, 'parse_node cannot be null' if parse_node.nil? - return Recipient.new - end - ## - ## Gets the emailAddress property value. The emailAddress property - ## @return a email_address - ## - def email_address - return @email_address - end - ## - ## Sets the emailAddress property value. The emailAddress property - ## @param value Value to set for the emailAddress property. - ## @return a void - ## - def email_address=(value) - @email_address = value - end - ## - ## The deserialization information for the current model - ## @return a i_dictionary - ## - def get_field_deserializers() - return { - "emailAddress" => lambda {|n| @email_address = n.get_object_value(lambda {|pn| Files::EmailAddress.create_from_discriminator_value(pn) }) }, - } - end - ## - ## Serializes information the current object - ## @param writer Serialization writer to use to serialize this model - ## @return a void - ## - def serialize(writer) - raise StandardError, 'writer cannot be null' if writer.nil? - writer.write_object_value("emailAddress", @email_address) - writer.write_additional_data(@additional_data) - end + class Recipient + include MicrosoftKiotaAbstractions::Parsable + include MicrosoftKiotaAbstractions::AdditionalDataHolder + + ## + # Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## + # The emailAddress property + ## + ## Gets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## @return a i_dictionary + ## + attr_accessor :additional_data + + ## + ## Sets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + ## @param value Value to set for the AdditionalData property. + ## @return a void + ## + + ## + ## Instantiates a new recipient and sets the default values. + ## @return a void + ## + def initialize + @additional_data = {} + end + + ## + ## Creates a new instance of the appropriate class based on discriminator value + ## @param parseNode The parse node to use to read the discriminator value and create the object + ## @return a recipient + ## + def self.create_from_discriminator_value(parse_node) + raise StandardError, 'parse_node cannot be null' if parse_node.nil? + + Recipient.new + end + + ## + ## Gets the emailAddress property value. The emailAddress property + ## @return a email_address + ## + attr_accessor :email_address + + ## + ## Sets the emailAddress property value. The emailAddress property + ## @param value Value to set for the emailAddress property. + ## @return a void + ## + + ## + ## The deserialization information for the current model + ## @return a i_dictionary + ## + def get_field_deserializers + { + 'emailAddress' => lambda { |n| + @email_address = n.get_object_value(lambda { |pn| + Files::EmailAddress.create_from_discriminator_value(pn) + }) + } + } + end + + ## + ## Serializes information the current object + ## @param writer Serialization writer to use to serialize this model + ## @return a void + ## + def serialize(writer) + raise StandardError, 'writer cannot be null' if writer.nil? + + writer.write_object_value('emailAddress', @email_address) + writer.write_additional_data(@additional_data) end + end end diff --git a/components/serialization/json/spec/json_serialization_writer_composed_type_spec.rb b/components/serialization/json/spec/json_serialization_writer_composed_type_spec.rb index 9bffd43..b6b5bee 100644 --- a/components/serialization/json/spec/json_serialization_writer_composed_type_spec.rb +++ b/components/serialization/json/spec/json_serialization_writer_composed_type_spec.rb @@ -11,8 +11,8 @@ class SimpleParsable def get_field_deserializers { - 'name' => lambda { |n| @name = n.get_string_value }, - 'age' => lambda { |n| @age = n.get_number_value } + 'name' => ->(n) { @name = n.get_string_value }, + 'age' => ->(n) { @age = n.get_number_value } } end @@ -32,7 +32,7 @@ class AnotherParsable attr_accessor :email def get_field_deserializers - { 'email' => lambda { |n| @email = n.get_string_value } } + { 'email' => ->(n) { @email = n.get_string_value } } end def serialize(writer) @@ -53,6 +53,7 @@ class UnionTypeWrapper def get_field_deserializers return @simple.get_field_deserializers if @simple return @another.get_field_deserializers if @another + {} end @@ -227,9 +228,9 @@ def self.create_from_discriminator_value(_parse_node) writer.write_collection_of_object_values('people', [obj1, obj2]) expect(writer.writer['people']).to eq([ - { 'name' => 'Alice', 'age' => 30 }, - { 'name' => 'Bob', 'age' => 25 } - ]) + { 'name' => 'Alice', 'age' => 30 }, + { 'name' => 'Bob', 'age' => 25 } + ]) end it 'serializes into self when key is nil' do diff --git a/components/serialization/json/spec/microsoft_kiota_serialization_json_spec.rb b/components/serialization/json/spec/microsoft_kiota_serialization_json_spec.rb index 40bd11e..1b852ff 100644 --- a/components/serialization/json/spec/microsoft_kiota_serialization_json_spec.rb +++ b/components/serialization/json/spec/microsoft_kiota_serialization_json_spec.rb @@ -1,72 +1,78 @@ # frozen_string_literal: true require_relative 'spec_helper' -require_relative './files/files.rb' +require_relative 'files/files' require 'microsoft_kiota_abstractions' require 'json' RSpec.describe MicrosoftKiotaSerializationJson do - it "has a version number" do + it 'has a version number' do expect(MicrosoftKiotaSerializationJson::VERSION).not_to be nil end - it "can build jsonParseNode" do + it 'can build jsonParseNode' do json_parse_node = MicrosoftKiotaSerializationJson::JsonParseNode.new(JSON.parse('{"value": [{"hasAttachments": false}] }')) expect(json_parse_node).not_to be nil - expect(json_parse_node.get_string_value().gsub(/\s+/, "")).to eq("{\"value\"=>[{\"hasAttachments\"=>false}]}") + expect(json_parse_node.get_string_value.gsub(/\s+/, '')).to eq('{"value"=>[{"hasAttachments"=>false}]}') end - it "can deserialize payload" do + it 'can deserialize payload' do file = File.open("#{File.dirname(__FILE__)}/sample.json") data = file.read file.close - message_response = MicrosoftKiotaSerializationJson::JsonParseNodeFactory.new.get_parse_node("application/json", data) - object_value = message_response.get_object_value(lambda {|pn| Files::MessageCollectionResponse.create_from_discriminator_value(pn)}) + message_response = MicrosoftKiotaSerializationJson::JsonParseNodeFactory.new.get_parse_node('application/json', + data) + object_value = message_response.get_object_value(lambda { |pn| + Files::MessageCollectionResponse.create_from_discriminator_value(pn) + }) ## Object Value tests - expect(object_value.instance_of? Files::MessageCollectionResponse).to eq(true) - expect(object_value.value[0].instance_of? Files::Message).to eq(true) - expect(object_value.value[0].body.instance_of? Files::ItemBody).to eq(true) - expect(object_value.value[0].cc_recipients[0].instance_of? Files::Recipient).to eq(true) - expect(object_value.value[0].cc_recipients[0].email_address.instance_of? Files::EmailAddress).to eq(true) + expect(object_value.instance_of?(Files::MessageCollectionResponse)).to eq(true) + expect(object_value.value[0].instance_of?(Files::Message)).to eq(true) + expect(object_value.value[0].body.instance_of?(Files::ItemBody)).to eq(true) + expect(object_value.value[0].cc_recipients[0].instance_of?(Files::Recipient)).to eq(true) + expect(object_value.value[0].cc_recipients[0].email_address.instance_of?(Files::EmailAddress)).to eq(true) ## String tests - expect(object_value.odata_next_link.instance_of? String).to eq(true) - expect(object_value.value[0].body_preview.instance_of? String).to eq(true) + expect(object_value.odata_next_link.instance_of?(String)).to eq(true) + expect(object_value.value[0].body_preview.instance_of?(String)).to eq(true) ## Boolean tests - expect(object_value.value[0].is_draft.to_s.downcase == "true" || object_value.value[0].is_draft.to_s.downcase == "false").to eq(true) - expect(object_value.value[0].is_read.to_s.downcase == "true" || object_value.value[0].is_read.to_s.downcase == "false").to eq(true) - expect(object_value.value[0].body_preview.to_s.downcase == "true" || object_value.value[0].body_preview.to_s.downcase == "false").to eq(false) + expect(%w[true false].include?(object_value.value[0].is_draft.to_s.downcase)).to eq(true) + expect(%w[true false].include?(object_value.value[0].is_read.to_s.downcase)).to eq(true) + expect(%w[true false].include?(object_value.value[0].body_preview.to_s.downcase)).to eq(false) ## Number tests - expect(object_value.additional_data["numb"].instance_of? Integer).to eq(true) + expect(object_value.additional_data['numb'].instance_of?(Integer)).to eq(true) ## GUID tests - expect(object_value.value[0].guid_id.instance_of? UUIDTools::UUID).to eq(true) + expect(object_value.value[0].guid_id.instance_of?(UUIDTools::UUID)).to eq(true) ## Date tests expect(object_value.value[0].received_date_time).to eq(nil) - expect((object_value.value[0].sent_date_time).instance_of? DateTime).to eq(true) + expect(object_value.value[0].sent_date_time.instance_of?(DateTime)).to eq(true) ## Collection of Primitive values tests - expect(object_value.additional_data["primativeValues"].instance_of? Array).to eq(true) + expect(object_value.additional_data['primativeValues'].instance_of?(Array)).to eq(true) ## Collection of object values tests - expect(object_value.value.instance_of? Array).to eq(true) + expect(object_value.value.instance_of?(Array)).to eq(true) ## Enum tests - expect(object_value.value[0].body.content_type.instance_of? Symbol).to eq(true) + expect(object_value.value[0].body.content_type.instance_of?(Symbol)).to eq(true) end - it "can serialize payload" do + it 'can serialize payload' do file = File.open("#{File.dirname(__FILE__)}/sample.json") data = file.read file.close - message_response = MicrosoftKiotaSerializationJson::JsonParseNodeFactory.new().get_parse_node("application/json", data) - object_value = message_response.get_object_value(lambda {|pn| Files::MessageCollectionResponse.create_from_discriminator_value(pn)}) - serializer = MicrosoftKiotaSerializationJson::JsonSerializationWriterFactory.new().get_serialization_writer("application/json") + message_response = MicrosoftKiotaSerializationJson::JsonParseNodeFactory.new.get_parse_node('application/json', + data) + object_value = message_response.get_object_value(lambda { |pn| + Files::MessageCollectionResponse.create_from_discriminator_value(pn) + }) + serializer = MicrosoftKiotaSerializationJson::JsonSerializationWriterFactory.new.get_serialization_writer('application/json') object_value.serialize(serializer) - expect(object_value.value[0].id.to_s == serializer.writer["value"][0]["id"]).to eq(true) + expect(object_value.value[0].id.to_s == serializer.writer['value'][0]['id']).to eq(true) end end diff --git a/components/serialization/json/spec/spec_helper.rb b/components/serialization/json/spec/spec_helper.rb index e233ca1..5e1b016 100644 --- a/components/serialization/json/spec/spec_helper.rb +++ b/components/serialization/json/spec/spec_helper.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true -require "microsoft_kiota_abstractions" + +require 'microsoft_kiota_abstractions' Dir["#{File.dirname(__FILE__)}/./../lib/*.rb"].each { |f| load(f) } RSpec.configure do |config| # Enable flags like --only-failures and --next-failure - config.example_status_persistence_file_path = ".rspec_status" + config.example_status_persistence_file_path = '.rspec_status' # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_patching! diff --git a/release-please-config.json b/release-please-config.json index 61c53cf..76498f2 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -1,48 +1,18 @@ { "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", + "release-type": "simple", + "include-v-in-tag": true, + "include-component-in-tag": false, + "bump-minor-pre-major": true, "packages": { - "components/abstractions": { - "release-type": "ruby", - "package-name": "microsoft_kiota_abstractions", - "changelog-path": "CHANGELOG.md", - "version-file": "lib/microsoft_kiota_abstractions/version.rb", - "component": "microsoft_kiota_abstractions" - }, - "components/serialization/json": { - "release-type": "ruby", - "package-name": "microsoft_kiota_serialization_json", - "changelog-path": "CHANGELOG.md", - "version-file": "lib/microsoft_kiota_serialization_json/version.rb", - "component": "microsoft_kiota_serialization_json" - }, - "components/http": { - "release-type": "ruby", - "package-name": "microsoft_kiota_faraday", + ".": { "changelog-path": "CHANGELOG.md", - "version-file": "lib/microsoft_kiota_faraday/version.rb", - "component": "microsoft_kiota_faraday" - }, - "components/authentication/oauth": { - "release-type": "ruby", - "package-name": "microsoft_kiota_authentication_oauth", - "changelog-path": "CHANGELOG.md", - "version-file": "lib/microsoft_kiota_authentication_oauth/version.rb", - "component": "microsoft_kiota_authentication_oauth" - } - }, - "plugins": [ - { - "type": "linked-versions", - "groupName": "kiota-ruby", - "components": [ - "microsoft_kiota_abstractions", - "microsoft_kiota_serialization_json", - "microsoft_kiota_faraday", - "microsoft_kiota_authentication_oauth" + "extra-files": [ + "components/abstractions/lib/microsoft_kiota_abstractions/version.rb", + "components/serialization/json/lib/microsoft_kiota_serialization_json/version.rb", + "components/http/lib/microsoft_kiota_faraday/version.rb", + "components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/version.rb" ] } - ], - "include-v-in-tag": true, - "include-component-in-tag": false, - "bump-minor-pre-major": true + } } diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..c5523bd --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +0.17.0 From 55ae8567f02ffd1960ff2b5aa554bc66433db6f7 Mon Sep 17 00:00:00 2001 From: andreatp Date: Fri, 21 Aug 2026 16:07:57 +0100 Subject: [PATCH 3/7] chore: add rubocop config and baseline todo - .rubocop.yml enforcing single_quotes, frozen_string_literal, Ruby 3.3 - .rubocop_todo.yml baseline for remaining non-auto-correctable offenses --- .rubocop.yml | 12 +++ .rubocop_todo.yml | 189 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 201 insertions(+) create mode 100644 .rubocop.yml create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..50d9f8e --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,12 @@ +inherit_from: .rubocop_todo.yml + +AllCops: + TargetRubyVersion: 3.3 + NewCops: enable + SuggestExtensions: false + +Style/StringLiterals: + EnforcedStyle: single_quotes + +Style/FrozenStringLiteralComment: + Enabled: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..02f7e2b --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,189 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2026-08-21 15:03:46 UTC using RuboCop version 1.89.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 12 +# Configuration parameters: EnforcedStyle, AllowedGems. +# SupportedStyles: Gemfile, gems.rb, gemspec +Gemspec/DevelopmentDependencies: + Exclude: + - 'components/abstractions/microsoft_kiota_abstractions.gemspec' + - 'components/authentication/oauth/microsoft_kiota_authentication_oauth.gemspec' + - 'components/http/microsoft_kiota_faraday.gemspec' + - 'components/serialization/json/microsoft_kiota_serialization_json.gemspec' + +# Offense count: 3 +# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches, IgnoreDuplicateElseBranch. +Lint/DuplicateBranch: + Exclude: + - 'components/serialization/json/lib/microsoft_kiota_serialization_json/json_parse_node.rb' + +# Offense count: 2 +# Configuration parameters: DelegatingMethods. +# DelegatingMethods: delegate +Lint/DuplicateMethods: + Exclude: + - 'components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_factory_registry.rb' + - 'components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory_registry.rb' + +# Offense count: 2 +# Configuration parameters: AllowComments, AllowEmptyLambdas. +Lint/EmptyBlock: + Exclude: + - 'components/abstractions/lib/microsoft_kiota_abstractions/authentication/anonymous_authentication_provider.rb' + - 'components/abstractions/lib/microsoft_kiota_abstractions/authentication/base_bearer_token_authentication_provider.rb' + +# Offense count: 3 +# Configuration parameters: AllowedParentClasses. +Lint/MissingSuper: + Exclude: + - 'components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_context.rb' + - 'components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb' + - 'components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/on_behalf_of_context.rb' + +# Offense count: 1 +Lint/SharedMutableDefault: + Exclude: + - 'components/serialization/json/lib/microsoft_kiota_serialization_json/json_parse_node.rb' + +# Offense count: 17 +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. +Metrics/AbcSize: + Max: 83 + +# Offense count: 17 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +# AllowedMethods: refine +Metrics/BlockLength: + Max: 152 + +# Offense count: 5 +# Configuration parameters: CountComments, CountAsOne. +Metrics/ClassLength: + Max: 175 + +# Offense count: 17 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/CyclomaticComplexity: + Max: 20 + +# Offense count: 23 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +Metrics/MethodLength: + Max: 61 + +# Offense count: 11 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/PerceivedComplexity: + Max: 18 + +# Offense count: 60 +Naming/AccessorMethodName: + Enabled: false + +# Offense count: 1 +Naming/ConstantName: + Exclude: + - 'components/serialization/json/spec/files/body_type.rb' + +# Offense count: 2 +# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to +Naming/MethodParameterName: + Exclude: + - 'components/abstractions/lib/microsoft_kiota_abstractions/request_information.rb' + +# Offense count: 1 +# Configuration parameters: Mode, AllowedMethods, AllowedPatterns, AllowBangMethods, WaywardPredicates. +# AllowedMethods: call +# WaywardPredicates: infinite?, nonzero? +Naming/PredicateMethod: + Exclude: + - 'components/abstractions/lib/microsoft_kiota_abstractions/request_headers.rb' + +# Offense count: 1 +Security/Eval: + Exclude: + - 'components/abstractions/lib/microsoft_kiota_abstractions/request_information.rb' + +# Offense count: 6 +Style/ClassVars: + Exclude: + - 'components/abstractions/lib/microsoft_kiota_abstractions/request_information.rb' + - 'components/http/lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_handler.rb' + - 'components/http/lib/microsoft_kiota_faraday/middleware/user_agent_handler.rb' + +# Offense count: 1 +Style/DocumentDynamicEvalDefinition: + Exclude: + - 'components/abstractions/lib/microsoft_kiota_abstractions/request_information.rb' + +# Offense count: 53 +# Configuration parameters: AllowedConstants. +Style/Documentation: + Enabled: false + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/EvalWithLocation: + Exclude: + - 'components/abstractions/lib/microsoft_kiota_abstractions/request_information.rb' + +# Offense count: 2 +Style/FileOpen: + Exclude: + - 'components/serialization/json/spec/microsoft_kiota_serialization_json_spec.rb' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals. +Style/GuardClause: + Exclude: + - 'components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_context.rb' + - 'components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb' + - 'components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/on_behalf_of_context.rb' + +# Offense count: 15 +# This cop supports safe autocorrection (--autocorrect). +Style/IfUnlessModifier: + Exclude: + - 'components/abstractions/lib/microsoft_kiota_abstractions/request_headers.rb' + - 'components/abstractions/lib/microsoft_kiota_abstractions/request_information.rb' + - 'components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_context.rb' + - 'components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context.rb' + - 'components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/contexts/on_behalf_of_context.rb' + - 'components/http/lib/microsoft_kiota_faraday/faraday_request_adapter.rb' + - 'components/http/lib/microsoft_kiota_faraday/kiota_client_factory.rb' + - 'components/http/lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_handler.rb' + - 'components/http/lib/microsoft_kiota_faraday/middleware/user_agent_handler.rb' + +# Offense count: 1 +# Configuration parameters: AllowedClasses. +Style/OneClassPerFile: + Exclude: + - 'spec/**/*' + - 'test/**/*' + - 'components/authentication/oauth/lib/microsoft_kiota_authentication_oauth/extensions/oauth2_ext.rb' + +# Offense count: 1 +Style/OptionalArguments: + Exclude: + - 'components/abstractions/lib/microsoft_kiota_abstractions/request_information.rb' + +# Offense count: 1 +# Configuration parameters: AllowedMethods. +# AllowedMethods: respond_to_missing? +Style/OptionalBooleanParameter: + Exclude: + - 'components/http/lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_option.rb' + +# Offense count: 55 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, AllowRBSInlineAnnotation, AllowCopDirectives, AllowedPatterns, SplitStrings. +# URISchemes: http, https +Layout/LineLength: + Max: 373 From c6e85977d356fe25ce1c2a6acc871d82d3713034 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 24 Aug 2026 10:24:05 -0400 Subject: [PATCH 4/7] docs: replaces outdated homepage Signed-off-by: Vincent Biret --- components/abstractions/microsoft_kiota_abstractions.gemspec | 2 +- .../oauth/microsoft_kiota_authentication_oauth.gemspec | 2 +- components/http/microsoft_kiota_faraday.gemspec | 2 +- .../json/microsoft_kiota_serialization_json.gemspec | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/abstractions/microsoft_kiota_abstractions.gemspec b/components/abstractions/microsoft_kiota_abstractions.gemspec index 08becc6..1be55ab 100644 --- a/components/abstractions/microsoft_kiota_abstractions.gemspec +++ b/components/abstractions/microsoft_kiota_abstractions.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |spec| spec.email = 'graphsdkpub+ruby@microsoft.com' spec.description = 'Microsoft Kiota Abstractions - Ruby abstractions for building library agnostic http client' spec.summary = 'The Kiota abstractions are language specific libraries defining the basic constructs Kiota projects need once an SDK has been generated from an OpenAPI definition.' - spec.homepage = 'https://microsoft.github.io/kiota/' + spec.homepage = 'https://learn.microsoft.com/openapi/kiota/' spec.license = 'MIT' spec.metadata = { 'bug_tracker_uri' => 'https://github.com/microsoft/kiota-ruby/issues', diff --git a/components/authentication/oauth/microsoft_kiota_authentication_oauth.gemspec b/components/authentication/oauth/microsoft_kiota_authentication_oauth.gemspec index 839ca6f..68e070c 100644 --- a/components/authentication/oauth/microsoft_kiota_authentication_oauth.gemspec +++ b/components/authentication/oauth/microsoft_kiota_authentication_oauth.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |spec| spec.email = 'graphsdkpub+ruby@microsoft.com' spec.description = 'Kiota Authentication implementation with oauth2' spec.summary = 'Microsoft Kiota Authentication OAuth - Kiota Ruby Authentication OAuth library' - spec.homepage = 'https://microsoft.github.io/kiota/' + spec.homepage = 'https://learn.microsoft.com/openapi/kiota/' spec.license = 'MIT' spec.metadata = { 'bug_tracker_uri' => 'https://github.com/microsoft/kiota-ruby/issues', diff --git a/components/http/microsoft_kiota_faraday.gemspec b/components/http/microsoft_kiota_faraday.gemspec index e2c7de8..2cb5e0d 100644 --- a/components/http/microsoft_kiota_faraday.gemspec +++ b/components/http/microsoft_kiota_faraday.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |spec| spec.email = 'graphsdkpub+ruby@microsoft.com' spec.description = 'Kiota HttpCore implementation with Faraday' spec.summary = 'Microsoft Kiota Faraday - Kiota Ruby http request adapter for running requests' - spec.homepage = 'https://microsoft.github.io/kiota/' + spec.homepage = 'https://learn.microsoft.com/openapi/kiota/' spec.license = 'MIT' spec.metadata = { 'bug_tracker_uri' => 'https://github.com/microsoft/kiota-ruby/issues', diff --git a/components/serialization/json/microsoft_kiota_serialization_json.gemspec b/components/serialization/json/microsoft_kiota_serialization_json.gemspec index f58201f..71bcc5c 100644 --- a/components/serialization/json/microsoft_kiota_serialization_json.gemspec +++ b/components/serialization/json/microsoft_kiota_serialization_json.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |spec| spec.email = 'graphsdkpub+ruby@microsoft.com' spec.description = 'Implementation of Kiota Serialization interfaces for JSON' spec.summary = 'Microsoft Kiota Serialization - Ruby serialization for building library agnostic http client' - spec.homepage = 'https://microsoft.github.io/kiota/' + spec.homepage = 'https://learn.microsoft.com/openapi/kiota/' spec.license = 'MIT' spec.metadata = { 'bug_tracker_uri' => 'https://github.com/microsoft/kiota-ruby/issues', From 5729914f8371c35e0b7c975b033ce7beaecf5bd7 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 24 Aug 2026 10:36:07 -0400 Subject: [PATCH 5/7] chore: linting --- .../oauth/spec/microsoft_kiota_authentication_oauth_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/authentication/oauth/spec/microsoft_kiota_authentication_oauth_spec.rb b/components/authentication/oauth/spec/microsoft_kiota_authentication_oauth_spec.rb index 82032d5..9499491 100644 --- a/components/authentication/oauth/spec/microsoft_kiota_authentication_oauth_spec.rb +++ b/components/authentication/oauth/spec/microsoft_kiota_authentication_oauth_spec.rb @@ -27,7 +27,7 @@ end it '(auth code context) throws when tenant_id/client_secret is nil/empty' do - expect do + expect do MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new(nil, nil, nil, nil) end.to raise_error(StandardError) expect do From 0adeeefeea222a7843b6218bd423b09d6a8f3011 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 24 Aug 2026 10:40:44 -0400 Subject: [PATCH 6/7] chore: use index instead of regex based detection for improved security and performance --- .../serialization/parse_node_factory_registry.rb | 16 ++++++++++++++-- .../serialization_writer_factory_registry.rb | 16 ++++++++++++++-- .../spec/parse_node_factory_registry_spec.rb | 1 + ...serialization_writer_factory_registry_spec.rb | 1 + 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_factory_registry.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_factory_registry.rb index 2658147..5bc7bab 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_factory_registry.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/parse_node_factory_registry.rb @@ -28,11 +28,23 @@ def get_parse_node(content_type, content) factory = @content_type_associated_factories[vendor_specific_content_type] return factory.get_parse_node(vendor_specific_content_type, content) if factory - clean_content_type = vendor_specific_content_type.gsub(%r{[^/]+\+}i, '') + clean_content_type = get_clean_content_type(vendor_specific_content_type) factory = @content_type_associated_factories[clean_content_type] return factory.get_parse_node(clean_content_type, content) if factory - raise StandardError, "Content type #{contentType} does not have a factory to be parsed" + raise StandardError, "Content type #{content_type} does not have a factory to be parsed" + end + + private + + def get_clean_content_type(content_type) + plus_index = content_type.rindex('+') + return content_type unless plus_index + + slash_index = content_type.rindex('/', plus_index) + return content_type unless slash_index && slash_index < plus_index + + "#{content_type[0..slash_index]}#{content_type[(plus_index + 1)..]}" end end end diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory_registry.rb b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory_registry.rb index c5e7865..16f98f1 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory_registry.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory_registry.rb @@ -27,11 +27,23 @@ def get_serialization_writer(content_type) factory = @content_type_associated_factories[vendor_specific_content_type] return factory.get_serialization_writer(vendor_specific_content_type) if factory - clean_content_type = vendor_specific_content_type.gsub(%r{[^/]+\+}i, '') + clean_content_type = get_clean_content_type(vendor_specific_content_type) factory = @content_type_associated_factories[clean_content_type] return factory.get_serialization_writer(clean_content_type) if factory - raise StandardError, "Content type #{contentType} does not have a factory to be serialized" + raise StandardError, "Content type #{content_type} does not have a factory to be serialized" + end + + private + + def get_clean_content_type(content_type) + plus_index = content_type.rindex('+') + return content_type unless plus_index + + slash_index = content_type.rindex('/', plus_index) + return content_type unless slash_index && slash_index < plus_index + + "#{content_type[0..slash_index]}#{content_type[(plus_index + 1)..]}" end end end diff --git a/components/abstractions/spec/parse_node_factory_registry_spec.rb b/components/abstractions/spec/parse_node_factory_registry_spec.rb index 37af0b6..72d57b1 100644 --- a/components/abstractions/spec/parse_node_factory_registry_spec.rb +++ b/components/abstractions/spec/parse_node_factory_registry_spec.rb @@ -8,6 +8,7 @@ values << 'application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8' values << 'application/vnd.github.mercy-preview+json' values << 'application/vnd.github.mercy-preview+json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8' + values << "application/#{Array.new(1000, 'vendor').join('.')}+json" serialized_value = '[1]' MicrosoftKiotaAbstractions::ParseNodeFactoryRegistry.default_instance.content_type_associated_factories['application/json'] = ParseNodeFactoryMock.new diff --git a/components/abstractions/spec/serialization_writer_factory_registry_spec.rb b/components/abstractions/spec/serialization_writer_factory_registry_spec.rb index c0ad9da..5722b03 100644 --- a/components/abstractions/spec/serialization_writer_factory_registry_spec.rb +++ b/components/abstractions/spec/serialization_writer_factory_registry_spec.rb @@ -8,6 +8,7 @@ values << 'application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8' values << 'application/vnd.github.mercy-preview+json' values << 'application/vnd.github.mercy-preview+json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8' + values << "application/#{Array.new(1000, 'vendor').join('.')}+json" MicrosoftKiotaAbstractions::SerializationWriterFactoryRegistry.default_instance.content_type_associated_factories['application/json'] = SerializationWriterFactoryMock.new it 'gets the serialization writer' do From 08bbf29ae5d83297d1140afdaba7a868a4e0e8ef Mon Sep 17 00:00:00 2001 From: andreatp Date: Mon, 24 Aug 2026 16:09:05 +0100 Subject: [PATCH 7/7] fix Readme to use rubocop single quote convention --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 31d7e15..1810538 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,10 @@ This repository contains the Ruby libraries for [Kiota](https://github.com/micro Add the gems you need to your application's Gemfile: ```ruby -gem "microsoft_kiota_abstractions" -gem "microsoft_kiota_serialization_json" -gem "microsoft_kiota_faraday" -gem "microsoft_kiota_authentication_oauth" +gem 'microsoft_kiota_abstractions' +gem 'microsoft_kiota_serialization_json' +gem 'microsoft_kiota_faraday' +gem 'microsoft_kiota_authentication_oauth' ``` ## Development