Skip to content

Commit 10da7a3

Browse files
authored
[Ruby] add file download tests (#17362)
* 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
1 parent dd36fa0 commit 10da7a3

File tree

156 files changed

+17233
-315
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+17233
-315
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Samples Ruby
2+
3+
on:
4+
push:
5+
paths:
6+
- 'samples/client/echo_api/ruby-httpx/**'
7+
- 'samples/client/echo_api/ruby-faraday/**'
8+
- 'samples/client/echo_api/ruby-typhoeus/**'
9+
pull_request:
10+
paths:
11+
- 'samples/client/echo_api/ruby-httpx/**'
12+
- 'samples/client/echo_api/ruby-faraday/**'
13+
- 'samples/client/echo_api/ruby-typhoeus/**'
14+
15+
jobs:
16+
build:
17+
name: Build Ruby
18+
runs-on: ubuntu-latest
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
sample:
23+
- 'samples/client/echo_api/ruby-httpx/'
24+
- 'samples/client/echo_api/ruby-faraday/'
25+
- 'samples/client/echo_api/ruby-typhoeus/'
26+
steps:
27+
- uses: actions/checkout@v4
28+
- name: Setup node.js
29+
uses: actions/setup-node@v4
30+
- name: Run echo server
31+
run: |
32+
git clone https://github.com/wing328/http-echo-server -b openapi-generator-test-server
33+
(cd http-echo-server && npm install && npm start &)
34+
- uses: actions/setup-ruby@v1
35+
with:
36+
ruby-version: 3.0
37+
bundler-cache: true
38+
- name: Install bundle
39+
working-directory: ${{ matrix.sample }}
40+
run: bundle install
41+
- name: Run rspec
42+
working-directory: ${{ matrix.sample }}
43+
run: rspec
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
generatorName: ruby
2+
outputDir: samples/client/echo_api/ruby-faraday
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/echo_api.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/ruby-client
5+
library: faraday
6+
additionalProperties:
7+
hideGenerationTimestamp: "true"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
generatorName: ruby
2+
outputDir: samples/client/echo_api/ruby-typhoeus
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/echo_api.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/ruby-client
5+
library: typhoeus
6+
additionalProperties:
7+
hideGenerationTimestamp: "true"

modules/openapi-generator/src/main/resources/ruby-client/api_client_typhoeus_partial.mustache

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,16 @@
145145
chunk.force_encoding(encoding)
146146
tempfile.write(chunk)
147147
end
148-
request.on_complete do |response|
149-
if tempfile
150-
tempfile.close
151-
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
152-
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
153-
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
154-
"explicitly with `tempfile.delete`"
155-
end
148+
# run the request to ensure the tempfile is created successfully before returning it
149+
request.run
150+
if tempfile
151+
tempfile.close
152+
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
153+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
154+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
155+
"explicitly with `tempfile.delete`"
156+
else
157+
fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
156158
end
157159

158160
tempfile
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Generated by: https://openapi-generator.tech
2+
#
3+
4+
*.gem
5+
*.rbc
6+
/.config
7+
/coverage/
8+
/InstalledFiles
9+
/pkg/
10+
/spec/reports/
11+
/spec/examples.txt
12+
/test/tmp/
13+
/test/version_tmp/
14+
/tmp/
15+
16+
## Specific to RubyMotion:
17+
.dat*
18+
.repl_history
19+
build/
20+
21+
## Documentation cache and generated files:
22+
/.yardoc/
23+
/_yardoc/
24+
/doc/
25+
/rdoc/
26+
27+
## Environment normalization:
28+
/.bundle/
29+
/vendor/bundle
30+
/lib/bundler/man/
31+
32+
# for a library or gem, you might want to ignore these files since the code is
33+
# intended to run in multiple environments; otherwise, check them in:
34+
# Gemfile.lock
35+
# .ruby-version
36+
# .ruby-gemset
37+
38+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
39+
.rvmrc
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.ruby: &ruby
2+
variables:
3+
LANG: "C.UTF-8"
4+
before_script:
5+
- ruby -v
6+
- bundle config set --local deployment true
7+
- bundle install -j $(nproc)
8+
parallel:
9+
matrix:
10+
- RUBY_VERSION: ['2.7', '3.0', '3.1']
11+
image: "ruby:$RUBY_VERSION"
12+
cache:
13+
paths:
14+
- vendor/ruby
15+
key: 'ruby-$RUBY_VERSION'
16+
17+
gem:
18+
extends: .ruby
19+
script:
20+
- bundle exec rspec
21+
- bundle exec rake build
22+
- bundle exec rake install
23+
artifacts:
24+
paths:
25+
- pkg/*.gem
26+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
24+
spec/api_client_spec.rb
25+
spec/configuration_spec.rb
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
.gitignore
2+
.gitlab-ci.yml
3+
.rspec
4+
.rubocop.yml
5+
.travis.yml
6+
Gemfile
7+
README.md
8+
Rakefile
9+
docs/AuthApi.md
10+
docs/Bird.md
11+
docs/BodyApi.md
12+
docs/Category.md
13+
docs/DataQuery.md
14+
docs/DefaultValue.md
15+
docs/FormApi.md
16+
docs/HeaderApi.md
17+
docs/NumberPropertiesOnly.md
18+
docs/PathApi.md
19+
docs/Pet.md
20+
docs/Query.md
21+
docs/QueryApi.md
22+
docs/StringEnumRef.md
23+
docs/Tag.md
24+
docs/TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.md
25+
docs/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md
26+
git_push.sh
27+
lib/openapi_client.rb
28+
lib/openapi_client/api/auth_api.rb
29+
lib/openapi_client/api/body_api.rb
30+
lib/openapi_client/api/form_api.rb
31+
lib/openapi_client/api/header_api.rb
32+
lib/openapi_client/api/path_api.rb
33+
lib/openapi_client/api/query_api.rb
34+
lib/openapi_client/api_client.rb
35+
lib/openapi_client/api_error.rb
36+
lib/openapi_client/configuration.rb
37+
lib/openapi_client/models/bird.rb
38+
lib/openapi_client/models/category.rb
39+
lib/openapi_client/models/data_query.rb
40+
lib/openapi_client/models/default_value.rb
41+
lib/openapi_client/models/number_properties_only.rb
42+
lib/openapi_client/models/pet.rb
43+
lib/openapi_client/models/query.rb
44+
lib/openapi_client/models/string_enum_ref.rb
45+
lib/openapi_client/models/tag.rb
46+
lib/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.rb
47+
lib/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.rb
48+
lib/openapi_client/version.rb
49+
openapi_client.gemspec
50+
spec/spec_helper.rb
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.2.0-SNAPSHOT
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--color
2+
--require spec_helper

0 commit comments

Comments
 (0)