forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Ruby] add
useAutoload
option to use autoload instead of require (O…
…penAPITools#13153) * [Ruby] Use Ruby autoload to lower memory usage and load times Fixes OpenAPITools#12648 Requiring all models up front can be very expensive in both time and memory if there are many models. In an example client with 6000 models, this would consume nearly 400MB of memory and take about 7 seconds to load. This is mostly unnecessary as most users of the client library will only actually use a small percentage of the library. The changes in this commit use Ruby's autoload capability to defer the loading until the constant is actually used. In that same example client with 6000 models, when initially requiring the library, the memory usage dropped to ~20MB and loaded in 0.3 seconds. As the constants are loaded on-demand, the memory would increase towards that 400MB ceiling, but if only a few constants are actually used, then memory will never actually hit that ceiling. An additional side effect of using Ruby's autoload is that the order of declaring the constants is not important, as Ruby will naturally load them in the correct order when they are needed. Thus, this commit obviates PR OpenAPITools#9103 and fixes OpenAPITools#4690. * add option to use autoload in ruby client * test ruby clients only * add tests * update samples * Revert "test ruby clients only" This reverts commit 0aaf71c. * update doc Co-authored-by: Jason Frey <[email protected]>
- Loading branch information
Showing
194 changed files
with
22,735 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
generatorName: ruby | ||
outputDir: samples/client/petstore/ruby-autoload | ||
library: typhoeus | ||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/ruby-client | ||
additionalProperties: | ||
gemVersion: 1.0.0 | ||
moduleName: Petstore | ||
gemName: petstore | ||
skipFormModel: "true" | ||
useAutoload: true | ||
strictSpecBehavior: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.3', '2.4', '2.5', '2.6', '2.7', '3.0'] | ||
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 | ||
|
23 changes: 23 additions & 0 deletions
23
samples/client/petstore/ruby-autoload/.openapi-generator-ignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# 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 |
128 changes: 128 additions & 0 deletions
128
samples/client/petstore/ruby-autoload/.openapi-generator/FILES
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
.gitignore | ||
.gitlab-ci.yml | ||
.rspec | ||
.rubocop.yml | ||
.travis.yml | ||
Gemfile | ||
README.md | ||
Rakefile | ||
docs/AdditionalPropertiesClass.md | ||
docs/AllOfWithSingleRef.md | ||
docs/Animal.md | ||
docs/AnotherFakeApi.md | ||
docs/ApiResponse.md | ||
docs/ArrayOfArrayOfNumberOnly.md | ||
docs/ArrayOfNumberOnly.md | ||
docs/ArrayTest.md | ||
docs/Capitalization.md | ||
docs/Cat.md | ||
docs/CatAllOf.md | ||
docs/Category.md | ||
docs/ClassModel.md | ||
docs/Client.md | ||
docs/DefaultApi.md | ||
docs/DeprecatedObject.md | ||
docs/Dog.md | ||
docs/DogAllOf.md | ||
docs/EnumArrays.md | ||
docs/EnumClass.md | ||
docs/EnumTest.md | ||
docs/FakeApi.md | ||
docs/FakeClassnameTags123Api.md | ||
docs/File.md | ||
docs/FileSchemaTestClass.md | ||
docs/Foo.md | ||
docs/FooGetDefaultResponse.md | ||
docs/FormatTest.md | ||
docs/HasOnlyReadOnly.md | ||
docs/HealthCheckResult.md | ||
docs/List.md | ||
docs/MapTest.md | ||
docs/MixedPropertiesAndAdditionalPropertiesClass.md | ||
docs/Model200Response.md | ||
docs/ModelReturn.md | ||
docs/Name.md | ||
docs/NullableClass.md | ||
docs/NumberOnly.md | ||
docs/ObjectWithDeprecatedFields.md | ||
docs/Order.md | ||
docs/OuterComposite.md | ||
docs/OuterEnum.md | ||
docs/OuterEnumDefaultValue.md | ||
docs/OuterEnumInteger.md | ||
docs/OuterEnumIntegerDefaultValue.md | ||
docs/OuterObjectWithEnumProperty.md | ||
docs/Pet.md | ||
docs/PetApi.md | ||
docs/ReadOnlyFirst.md | ||
docs/SingleRefType.md | ||
docs/SpecialModelName.md | ||
docs/StoreApi.md | ||
docs/Tag.md | ||
docs/User.md | ||
docs/UserApi.md | ||
git_push.sh | ||
lib/petstore.rb | ||
lib/petstore/api/another_fake_api.rb | ||
lib/petstore/api/default_api.rb | ||
lib/petstore/api/fake_api.rb | ||
lib/petstore/api/fake_classname_tags123_api.rb | ||
lib/petstore/api/pet_api.rb | ||
lib/petstore/api/store_api.rb | ||
lib/petstore/api/user_api.rb | ||
lib/petstore/api_client.rb | ||
lib/petstore/api_error.rb | ||
lib/petstore/configuration.rb | ||
lib/petstore/models/additional_properties_class.rb | ||
lib/petstore/models/all_of_with_single_ref.rb | ||
lib/petstore/models/animal.rb | ||
lib/petstore/models/api_response.rb | ||
lib/petstore/models/array_of_array_of_number_only.rb | ||
lib/petstore/models/array_of_number_only.rb | ||
lib/petstore/models/array_test.rb | ||
lib/petstore/models/capitalization.rb | ||
lib/petstore/models/cat.rb | ||
lib/petstore/models/cat_all_of.rb | ||
lib/petstore/models/category.rb | ||
lib/petstore/models/class_model.rb | ||
lib/petstore/models/client.rb | ||
lib/petstore/models/deprecated_object.rb | ||
lib/petstore/models/dog.rb | ||
lib/petstore/models/dog_all_of.rb | ||
lib/petstore/models/enum_arrays.rb | ||
lib/petstore/models/enum_class.rb | ||
lib/petstore/models/enum_test.rb | ||
lib/petstore/models/file.rb | ||
lib/petstore/models/file_schema_test_class.rb | ||
lib/petstore/models/foo.rb | ||
lib/petstore/models/foo_get_default_response.rb | ||
lib/petstore/models/format_test.rb | ||
lib/petstore/models/has_only_read_only.rb | ||
lib/petstore/models/health_check_result.rb | ||
lib/petstore/models/list.rb | ||
lib/petstore/models/map_test.rb | ||
lib/petstore/models/mixed_properties_and_additional_properties_class.rb | ||
lib/petstore/models/model200_response.rb | ||
lib/petstore/models/model_return.rb | ||
lib/petstore/models/name.rb | ||
lib/petstore/models/nullable_class.rb | ||
lib/petstore/models/number_only.rb | ||
lib/petstore/models/object_with_deprecated_fields.rb | ||
lib/petstore/models/order.rb | ||
lib/petstore/models/outer_composite.rb | ||
lib/petstore/models/outer_enum.rb | ||
lib/petstore/models/outer_enum_default_value.rb | ||
lib/petstore/models/outer_enum_integer.rb | ||
lib/petstore/models/outer_enum_integer_default_value.rb | ||
lib/petstore/models/outer_object_with_enum_property.rb | ||
lib/petstore/models/pet.rb | ||
lib/petstore/models/read_only_first.rb | ||
lib/petstore/models/single_ref_type.rb | ||
lib/petstore/models/special_model_name.rb | ||
lib/petstore/models/tag.rb | ||
lib/petstore/models/user.rb | ||
lib/petstore/version.rb | ||
petstore.gemspec | ||
spec/api_client_spec.rb | ||
spec/configuration_spec.rb | ||
spec/spec_helper.rb |
1 change: 1 addition & 0 deletions
1
samples/client/petstore/ruby-autoload/.openapi-generator/VERSION
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
6.1.0-SNAPSHOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--color | ||
--require spec_helper |
Oops, something went wrong.