Skip to content

Commit

Permalink
[Ruby] add file download tests (#17362)
Browse files Browse the repository at this point in the history
* add new ruby echo api clients

* add tests for ruby faraday file download

* add file download test to ruby Typhoeus

* add ruby workflow, add tests for ruby httpx

* update

* fix
  • Loading branch information
wing328 authored Dec 9, 2023
1 parent dd36fa0 commit 10da7a3
Show file tree
Hide file tree
Showing 156 changed files with 17,233 additions and 315 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/samples-ruby.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Samples Ruby

on:
push:
paths:
- 'samples/client/echo_api/ruby-httpx/**'
- 'samples/client/echo_api/ruby-faraday/**'
- 'samples/client/echo_api/ruby-typhoeus/**'
pull_request:
paths:
- 'samples/client/echo_api/ruby-httpx/**'
- 'samples/client/echo_api/ruby-faraday/**'
- 'samples/client/echo_api/ruby-typhoeus/**'

jobs:
build:
name: Build Ruby
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sample:
- 'samples/client/echo_api/ruby-httpx/'
- 'samples/client/echo_api/ruby-faraday/'
- 'samples/client/echo_api/ruby-typhoeus/'
steps:
- uses: actions/checkout@v4
- name: Setup node.js
uses: actions/setup-node@v4
- name: Run echo server
run: |
git clone https://github.com/wing328/http-echo-server -b openapi-generator-test-server
(cd http-echo-server && npm install && npm start &)
- uses: actions/setup-ruby@v1
with:
ruby-version: 3.0
bundler-cache: true
- name: Install bundle
working-directory: ${{ matrix.sample }}
run: bundle install
- name: Run rspec
working-directory: ${{ matrix.sample }}
run: rspec
7 changes: 7 additions & 0 deletions bin/configs/ruby-faraday-echo-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
generatorName: ruby
outputDir: samples/client/echo_api/ruby-faraday
inputSpec: modules/openapi-generator/src/test/resources/3_0/echo_api.yaml
templateDir: modules/openapi-generator/src/main/resources/ruby-client
library: faraday
additionalProperties:
hideGenerationTimestamp: "true"
7 changes: 7 additions & 0 deletions bin/configs/ruby-typhoeus-echo-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
generatorName: ruby
outputDir: samples/client/echo_api/ruby-typhoeus
inputSpec: modules/openapi-generator/src/test/resources/3_0/echo_api.yaml
templateDir: modules/openapi-generator/src/main/resources/ruby-client
library: typhoeus
additionalProperties:
hideGenerationTimestamp: "true"
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,16 @@
chunk.force_encoding(encoding)
tempfile.write(chunk)
end
request.on_complete do |response|
if tempfile
tempfile.close
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
"explicitly with `tempfile.delete`"
end
# run the request to ensure the tempfile is created successfully before returning it
request.run
if tempfile
tempfile.close
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
"explicitly with `tempfile.delete`"
else
fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
end

tempfile
Expand Down
39 changes: 39 additions & 0 deletions samples/client/echo_api/ruby-faraday/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by: https://openapi-generator.tech
#

*.gem
*.rbc
/.config
/coverage/
/InstalledFiles
/pkg/
/spec/reports/
/spec/examples.txt
/test/tmp/
/test/version_tmp/
/tmp/

## Specific to RubyMotion:
.dat*
.repl_history
build/

## Documentation cache and generated files:
/.yardoc/
/_yardoc/
/doc/
/rdoc/

## Environment normalization:
/.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:
# Gemfile.lock
# .ruby-version
# .ruby-gemset

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc
26 changes: 26 additions & 0 deletions samples/client/echo_api/ruby-faraday/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.ruby: &ruby
variables:
LANG: "C.UTF-8"
before_script:
- ruby -v
- bundle config set --local deployment true
- bundle install -j $(nproc)
parallel:
matrix:
- RUBY_VERSION: ['2.7', '3.0', '3.1']
image: "ruby:$RUBY_VERSION"
cache:
paths:
- vendor/ruby
key: 'ruby-$RUBY_VERSION'

gem:
extends: .ruby
script:
- bundle exec rspec
- bundle exec rake build
- bundle exec rake install
artifacts:
paths:
- pkg/*.gem

25 changes: 25 additions & 0 deletions samples/client/echo_api/ruby-faraday/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
spec/api_client_spec.rb
spec/configuration_spec.rb
50 changes: 50 additions & 0 deletions samples/client/echo_api/ruby-faraday/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.gitignore
.gitlab-ci.yml
.rspec
.rubocop.yml
.travis.yml
Gemfile
README.md
Rakefile
docs/AuthApi.md
docs/Bird.md
docs/BodyApi.md
docs/Category.md
docs/DataQuery.md
docs/DefaultValue.md
docs/FormApi.md
docs/HeaderApi.md
docs/NumberPropertiesOnly.md
docs/PathApi.md
docs/Pet.md
docs/Query.md
docs/QueryApi.md
docs/StringEnumRef.md
docs/Tag.md
docs/TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.md
docs/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md
git_push.sh
lib/openapi_client.rb
lib/openapi_client/api/auth_api.rb
lib/openapi_client/api/body_api.rb
lib/openapi_client/api/form_api.rb
lib/openapi_client/api/header_api.rb
lib/openapi_client/api/path_api.rb
lib/openapi_client/api/query_api.rb
lib/openapi_client/api_client.rb
lib/openapi_client/api_error.rb
lib/openapi_client/configuration.rb
lib/openapi_client/models/bird.rb
lib/openapi_client/models/category.rb
lib/openapi_client/models/data_query.rb
lib/openapi_client/models/default_value.rb
lib/openapi_client/models/number_properties_only.rb
lib/openapi_client/models/pet.rb
lib/openapi_client/models/query.rb
lib/openapi_client/models/string_enum_ref.rb
lib/openapi_client/models/tag.rb
lib/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.rb
lib/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.rb
lib/openapi_client/version.rb
openapi_client.gemspec
spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.2.0-SNAPSHOT
2 changes: 2 additions & 0 deletions samples/client/echo_api/ruby-faraday/.rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--require spec_helper
148 changes: 148 additions & 0 deletions samples/client/echo_api/ruby-faraday/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# This file is based on https://github.com/rails/rails/blob/master/.rubocop.yml (MIT license)
# Automatically generated by OpenAPI Generator (https://openapi-generator.tech)
AllCops:
TargetRubyVersion: 2.4
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
# to ignore them, so only the ones explicitly set in this file are enabled.
DisabledByDefault: true
Exclude:
- '**/templates/**/*'
- '**/vendor/**/*'
- 'actionpack/lib/action_dispatch/journey/parser.rb'

# Prefer &&/|| over and/or.
Style/AndOr:
Enabled: true

# Align `when` with `case`.
Layout/CaseIndentation:
Enabled: true

# Align comments with method definitions.
Layout/CommentIndentation:
Enabled: true

Layout/ElseAlignment:
Enabled: true

Layout/EmptyLineAfterMagicComment:
Enabled: true

# In a regular class definition, no empty lines around the body.
Layout/EmptyLinesAroundClassBody:
Enabled: true

# In a regular method definition, no empty lines around the body.
Layout/EmptyLinesAroundMethodBody:
Enabled: true

# In a regular module definition, no empty lines around the body.
Layout/EmptyLinesAroundModuleBody:
Enabled: true

Layout/FirstArgumentIndentation:
Enabled: true

# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
Style/HashSyntax:
Enabled: false

# Method definitions after `private` or `protected` isolated calls need one
# extra level of indentation.
Layout/IndentationConsistency:
Enabled: true
EnforcedStyle: indented_internal_methods

# Two spaces, no tabs (for indentation).
Layout/IndentationWidth:
Enabled: true

Layout/LeadingCommentSpace:
Enabled: true

Layout/SpaceAfterColon:
Enabled: true

Layout/SpaceAfterComma:
Enabled: true

Layout/SpaceAroundEqualsInParameterDefault:
Enabled: true

Layout/SpaceAroundKeyword:
Enabled: true

Layout/SpaceAroundOperators:
Enabled: true

Layout/SpaceBeforeComma:
Enabled: true

Layout/SpaceBeforeFirstArg:
Enabled: true

Style/DefWithParentheses:
Enabled: true

# Defining a method with parameters needs parentheses.
Style/MethodDefParentheses:
Enabled: true

Style/FrozenStringLiteralComment:
Enabled: false
EnforcedStyle: always

# Use `foo {}` not `foo{}`.
Layout/SpaceBeforeBlockBraces:
Enabled: true

# Use `foo { bar }` not `foo {bar}`.
Layout/SpaceInsideBlockBraces:
Enabled: true

# Use `{ a: 1 }` not `{a:1}`.
Layout/SpaceInsideHashLiteralBraces:
Enabled: true

Layout/SpaceInsideParens:
Enabled: true

# Check quotes usage according to lint rule below.
#Style/StringLiterals:
# Enabled: true
# EnforcedStyle: single_quotes

# Detect hard tabs, no hard tabs.
Layout/IndentationStyle:
Enabled: true

# Blank lines should not have any spaces.
Layout/TrailingEmptyLines:
Enabled: true

# No trailing whitespace.
Layout/TrailingWhitespace:
Enabled: false

# Use quotes for string literals when they are enough.
Style/RedundantPercentQ:
Enabled: true

# Align `end` with the matching keyword or starting expression except for
# assignments, where it should be aligned with the LHS.
Layout/EndAlignment:
Enabled: true
EnforcedStyleAlignWith: variable
AutoCorrect: true

# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
Lint/RequireParentheses:
Enabled: true

Style/RedundantReturn:
Enabled: true
AllowMultipleReturnValues: true

Style/Semicolon:
Enabled: true
AllowAsExpressionSeparator: true
11 changes: 11 additions & 0 deletions samples/client/echo_api/ruby-faraday/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: ruby
cache: bundler
rvm:
- 2.7
- 3.0
- 3.1
script:
- bundle install --path vendor/bundle
- bundle exec rspec
- gem build openapi_client.gemspec
- gem install ./openapi_client-1.0.0.gem
Loading

0 comments on commit 10da7a3

Please sign in to comment.