Skip to content

Commit

Permalink
# get rid of low/high level wordings
Browse files Browse the repository at this point in the history
Signed-off-by: Theo Truong <[email protected]>
  • Loading branch information
nhtruong committed Nov 28, 2023
1 parent 15e5c2b commit 2906e8c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
22 changes: 11 additions & 11 deletions api_generator/USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,39 @@ require './lib/api_generator'
generator = ApiGenerator.new('./OpenSearch.openapi.json')
```

### Generate High-level API Actions
### Generate Spec Methods:

The `generate_high_level` method accepts the path to the root directory of the `opensearch-ruby` gem as a parameter. By default, it points to the parent directory of the folder containing the generator script. For example to generate all actions into the `tmp` directory:
The `generate_spec_methods` method accepts the path to the root directory of the `opensearch-ruby` gem as a parameter. By default, it points to the parent directory of the folder containing the generator script. For example to generate all actions into the `tmp` directory:
```ruby
generator.generate_high_level('./tmp')
generator.generate_spec_methods('./tmp')
```

You can also target a specific API version by passing in the version number as a parameter. For example to generate all actions for version `1.0` into the `tmp` directory:
```ruby
generator.generate_high_level(version: '1.0')
generator.generate_spec_methods(version: '1.0')
```

The generator also support incremental generation. For example, to generate all actions of the `cat` namespace:
```ruby
generator.generate_high_level(namespace: 'cat')
generator.generate_spec_methods(namespace: 'cat')
```

To limit it to specific actions of a namespace:
```ruby
generator.generate_high_level(namespace: 'cat', actions: %w[aliases allocation])
generator.generate_spec_methods(namespace: 'cat', actions: %w[aliases allocation])
```

Note that the root namespace is presented by an empty string `''`. For example, to generate all actions of the root namespace for OS version 2.3:
```ruby
generator.generate_high_level(version: '2.3', namespace: '')
generator.generate_spec_methods(version: '2.3', namespace: '')
```

### Generate low-level API actions:
### Generate Static Methods:

To generate the low level API methods:
To generate static methods:

```ruby
generator.generate_low_level
generator.generate_static_methods
```

The low level API methods are independent of the Spec. A change in the OpenSearch API Spec will not affect the low level APIs. So, only execute `generate_low_level` if you have made changes to the low-level APIs logic.
The static methods are independent of the Spec. A change in the OpenSearch API Spec will not affect these methods.
8 changes: 4 additions & 4 deletions api_generator/lib/api_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ def initialize(openapi_spec)
@spec = Openapi3Parser.load_file(openapi_spec)
end

# Generate high level API methods from the OpenSearch Specs.
# Generate API methods from the OpenSearch Specs.
# @param [String] gem_folder location of the API Gem folder (default to the parent folder of the generator)
# @param [String] version target OpenSearch version to generate like "2.5" or "3.0"
# @param [String] namespace namespace to generate (Default to all namespaces. Use '' for root)
# @param [Array<String>] actions list of actions in the specified namespace to generate (Default to all actions)
def generate_high_level(gem_folder = '../', version: nil, namespace: nil, actions: nil)
def generate_spec_methods(gem_folder = '../', version: nil, namespace: nil, actions: nil)
gem_folder = Pathname gem_folder
namespaces = existing_namespaces(gem_folder)
target_actions(version, namespace, actions).each do |action|
Expand All @@ -39,9 +39,9 @@ def generate_high_level(gem_folder = '../', version: nil, namespace: nil, action
IndexGenerator.new(gem_folder.join('lib/opensearch'), namespaces).generate
end

# Generate low level API methods that are independent of the OpenSearch Specs.
# Generate basic HTTP methods that are independent of the OpenSearch Specs.
# @param [String] gem_folder location of the API Gem folder (default to the parent folder of the generator)
def generate_low_level(gem_folder = '../')
def generate_static_methods(gem_folder = '../')
gem_folder = Pathname gem_folder
namespaces = existing_namespaces(gem_folder)
low_level_namespace = 'http'
Expand Down

0 comments on commit 2906e8c

Please sign in to comment.