diff --git a/.github/workflows/update-specs-and-client-libraries.yaml b/.github/workflows/update-specs-and-client-libraries.yaml index 1a71150a..ca91b1ec 100644 --- a/.github/workflows/update-specs-and-client-libraries.yaml +++ b/.github/workflows/update-specs-and-client-libraries.yaml @@ -69,7 +69,7 @@ jobs: python_version: ${{ steps.generator.outputs.python_urllib3_version }} ruby_version: ${{ steps.generator.outputs.ruby_faraday_version }} container: - image: openapitools/openapi-generator-cli:v7.5.0 + image: openapitools/openapi-generator-cli:v7.6.0 env: OPENAPI_GENERATOR_COMMAND: docker-entrypoint.sh BUMP_CLIENT_LIBRARY_VERSION: ${{ inputs.type-of-change }} diff --git a/generators/java/okhttp-gson/templates/SHA256SUM b/generators/java/okhttp-gson/templates/SHA256SUM index 97fd306d..0ba427de 100644 --- a/generators/java/okhttp-gson/templates/SHA256SUM +++ b/generators/java/okhttp-gson/templates/SHA256SUM @@ -1,5 +1,5 @@ 16502193337397367078434a27f67edfc6410f4c06d12db876155885d6a49394 ./README.mustache 7b635a5f3fcc4cb2ace38f0dd0ca8252a78090e592a6c35fe5a08f7bc407ef6b ./libraries/okhttp-gson/ApiClient.mustache -0e06162937a3175d59b3bdb9fa249de9888ea0d0a06cfbae543f53720ff706e5 ./libraries/okhttp-gson/oneof_model.mustache -ee73f2440b54f85d91dfd65350167639e770c0d85e75690a8f797852852ec516 ./libraries/okhttp-gson/pom.mustache +0e77feaf2d6b0818194161ac7e621189aa6e7900b45d46fa4ff1232894bb1a7a ./libraries/okhttp-gson/oneof_model.mustache +e83ff873cc6a5a7e064b4732ab4bfbb3fa32660d015b9ca1b6bdb5884335c506 ./libraries/okhttp-gson/pom.mustache diff --git a/generators/php/templates/ObjectSerializer.mustache b/generators/php/templates/ObjectSerializer.mustache index 3af36748..bfd1b836 100644 --- a/generators/php/templates/ObjectSerializer.mustache +++ b/generators/php/templates/ObjectSerializer.mustache @@ -538,22 +538,64 @@ class ObjectSerializer } /** - * Native `http_build_query` wrapper. - * @see https://www.php.net/manual/en/function.http-build-query - * - * @param array|object $data May be an array or object containing properties. - * @param string $numeric_prefix If numeric indices are used in the base array and this parameter is provided, it will be prepended to the numeric index for elements in the base array only. - * @param string|null $arg_separator arg_separator.output is used to separate arguments but may be overridden by specifying this parameter. - * @param int $encoding_type Encoding type. By default, PHP_QUERY_RFC1738. - * - * @return string - */ - public static function buildQuery( - $data, - string $numeric_prefix = '', - ?string $arg_separator = null, - int $encoding_type = \PHP_QUERY_RFC3986 - ): string { - return \GuzzleHttp\Psr7\Query::build($data, $encoding_type); + * Build a query string from an array of key value pairs. + * + * This function can use the return value of `parse()` to build a query + * string. This function does not modify the provided keys when an array is + * encountered (like `http_build_query()` would). + * + * The function is copied from https://github.com/guzzle/psr7/blob/a243f80a1ca7fe8ceed4deee17f12c1930efe662/src/Query.php#L59-L112 + * with a modification which is described in https://github.com/guzzle/psr7/pull/603 + * + * @param array $params Query string parameters. + * @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986 + * to encode using RFC3986, or PHP_QUERY_RFC1738 + * to encode using RFC1738. + */ + public static function buildQuery(array $params, $encoding = PHP_QUERY_RFC3986): string + { + if (!$params) { + return ''; + } + + if ($encoding === false) { + $encoder = function (string $str): string { + return $str; + }; + } elseif ($encoding === PHP_QUERY_RFC3986) { + $encoder = 'rawurlencode'; + } elseif ($encoding === PHP_QUERY_RFC1738) { + $encoder = 'urlencode'; + } else { + throw new \InvalidArgumentException('Invalid type'); + } + + $castBool = Configuration::BOOLEAN_FORMAT_INT == Configuration::getDefaultConfiguration()->getBooleanFormatForQueryString() + ? function ($v) { return (int) $v; } + : function ($v) { return $v ? 'true' : 'false'; }; + + $qs = ''; + foreach ($params as $k => $v) { + $k = $encoder((string) $k); + if (!is_array($v)) { + $qs .= $k; + $v = is_bool($v) ? $castBool($v) : $v; + if ($v !== null) { + $qs .= '='.$encoder((string) $v); + } + $qs .= '&'; + } else { + foreach ($v as $vv) { + $qs .= $k; + $vv = is_bool($vv) ? $castBool($vv) : $vv; + if ($vv !== null) { + $qs .= '='.$encoder((string) $vv); + } + $qs .= '&'; + } + } + } + + return $qs ? (string) substr($qs, 0, -1) : ''; } } diff --git a/generators/php/templates/SHA256SUM b/generators/php/templates/SHA256SUM index 947f82f8..1c63395d 100644 --- a/generators/php/templates/SHA256SUM +++ b/generators/php/templates/SHA256SUM @@ -1,6 +1,6 @@ bb92a3f3107664c296ebc45c75bff7c88abf8b765565f4656a05e24234cb6d67 ./Configuration.mustache -4d5302fc21ddf1cd79e009a18bcb162d7a95f850d21d67461c7beab5acc09a19 ./ObjectSerializer.mustache +557173b27efb57eeba6187b8b64963a49964ade8f5f6418bd514ece483f392dd ./ObjectSerializer.mustache 8eebaed003795c011df87fecd1f89c630dd3f23282d80e7f407f62009e2cd0ee ./README.mustache 2d94750ad5d913f8b7fbba24681c7cc1d75e96c89ec46c379e6625c825b39020 ./model_generic.mustache 37d3333c7c3dbc6f6bffe64ce076bc512a2a1e61e986738c8e023bb745168e9a ./phpunit.xml.mustache diff --git a/generators/ruby/faraday/templates/SHA256SUM b/generators/ruby/faraday/templates/SHA256SUM index d5234338..e474fcb8 100644 --- a/generators/ruby/faraday/templates/SHA256SUM +++ b/generators/ruby/faraday/templates/SHA256SUM @@ -1,6 +1,5 @@ 631eea1aeb59eff826cd4975334d66bdf7ad14d3feacdf35ed5b07f33548981e ./Gemfile.mustache 88dc22838f416232553b387453a2ebecf01d66508d8657d5313320cc03ceb6a2 ./README.mustache -3748b0448b9a3e4f899c9faf72fedd3e378f840353422e475e0ad828d78b4d64 ./api_client.mustache b9af426fa4b72082dad184722e97c61366cceab0d247b477b2834e38aa6c3411 ./configuration.mustache e66f0139c35c8b1d88c19787b2379ee9e6857ced963624c9a945ee68f3b41b2f ./gemspec.mustache diff --git a/generators/ruby/faraday/templates/api_client.mustache b/generators/ruby/faraday/templates/api_client.mustache deleted file mode 100644 index db858fff..00000000 --- a/generators/ruby/faraday/templates/api_client.mustache +++ /dev/null @@ -1,248 +0,0 @@ -=begin -{{> api_info}} -=end - -require 'date' -require 'json' -require 'logger' -require 'tempfile' -require 'time' -{{#isTyphoeus}} -require 'typhoeus' -{{/isTyphoeus}} -{{#isFaraday}} -require 'faraday' -require 'faraday/multipart' if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0') -require 'marcel' -{{/isFaraday}} -{{#isHttpx}} -require 'httpx' -require 'net/http/status' -{{/isHttpx}} - - -module {{moduleName}} - class ApiClient - # The Configuration object holding settings to be used in the API client. - attr_accessor :config - - # Defines the headers to be used in HTTP requests of all API calls by default. - # - # @return [Hash] - attr_accessor :default_headers - - # Initializes the ApiClient - # @option config [Configuration] Configuration for initializing the object, default to Configuration.default - def initialize(config = Configuration.default) - @config = config - @user_agent = "{{{httpUserAgent}}}{{^httpUserAgent}}OpenAPI-Generator/#{VERSION}/ruby{{/httpUserAgent}}" - @default_headers = { - 'Content-Type' => 'application/json', - 'User-Agent' => @user_agent - } - end - - def self.default - @@default ||= ApiClient.new - end - -{{#isTyphoeus}} -{{> api_client_typhoeus_partial}} -{{/isTyphoeus}} -{{#isFaraday}} -{{> api_client_faraday_partial}} -{{/isFaraday}} -{{#isHttpx}} -{{> api_client_httpx_partial}} -{{/isHttpx}} - # Check if the given MIME is a JSON MIME. - # JSON MIME examples: - # application/json - # application/json; charset=UTF8 - # APPLICATION/JSON - # */* - # @param [String] mime MIME - # @return [Boolean] True if the MIME is application/json - def json_mime?(mime) - {{! Modified the regex to avoid high alert - to remove in v7.6.0 }} - (mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil? - end - - # Deserialize the response to the given return type. - # - # @param [Response] response HTTP response - # @param [String] return_type some examples: "User", "Array", "Hash" - def deserialize(response, return_type) - body = response.body - return nil if body.nil? || body.empty? - - # return response body directly for String return type - return body.to_s if return_type == 'String' - - # ensuring a default content type - content_type = response.headers['Content-Type'] || 'application/json' - - fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type) - - begin - data = JSON.parse("[#{body}]", :symbolize_names => true)[0] - rescue JSON::ParserError => e - if %w(String Date Time).include?(return_type) - data = body - else - raise e - end - end - - convert_to_type data, return_type - end - - # Convert data to the given return type. - # @param [Object] data Data to be converted - # @param [String] return_type Return type - # @return [Mixed] Data in a particular type - def convert_to_type(data, return_type) - return nil if data.nil? - case return_type - when 'String' - data.to_s - when 'Integer' - data.to_i - when 'Float' - data.to_f - when 'Boolean' - data == true - when 'Time' - # parse date time (expecting ISO 8601 format) - Time.parse data - when 'Date' - # parse date time (expecting ISO 8601 format) - Date.parse data - when 'Object' - # generic object (usually a Hash), return directly - data - when /\AArray<(.+)>\z/ - # e.g. Array - sub_type = $1 - data.map { |item| convert_to_type(item, sub_type) } - when /\AHash\\z/ - # e.g. Hash - sub_type = $1 - {}.tap do |hash| - data.each { |k, v| hash[k] = convert_to_type(v, sub_type) } - end - else - # models (e.g. Pet) or oneOf - klass = {{moduleName}}.const_get(return_type) - klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data) - end - end - - # Sanitize filename by removing path. - # e.g. ../../sun.gif becomes sun.gif - # - # @param [String] filename the filename to be sanitized - # @return [String] the sanitized filename - def sanitize_filename(filename) - {{! Modified the regex to avoid high alert - to remove in v7.6.0 }} - filename.split(/[\/\\]/).last - end - - def build_request_url(path, opts = {}) - # Add leading and trailing slashes to path - path = "/#{path}".gsub(/\/+/, '/') - @config.base_url(opts[:operation]) + path - end - - # Update header and query params based on authentication settings. - # - # @param [Hash] header_params Header parameters - # @param [Hash] query_params Query parameters - # @param [String] auth_names Authentication scheme name - def update_params_for_auth!(header_params, query_params, auth_names) - Array(auth_names).each do |auth_name| - auth_setting = @config.auth_settings[auth_name] - next unless auth_setting - case auth_setting[:in] - when 'header' then header_params[auth_setting[:key]] = auth_setting[:value] - when 'query' then query_params[auth_setting[:key]] = auth_setting[:value] - else fail ArgumentError, 'Authentication token must be in `query` or `header`' - end - end - end - - # Sets user agent in HTTP header - # - # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0) - def user_agent=(user_agent) - @user_agent = user_agent - @default_headers['User-Agent'] = @user_agent - end - - # Return Accept header based on an array of accepts provided. - # @param [Array] accepts array for Accept - # @return [String] the Accept header (e.g. application/json) - def select_header_accept(accepts) - return nil if accepts.nil? || accepts.empty? - # use JSON when present, otherwise use all of the provided - json_accept = accepts.find { |s| json_mime?(s) } - json_accept || accepts.join(',') - end - - # Return Content-Type header based on an array of content types provided. - # @param [Array] content_types array for Content-Type - # @return [String] the Content-Type header (e.g. application/json) - def select_header_content_type(content_types) - # return nil by default - return if content_types.nil? || content_types.empty? - # use JSON when present, otherwise use the first one - json_content_type = content_types.find { |s| json_mime?(s) } - json_content_type || content_types.first - end - - # Convert object (array, hash, object, etc) to JSON string. - # @param [Object] model object to be converted into JSON string - # @return [String] JSON string representation of the object - def object_to_http_body(model) - return model if model.nil? || model.is_a?(String) - local_body = nil - if model.is_a?(Array) - local_body = model.map { |m| object_to_hash(m) } - else - local_body = object_to_hash(model) - end - local_body.to_json - end - - # Convert object(non-array) to hash. - # @param [Object] obj object to be converted into JSON string - # @return [String] JSON string representation of the object - def object_to_hash(obj) - if obj.respond_to?(:to_hash) - obj.to_hash - else - obj - end - end - - # Build parameter value according to the given collection format. - # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi - def build_collection_param(param, collection_format) - case collection_format - when :csv - param.join(',') - when :ssv - param.join(' ') - when :tsv - param.join("\t") - when :pipes - param.join('|') - when :multi - # return the array directly as typhoeus will handle it as expected - param - else - fail "unknown collection format: #{collection_format.inspect}" - end - end - end -end diff --git a/generators/typescript-axios/templates/SHA256SUM b/generators/typescript-axios/templates/SHA256SUM index 912333cd..5ddd8a09 100644 --- a/generators/typescript-axios/templates/SHA256SUM +++ b/generators/typescript-axios/templates/SHA256SUM @@ -2,5 +2,5 @@ e13ee7c0cad9a79bab00e8b2a7942bc5a78f63115ece3dfd71a6472bdb02dd22 ./README.mustache d8d68213e1a9a9983f89f688aaf31360f69d34a871cab4fc94f59a40279b13d9 ./configuration.mustache 5030fcd1954b4d981f2d06fce4900fe29c97c7b74ee66f2eb5f45e81b9252a94 ./index.mustache -c7e61e2b36fbf70d84b75162b09b4f571466b59d0b72c7f1e3e517c6d7342622 ./package.mustache +28f5e210e99474200c8e5f13e4f2374c1556406eb71c15e808d81913000cd549 ./package.mustache 89b381b068d1849cc98721643c923ee153a5bdd69e19306dda59114ba0a2e243 ./tsconfig.mustache diff --git a/generators/typescript-axios/templates/package.mustache b/generators/typescript-axios/templates/package.mustache index 3a0c98ce..94f6812c 100644 --- a/generators/typescript-axios/templates/package.mustache +++ b/generators/typescript-axios/templates/package.mustache @@ -18,7 +18,7 @@ "identity", "verification", "api" - {{! Added keywords - NED }} + {{! Added keywords - END }} ], "license": "MIT", {{! Updated license }} "main": "./dist/index.js", @@ -62,10 +62,10 @@ "ts-jest": "^26.4.4", "dotenv": "^16.4.5", {{! Added dependencies for tests development - END }} - "@types/node": "^12.11.5", - "typescript": "^4.0" + "@types/node": "12.11.5 - 12.20.42", + "typescript": "^4.0 || ^5.0" }, - {{! Added block for package delivery }} + {{! Updated block for package delivery }} "publishConfig": { "access": "public" } diff --git a/shell/generate.sh b/shell/generate.sh index acc3c488..572e732a 100755 --- a/shell/generate.sh +++ b/shell/generate.sh @@ -10,7 +10,7 @@ COMMON_CONFIG_FILE="generators/common/config.yaml" GENERATORS=${*:-`find generators -name 'config.yaml' -exec dirname {} \; | sed 's/generators\///'`} GENERATED_CONFIG_FILES="" -OPENAPI_GENERATOR_VERSION=${OPENAPI_GENERATOR_VERSION:-v7.5.0} +OPENAPI_GENERATOR_VERSION=${OPENAPI_GENERATOR_VERSION:-v7.6.0} OPENAPI_GENERATOR_COMMAND=${OPENAPI_GENERATOR_COMMAND:-\ docker run --rm -v "$(pwd):/local" -w /local \ openapitools/openapi-generator-cli:${OPENAPI_GENERATOR_VERSION}}