Skip to content

Commit

Permalink
API Generator
Browse files Browse the repository at this point in the history
Signed-off-by: Theo Truong <theotr@amazon.com>
  • Loading branch information
nhtruong committed Dec 17, 2024
1 parent c1a9cc9 commit 62fb7f0
Show file tree
Hide file tree
Showing 661 changed files with 12,693 additions and 24,361 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
fail-fast: false
matrix:
cluster-version: [ "1.0.0", "1.0.1", "1.1.0", "1.2.0", "1.2.1", "1.2.2", "1.2.3", "1.2.4", "1.3.0", "1.3.1", "2.0.0" ]
cluster-version: [ "1.3.3", "2.0.1", "2.18.0" ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
strategy:
fail-fast: false
matrix:
cluster-version: [ "1.0.0", "1.0.1", "1.1.0", "1.2.0", "1.2.1", "1.2.2", "1.2.3", "1.2.4", "1.3.0", "1.3.1", "1.3.2", "1.3.3", "2.0.0", "2.0.1" ]
cluster-version: [ "1.3.3", "2.0.1" ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
63 changes: 63 additions & 0 deletions .github/workflows/generate_api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Generate API from Spec
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 0" # Every Sunday at midnight GMT
jobs:
generate-api:
if: ${{ github.repository == 'opensearch-project/opensearch-ruby' }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./api_generator
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: Config git to rebase
run: git config --global pull.rebase true

- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1

- name: Update bundler
run: |
sudo apt-get update
bundle install
- name: Generate API
run: |-
bundle exec rake download_spec
bundle exec rake generate_api
- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_ENV

- name: GitHub App token
id: github_app_token
uses: tibdex/github-app-token@v2.1.0
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}

- name: Create pull request
uses: peter-evans/create-pull-request@v7
with:
token: ${{ steps.github_app_token.outputs.token }}
commit-message: "Updated opensearch-ruby to reflect the latest OpenSearch API spec (${{ env.date }})"
title: "[AUTOCUT] Update opensearch-ruby to reflect the latest OpenSearch API spec (${{ env.date }})"
body: |
Update `opensearch-ruby` to reflect the latest [OpenSearch API spec](https://github.com/opensearch-project/opensearch-api-specification/releases/download/main-latest/opensearch-openapi.yaml).
Date: ${{ env.date }}
branch: update-api-from-spec-${{ env.date }}
base: main
signoff: true
labels: |
autocut
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [ 2.5, 2.6, 2.7, '3.0', 3.1, 3.2, 3.3, jruby-9.3 ]
ruby: [ 3.0, 3.3, jruby-9.4 ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [ 2.6, 2.7, '3.0', 3.1, 3.2, 3.3, jruby-9.3 ]
ruby: [ 3.0, 3.3, jruby-9.3 ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [ 2.5, 2.6, 2.7, '3.0', 3.1, 3.2, 3.3, jruby-9.3 ]
ruby: [ 3.0, 3.3, jruby-9.3 ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/test-unreleased.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ on:

jobs:
test:
env:
TEST_OPENSEARCH_SERVER: http://localhost:9200
PORT: 9200
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down Expand Up @@ -98,7 +101,7 @@ jobs:
bundle install
working-directory: ruby-client

- name: opensearch-ruby
- name: Perform Integration Tests
working-directory: ruby-client
run: rake test:integration

Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ coverage
docs/
rdoc/
tmp
Gemfile.lock
/Gemfile.lock
.DS_Store
*.log
.idea/*
profile/**/data/*.json
.byebug_history
dist/
gem-private_key.pem
.ruby-version
/.ruby-version
*/.idea/**
5 changes: 4 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require:
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.5
TargetRubyVersion: 3.0
NewCops: enable
Exclude:
- 'api_generator/**/*'
Expand Down Expand Up @@ -36,3 +36,6 @@ Layout/FirstArgumentIndentation:

Layout/FirstArrayElementIndentation:
Enabled: false

Layout/LineLength:
Enabled: false
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Fixed
### Security

## [4.0.0]
### Added
- Added an API Generator ([#233](https://github.com/opensearch-project/opensearch-ruby/issues/233))
- Added a workflow to generate API methods from OpenSearch API Spec
### Changed
- Restructured the API methods and modules to be more efficient and intuitive
### Deprecated
- Removed support for Ruby 2.x

## [3.4.0]
### Added
- Added `script_score` to Query DSL ([#254](https://github.com/opensearch-project/opensearch-ruby/pull/254))
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ source 'https://rubygems.org'

gem 'opensearch-ruby', path: __dir__, require: false

gem 'activesupport'
gem 'ansi'
gem 'bundler'
gem 'cane'
Expand Down
4 changes: 4 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Upgrading
Major versions of OpenSearch introduce breaking changes that require careful upgrades of the client. Check the [Compatibility](COMPATIBILITY.md) doc to see which version of the client should be used against your OpenSearch cluster.

### Upgrade to OpenSearch Ruby 4
OpenSearch Ruby 4 drops support for Ruby 2.x. If you are using Ruby 2.x, you should upgrade to Ruby 3.x before upgrading to OpenSearch Ruby 4.


### Upgrade to OpenSearch Ruby 3
In Version 3 of the OpenSearch Ruby client, we have added the `api` and `transport` modules as the core components of the gem, instead of treating them as separate gems that are required by the `opensearch-ruby` gem. This removes the confusions around compatibility between the ruby client, its legacy dependencies, and the OpenSearch cluster.

Expand Down
1 change: 1 addition & 0 deletions api_generator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
opensearch-openapi.yaml
19 changes: 19 additions & 0 deletions api_generator/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require: rubocop-rake
AllCops:
Include:
- 'lib/**/*.rb'
- 'Rakefile'
NewCops: enable

Metrics/CyclomaticComplexity:
Enabled: false
Metrics/MethodLength:
Enabled: false
Metrics/AbcSize:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false
Layout/EmptyLineAfterGuardClause:
Enabled: false
Style/MultilineBlockChain:
Enabled: false
1 change: 1 addition & 0 deletions api_generator/.ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.1.0
21 changes: 21 additions & 0 deletions api_generator/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

# frozen_string_literal: true

require 'rake'
require 'active_support/all'

task :download_spec do
sh 'curl -L -X GET "https://github.com/opensearch-project/opensearch-api-specification/releases/download/main-latest/opensearch-openapi.yaml" -o opensearch-openapi.yaml'
end


task :generate_api do
require './lib/generator'
generator = Generator.new('./opensearch-openapi.yaml', '../')
generator.generate
end
16 changes: 16 additions & 0 deletions api_generator/gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

# frozen_string_literal: true

source 'https://rubygems.org'

gem 'rake'
gem 'rubocop', '~> 1.44', require: false
gem 'rubocop-rspec', require: false
gem 'rubocop-rake', require: false
gem 'mustache', '~> 1'
gem 'activesupport', '~> 7'
71 changes: 71 additions & 0 deletions api_generator/gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (7.2.1)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.8)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
drb (2.2.1)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
json (2.7.2)
language_server-protocol (3.17.0.3)
logger (1.6.1)
minitest (5.25.1)
mustache (1.1.1)
parallel (1.26.3)
parser (3.3.5.0)
ast (~> 2.4.1)
racc
racc (1.8.1)
rainbow (3.1.1)
rake (13.2.1)
regexp_parser (2.9.2)
rubocop (1.66.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.4, < 3.0)
rubocop-ast (>= 1.32.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.32.3)
parser (>= 3.3.1.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (2.11.1)
rubocop (~> 1.19)
ruby-progressbar (1.13.0)
securerandom (0.3.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.6.0)

PLATFORMS
ruby
x86_64-darwin-22

DEPENDENCIES
activesupport (~> 7)
mustache (~> 1)
rake
rubocop (~> 1.44)
rubocop-rake
rubocop-rspec

BUNDLED WITH
2.5.3
2 changes: 2 additions & 0 deletions api_generator/lib/_generated_code_warning.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file is generated from the OpenSearch REST API spec.
# Do not modify it by hand. Instead, modify the generator or the spec.
5 changes: 5 additions & 0 deletions api_generator/lib/_license_header.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
Loading

0 comments on commit 62fb7f0

Please sign in to comment.