Skip to content

Commit

Permalink
Fixed: mustache file not found error (#269)
Browse files Browse the repository at this point in the history
Fixed: Wrong type due to SpecHash parsing bug
Fixed: Extra space in method description

Signed-off-by: Theo Truong <theotr@amazon.com>
  • Loading branch information
nhtruong authored Feb 7, 2025
1 parent d081e8c commit 29567b4
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/check_license_headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# under the License.

LICENSE = File.read('./.github/license-header.txt')
files = `git ls-files | grep -E '\.rb|Rakefile|\.rake|\.erb|Gemfile|gemspec'`.split("\n")
files = `git ls-files | grep -E '\.rb|^Rakefile$|\.rake|\.erb|^Gemfile$|^gemspec$'`.split("\n")
errors = []

files.each do |file|
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ on:
- "*"
paths-ignore:
- '*.md'
- '.github/workflows/generate_api.yml'
- 'api_generator/**'
pull_request:
branches:
- "*"
paths-ignore:
- '*.md'
- '.github/workflows/generate_api.yml'
- 'api_generator/**'

jobs:
test-opensearch:
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/generate_api.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: Generate API from Spec
on:
pull_request:
paths:
- '.github/workflows/generate_api.yml'
- 'api_generator/**'
workflow_dispatch:
schedule:
- cron: "0 0 * * 0" # Every Sunday at midnight GMT
Expand Down Expand Up @@ -37,18 +41,30 @@ jobs:
bundle exec rake download_spec
bundle exec rake generate_api
# This should only trigger on pull requests that modifies the api_generator directory
# and NOT on the scheduled workflow since the scheduled workflow will trigger the lint workflow instead.
- name: Lint generated files
if: ${{ github.event_name == 'pull_request' }}
working-directory: ./
run: |-
bundle install
bundle exec rubocop
- name: Get current date
id: date
if: ${{ github.event_name != 'pull_request' }}
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_ENV

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

- name: Create pull request
if: ${{ github.event_name != 'pull_request' }}
uses: peter-evans/create-pull-request@v7
with:
token: ${{ steps.github_app_token.outputs.token }}
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ on:
- "*"
paths-ignore:
- '*.md'
- '.github/workflows/generate_api.yml'
- 'api_generator/**'
pull_request:
branches:
- "*"
paths-ignore:
- '*.md'
- '.github/workflows/generate_api.yml'
- 'api_generator/**'
jobs:
test-opensearch:
env:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test-unreleased.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ on:
- 'main'
paths-ignore:
- '*.md'
- '.github/workflows/generate_api.yml'
- 'api_generator/**'
pull_request:
branches:
- 'main'
paths-ignore:
- '*.md'
- '.github/workflows/generate_api.yml'
- 'api_generator/**'

jobs:
test:
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion api_generator/lib/generators/action_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def initialize(gem_folder, namespace, action)
@module_name = namespace.root ? 'Root' : namespace.name.camelize
@method_name = action.name.underscore
@valid_params_constant_name = "#{action.name.upcase}_QUERY_PARAMS"
@method_description = action.description.squeeze("\n").gsub("\n", "\n # ")
@method_description = action.description.split("\n").filter(&:present?).map(&:strip).join("\n # ")
end

def argument_descriptions
Expand Down
21 changes: 16 additions & 5 deletions api_generator/lib/spec_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,25 @@ class << self; attr_reader :parsed; end

# @param [Hash] hash
def initialize(hash = {}, parsed: true)
raise ArgumentError, "#{self.class} must be initialized with a Hash" unless hash.is_a?(Hash)
@hash = parsed ? hash : parse(hash)
@parsed_keys = Set.new
end

def to_s
"<SpecHash: #{@hash.to_s}>"
end

def is_a?(klass)
klass == SpecHash || super
end

def [](key)
parse(@hash[key])
return @hash[key] if @parsed_keys.include?(key)
@hash[key] = parse(@hash[key])
end

def respond_to_missing?(name)
def respond_to_missing?(name, ...)
@hash.key?(name.to_s) || {}.respond_to?(name) || super
end

Expand All @@ -49,7 +60,7 @@ def method_missing(name, ...)
warn "Accessing Hash attribute `#{name}` which is also a key of the SpecHash instance." if @hash.key?(name.to_s)
return @hash.send(name, ...)
end
parse(@hash[name.to_s])
self[name.to_s]
end

private
Expand All @@ -59,8 +70,8 @@ def parse(value)
return value unless value.is_a?(Hash)
ref = value.delete('$ref')
value.transform_values! { |v| parse(v) }
return SpecHash.new(value) unless ref
SpecHash.new(parse(resolve(ref)).merge(value))
value.merge!(resolve(ref)) if ref
SpecHash.new(value)
end

def resolve(ref)
Expand Down

0 comments on commit 29567b4

Please sign in to comment.