From 3d7a01952411a8c9276ebcdb2c0943fd1df97c4e Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 24 Oct 2018 13:56:24 +0800 Subject: [PATCH] update samples and reenable ensure-up-to-date (#1304) --- CI/circle_parallel.sh | 2 +- docs/generators/lua.md | 2 +- samples/client/petstore/ruby/README.md | 3 + .../client/petstore/ruby/docs/DefaultApi.md | 47 +++++ samples/client/petstore/ruby/docs/Foo.md | 8 + .../ruby/docs/InlineResponseDefault.md | 8 + samples/client/petstore/ruby/lib/petstore.rb | 3 + .../ruby/lib/petstore/api/default_api.rb | 66 +++++++ .../petstore/ruby/lib/petstore/models/foo.rb | 185 ++++++++++++++++++ .../models/inline_response_default.rb | 183 +++++++++++++++++ .../ruby/spec/api/default_api_spec.rb | 44 +++++ .../petstore/ruby/spec/models/foo_spec.rb | 41 ++++ .../models/inline_response_default_spec.rb | 41 ++++ 13 files changed, 631 insertions(+), 2 deletions(-) create mode 100644 samples/client/petstore/ruby/docs/DefaultApi.md create mode 100644 samples/client/petstore/ruby/docs/Foo.md create mode 100644 samples/client/petstore/ruby/docs/InlineResponseDefault.md create mode 100644 samples/client/petstore/ruby/lib/petstore/api/default_api.rb create mode 100644 samples/client/petstore/ruby/lib/petstore/models/foo.rb create mode 100644 samples/client/petstore/ruby/lib/petstore/models/inline_response_default.rb create mode 100644 samples/client/petstore/ruby/spec/api/default_api_spec.rb create mode 100644 samples/client/petstore/ruby/spec/models/foo_spec.rb create mode 100644 samples/client/petstore/ruby/spec/models/inline_response_default_spec.rb diff --git a/CI/circle_parallel.sh b/CI/circle_parallel.sh index 51d81a2afaf..cda481a62fd 100755 --- a/CI/circle_parallel.sh +++ b/CI/circle_parallel.sh @@ -15,7 +15,7 @@ elif [ "$NODE_INDEX" = "2" ]; then java -version #export GO_POST_PROCESS_FILE="/usr/local/bin/gofmt -w" # not formatting the code as different go versions may format the code a bit different - #./bin/utils/ensure-up-to-date + ./bin/utils/ensure-up-to-date else echo "Running node $NODE_INDEX to test 'samples.circleci.jdk7' defined in pom.xml ..." sudo update-java-alternatives -s java-1.7.0-openjdk-amd64 diff --git a/docs/generators/lua.md b/docs/generators/lua.md index d35fb4f2cd3..baf2a6d5544 100644 --- a/docs/generators/lua.md +++ b/docs/generators/lua.md @@ -2,7 +2,7 @@ CONFIG OPTIONS for lua packageName - Lua package name (convention: lowercase). (Default: openapir-client) + Lua package name (convention: single word). (Default: openapiclient) packageVersion Lua package version. (Default: 1.0.0-1) diff --git a/samples/client/petstore/ruby/README.md b/samples/client/petstore/ruby/README.md index 0bc344953b2..68720d86002 100644 --- a/samples/client/petstore/ruby/README.md +++ b/samples/client/petstore/ruby/README.md @@ -74,6 +74,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- *Petstore::AnotherFakeApi* | [**call_123_test_special_tags**](docs/AnotherFakeApi.md#call_123_test_special_tags) | **PATCH** /another-fake/dummy | To test special tags +*Petstore::DefaultApi* | [**foo_get**](docs/DefaultApi.md#foo_get) | **GET** /foo | *Petstore::FakeApi* | [**fake_outer_boolean_serialize**](docs/FakeApi.md#fake_outer_boolean_serialize) | **POST** /fake/outer/boolean | *Petstore::FakeApi* | [**fake_outer_composite_serialize**](docs/FakeApi.md#fake_outer_composite_serialize) | **POST** /fake/outer/composite | *Petstore::FakeApi* | [**fake_outer_number_serialize**](docs/FakeApi.md#fake_outer_number_serialize) | **POST** /fake/outer/number | @@ -129,8 +130,10 @@ Class | Method | HTTP request | Description - [Petstore::EnumTest](docs/EnumTest.md) - [Petstore::File](docs/File.md) - [Petstore::FileSchemaTestClass](docs/FileSchemaTestClass.md) + - [Petstore::Foo](docs/Foo.md) - [Petstore::FormatTest](docs/FormatTest.md) - [Petstore::HasOnlyReadOnly](docs/HasOnlyReadOnly.md) + - [Petstore::InlineResponseDefault](docs/InlineResponseDefault.md) - [Petstore::List](docs/List.md) - [Petstore::MapTest](docs/MapTest.md) - [Petstore::MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md) diff --git a/samples/client/petstore/ruby/docs/DefaultApi.md b/samples/client/petstore/ruby/docs/DefaultApi.md new file mode 100644 index 00000000000..d7d2a57f285 --- /dev/null +++ b/samples/client/petstore/ruby/docs/DefaultApi.md @@ -0,0 +1,47 @@ +# Petstore::DefaultApi + +All URIs are relative to *http://petstore.swagger.io:80/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**foo_get**](DefaultApi.md#foo_get) | **GET** /foo | + + +# **foo_get** +> InlineResponseDefault foo_get + + + +### Example +```ruby +# load the gem +require 'petstore' + +api_instance = Petstore::DefaultApi.new + +begin + result = api_instance.foo_get + p result +rescue Petstore::ApiError => e + puts "Exception when calling DefaultApi->foo_get: #{e}" +end +``` + +### Parameters +This endpoint does not need any parameter. + +### Return type + +[**InlineResponseDefault**](InlineResponseDefault.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/json + + + diff --git a/samples/client/petstore/ruby/docs/Foo.md b/samples/client/petstore/ruby/docs/Foo.md new file mode 100644 index 00000000000..3dd099f1593 --- /dev/null +++ b/samples/client/petstore/ruby/docs/Foo.md @@ -0,0 +1,8 @@ +# Petstore::Foo + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**bar** | **String** | | [optional] [default to 'bar'] + + diff --git a/samples/client/petstore/ruby/docs/InlineResponseDefault.md b/samples/client/petstore/ruby/docs/InlineResponseDefault.md new file mode 100644 index 00000000000..96b4ac89b74 --- /dev/null +++ b/samples/client/petstore/ruby/docs/InlineResponseDefault.md @@ -0,0 +1,8 @@ +# Petstore::InlineResponseDefault + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**string** | [**Foo**](Foo.md) | | [optional] + + diff --git a/samples/client/petstore/ruby/lib/petstore.rb b/samples/client/petstore/ruby/lib/petstore.rb index d5d034f8f3f..98e4c4b7f6e 100644 --- a/samples/client/petstore/ruby/lib/petstore.rb +++ b/samples/client/petstore/ruby/lib/petstore.rb @@ -35,8 +35,10 @@ require 'petstore/models/enum_class' require 'petstore/models/enum_test' require 'petstore/models/file' require 'petstore/models/file_schema_test_class' +require 'petstore/models/foo' require 'petstore/models/format_test' require 'petstore/models/has_only_read_only' +require 'petstore/models/inline_response_default' require 'petstore/models/list' require 'petstore/models/map_test' require 'petstore/models/mixed_properties_and_additional_properties_class' @@ -56,6 +58,7 @@ require 'petstore/models/user' # APIs require 'petstore/api/another_fake_api' +require 'petstore/api/default_api' require 'petstore/api/fake_api' require 'petstore/api/fake_classname_tags123_api' require 'petstore/api/pet_api' diff --git a/samples/client/petstore/ruby/lib/petstore/api/default_api.rb b/samples/client/petstore/ruby/lib/petstore/api/default_api.rb new file mode 100644 index 00000000000..32255daa98c --- /dev/null +++ b/samples/client/petstore/ruby/lib/petstore/api/default_api.rb @@ -0,0 +1,66 @@ +=begin +#OpenAPI Petstore + +#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + +OpenAPI spec version: 1.0.0 + +Generated by: https://openapi-generator.tech +OpenAPI Generator version: 3.3.2-SNAPSHOT + +=end + +require 'uri' + +module Petstore + class DefaultApi + attr_accessor :api_client + + def initialize(api_client = ApiClient.default) + @api_client = api_client + end + # @param [Hash] opts the optional parameters + # @return [InlineResponseDefault] + def foo_get(opts = {}) + data, _status_code, _headers = foo_get_with_http_info(opts) + data + end + + # @param [Hash] opts the optional parameters + # @return [Array<(InlineResponseDefault, Fixnum, Hash)>] InlineResponseDefault data, response status code and response headers + def foo_get_with_http_info(opts = {}) + if @api_client.config.debugging + @api_client.config.logger.debug 'Calling API: DefaultApi.foo_get ...' + end + # resource path + local_var_path = '/foo' + + # query parameters + query_params = {} + + # header parameters + header_params = {} + # HTTP header 'Accept' (if needed) + header_params['Accept'] = @api_client.select_header_accept(['application/json']) + + # form parameters + form_params = {} + + # http body (model) + post_body = nil + auth_names = [] + data, status_code, headers = @api_client.call_api(:GET, local_var_path, + :header_params => header_params, + :query_params => query_params, + :form_params => form_params, + :body => post_body, + :auth_names => auth_names, + :return_type => 'InlineResponseDefault') + if @api_client.config.debugging + @api_client.config.logger.debug "API called: DefaultApi#foo_get\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" + end + return data, status_code, headers + end + + end +end diff --git a/samples/client/petstore/ruby/lib/petstore/models/foo.rb b/samples/client/petstore/ruby/lib/petstore/models/foo.rb new file mode 100644 index 00000000000..a8fc05cf0e6 --- /dev/null +++ b/samples/client/petstore/ruby/lib/petstore/models/foo.rb @@ -0,0 +1,185 @@ +=begin +#OpenAPI Petstore + +#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + +OpenAPI spec version: 1.0.0 + +Generated by: https://openapi-generator.tech +OpenAPI Generator version: 3.3.2-SNAPSHOT + +=end + +require 'date' + +module Petstore + class Foo + attr_accessor :bar + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'bar' => :'bar' + } + end + + # Attribute type mapping. + def self.openapi_types + { + :'bar' => :'String' + } + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + return unless attributes.is_a?(Hash) + + # convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v } + + if attributes.has_key?(:'bar') + self.bar = attributes[:'bar'] + else + self.bar = 'bar' + end + end + + # Show invalid properties with the reasons. Usually used together with valid? + # @return Array for valid properties with the reasons + def list_invalid_properties + invalid_properties = Array.new + invalid_properties + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + def valid? + true + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(o) + return true if self.equal?(o) + self.class == o.class && + bar == o.bar + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(o) + self == o + end + + # Calculates hash code according to all attributes. + # @return [Fixnum] Hash code + def hash + [bar].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + self.class.openapi_types.each_pair do |key, type| + if type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the the attribute + # is documented as an array but the input is not + if attributes[self.class.attribute_map[key]].is_a?(Array) + self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) + end + elsif !attributes[self.class.attribute_map[key]].nil? + self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) + end # or else data not found in attributes(hash), not an issue as the data can be optional + end + + self + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def _deserialize(type, value) + case type.to_sym + when :DateTime + DateTime.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :BOOLEAN + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + else # model + temp_model = Petstore.const_get(type).new + temp_model.build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + next if value.nil? + hash[param] = _to_hash(value) + end + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to? :to_hash + value.to_hash + else + value + end + end + end +end diff --git a/samples/client/petstore/ruby/lib/petstore/models/inline_response_default.rb b/samples/client/petstore/ruby/lib/petstore/models/inline_response_default.rb new file mode 100644 index 00000000000..60d14ae0646 --- /dev/null +++ b/samples/client/petstore/ruby/lib/petstore/models/inline_response_default.rb @@ -0,0 +1,183 @@ +=begin +#OpenAPI Petstore + +#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + +OpenAPI spec version: 1.0.0 + +Generated by: https://openapi-generator.tech +OpenAPI Generator version: 3.3.2-SNAPSHOT + +=end + +require 'date' + +module Petstore + class InlineResponseDefault + attr_accessor :string + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'string' => :'string' + } + end + + # Attribute type mapping. + def self.openapi_types + { + :'string' => :'Foo' + } + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + return unless attributes.is_a?(Hash) + + # convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v } + + if attributes.has_key?(:'string') + self.string = attributes[:'string'] + end + end + + # Show invalid properties with the reasons. Usually used together with valid? + # @return Array for valid properties with the reasons + def list_invalid_properties + invalid_properties = Array.new + invalid_properties + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + def valid? + true + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(o) + return true if self.equal?(o) + self.class == o.class && + string == o.string + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(o) + self == o + end + + # Calculates hash code according to all attributes. + # @return [Fixnum] Hash code + def hash + [string].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + self.class.openapi_types.each_pair do |key, type| + if type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the the attribute + # is documented as an array but the input is not + if attributes[self.class.attribute_map[key]].is_a?(Array) + self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) + end + elsif !attributes[self.class.attribute_map[key]].nil? + self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) + end # or else data not found in attributes(hash), not an issue as the data can be optional + end + + self + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def _deserialize(type, value) + case type.to_sym + when :DateTime + DateTime.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :BOOLEAN + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + else # model + temp_model = Petstore.const_get(type).new + temp_model.build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + next if value.nil? + hash[param] = _to_hash(value) + end + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to? :to_hash + value.to_hash + else + value + end + end + end +end diff --git a/samples/client/petstore/ruby/spec/api/default_api_spec.rb b/samples/client/petstore/ruby/spec/api/default_api_spec.rb new file mode 100644 index 00000000000..7783f719c56 --- /dev/null +++ b/samples/client/petstore/ruby/spec/api/default_api_spec.rb @@ -0,0 +1,44 @@ +=begin +#OpenAPI Petstore + +#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + +OpenAPI spec version: 1.0.0 + +Generated by: https://openapi-generator.tech +OpenAPI Generator version: 3.3.2-SNAPSHOT + +=end + +require 'spec_helper' +require 'json' + +# Unit tests for Petstore::DefaultApi +# Automatically generated by openapi-generator (https://openapi-generator.tech) +# Please update as you see appropriate +describe 'DefaultApi' do + before do + # run before each test + @instance = Petstore::DefaultApi.new + end + + after do + # run after each test + end + + describe 'test an instance of DefaultApi' do + it 'should create an instance of DefaultApi' do + expect(@instance).to be_instance_of(Petstore::DefaultApi) + end + end + + # unit tests for foo_get + # @param [Hash] opts the optional parameters + # @return [InlineResponseDefault] + describe 'foo_get test' do + it 'should work' do + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers + end + end + +end diff --git a/samples/client/petstore/ruby/spec/models/foo_spec.rb b/samples/client/petstore/ruby/spec/models/foo_spec.rb new file mode 100644 index 00000000000..1d9f2c551bc --- /dev/null +++ b/samples/client/petstore/ruby/spec/models/foo_spec.rb @@ -0,0 +1,41 @@ +=begin +#OpenAPI Petstore + +#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + +OpenAPI spec version: 1.0.0 + +Generated by: https://openapi-generator.tech +OpenAPI Generator version: 3.3.2-SNAPSHOT + +=end + +require 'spec_helper' +require 'json' +require 'date' + +# Unit tests for Petstore::Foo +# Automatically generated by openapi-generator (https://openapi-generator.tech) +# Please update as you see appropriate +describe 'Foo' do + before do + # run before each test + @instance = Petstore::Foo.new + end + + after do + # run after each test + end + + describe 'test an instance of Foo' do + it 'should create an instance of Foo' do + expect(@instance).to be_instance_of(Petstore::Foo) + end + end + describe 'test attribute "bar"' do + it 'should work' do + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers + end + end + +end diff --git a/samples/client/petstore/ruby/spec/models/inline_response_default_spec.rb b/samples/client/petstore/ruby/spec/models/inline_response_default_spec.rb new file mode 100644 index 00000000000..ccbb8fcaaaf --- /dev/null +++ b/samples/client/petstore/ruby/spec/models/inline_response_default_spec.rb @@ -0,0 +1,41 @@ +=begin +#OpenAPI Petstore + +#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + +OpenAPI spec version: 1.0.0 + +Generated by: https://openapi-generator.tech +OpenAPI Generator version: 3.3.2-SNAPSHOT + +=end + +require 'spec_helper' +require 'json' +require 'date' + +# Unit tests for Petstore::InlineResponseDefault +# Automatically generated by openapi-generator (https://openapi-generator.tech) +# Please update as you see appropriate +describe 'InlineResponseDefault' do + before do + # run before each test + @instance = Petstore::InlineResponseDefault.new + end + + after do + # run after each test + end + + describe 'test an instance of InlineResponseDefault' do + it 'should create an instance of InlineResponseDefault' do + expect(@instance).to be_instance_of(Petstore::InlineResponseDefault) + end + end + describe 'test attribute "string"' do + it 'should work' do + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers + end + end + +end