Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[php] replace $collectionFormat with $style #5517

Merged
merged 2 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,15 @@

package org.openapitools.codegen.languages;

import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.*;
import org.openapitools.codegen.CliOption;
import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.meta.GeneratorMetadata;
import org.openapitools.codegen.meta.Stability;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.*;

import static org.openapitools.codegen.utils.StringUtils.*;

public class PhpSlim4ServerCodegen extends PhpSlimServerCodegen {
private static final Logger LOGGER = LoggerFactory.getLogger(PhpSlim4ServerCodegen.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import java.net.URLEncoder;
import java.util.*;

import static org.openapitools.codegen.utils.StringUtils.*;
import static org.openapitools.codegen.utils.StringUtils.camelize;

public class PhpSlimServerCodegen extends AbstractPhpCodegen {
private static final Logger LOGGER = LoggerFactory.getLogger(PhpSlimServerCodegen.class);
Expand Down Expand Up @@ -241,7 +241,7 @@ public String encodePath(String input) {
.replace("\\/", "/"))
.replaceAll("[\\t\\n\\r]", " ")
.replace("\\", "\\\\"));
// .replace("\"", "\\\""));
// .replace("\"", "\\\""));

// from AbstractPhpCodegen.java
// Trim the string to avoid leading and trailing spaces.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public PhpSymfonyServerCodegen() {
SchemaSupportFeature.Polymorphism
)
);

// clear import mapping (from default generator) as php does not use it
// at the moment
importMapping.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
op.httpMethod = httpMethodDeclaration;
//Producing content with media type "*/*" is not supported
if (op.produces != null) {
for (Map<String, String> p: op.produces) {
for (Map<String, String> p : op.produces) {
if (p.replace("mediaType", "*/*", "n/a")) {
LOGGER.warn("Media type range '*/*' is not supported, using 'n/a' for code generation instead");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@ class ObjectSerializer
* Serialize an array to a string.
*
* @param array $collection collection to serialize to a string
* @param string $collectionFormat the format use for serialization (csv,
* @param string $style the format use for serialization (csv,
* ssv, tsv, pipes, multi)
* @param bool $allowCollectionFormatMulti allow collection format to be a multidimensional array
*
* @return string
*/
public static function serializeCollection(array $collection, $style, $allowCollectionFormatMulti = false)
{
if ($allowCollectionFormatMulti && ('multi' === $collectionFormat)) {
if ($allowCollectionFormatMulti && ('multi' === $style)) {
// http_build_query() almost does the job for us. We just
// need to fix the result of multidimensional arrays.
return preg_replace('/%5B[0-9]+%5D=/', '=', http_build_query($collection, '', '&'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2677,7 +2677,7 @@ protected function testEnumParametersRequest($enum_header_string_array = null, $

// query params
if (is_array($enum_query_string_array)) {
$enum_query_string_array = ObjectSerializer::serializeCollection($enum_query_string_array, 'csv', true);
$enum_query_string_array = ObjectSerializer::serializeCollection($enum_query_string_array, 'form', true);
}
if ($enum_query_string_array !== null) {
$queryParams['enum_query_string_array'] = $enum_query_string_array;
Expand Down Expand Up @@ -3761,7 +3761,7 @@ protected function testQueryParameterCollectionFormatRequest($pipe, $ioutil, $ht

// query params
if (is_array($pipe)) {
$pipe = ObjectSerializer::serializeCollection($pipe, 'csv', true);
$pipe = ObjectSerializer::serializeCollection($pipe, 'form', true);
}
if ($pipe !== null) {
$queryParams['pipe'] = $pipe;
Expand All @@ -3779,7 +3779,7 @@ protected function testQueryParameterCollectionFormatRequest($pipe, $ioutil, $ht

// query params
if (is_array($http)) {
$http = ObjectSerializer::serializeCollection($http, 'space', true);
$http = ObjectSerializer::serializeCollection($http, 'spaceDelimited', true);
}
if ($http !== null) {
$queryParams['http'] = $http;
Expand All @@ -3788,7 +3788,7 @@ protected function testQueryParameterCollectionFormatRequest($pipe, $ioutil, $ht

// query params
if (is_array($url)) {
$url = ObjectSerializer::serializeCollection($url, 'csv', true);
$url = ObjectSerializer::serializeCollection($url, 'form', true);
}
if ($url !== null) {
$queryParams['url'] = $url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ protected function findPetsByStatusRequest($status)

// query params
if (is_array($status)) {
$status = ObjectSerializer::serializeCollection($status, 'csv', true);
$status = ObjectSerializer::serializeCollection($status, 'form', true);
}
if ($status !== null) {
$queryParams['status'] = $status;
Expand Down Expand Up @@ -1056,7 +1056,7 @@ protected function findPetsByTagsRequest($tags)

// query params
if (is_array($tags)) {
$tags = ObjectSerializer::serializeCollection($tags, 'csv', true);
$tags = ObjectSerializer::serializeCollection($tags, 'form', true);
}
if ($tags !== null) {
$queryParams['tags'] = $tags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,15 @@ public static function toString($value)
* Serialize an array to a string.
*
* @param array $collection collection to serialize to a string
* @param string $collectionFormat the format use for serialization (csv,
* @param string $style the format use for serialization (csv,
* ssv, tsv, pipes, multi)
* @param bool $allowCollectionFormatMulti allow collection format to be a multidimensional array
*
* @return string
*/
public static function serializeCollection(array $collection, $style, $allowCollectionFormatMulti = false)
{
if ($allowCollectionFormatMulti && ('multi' === $collectionFormat)) {
if ($allowCollectionFormatMulti && ('multi' === $style)) {
// http_build_query() almost does the job for us. We just
// need to fix the result of multidimensional arrays.
return preg_replace('/%5B[0-9]+%5D=/', '=', http_build_query($collection, '', '&'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3778,7 +3778,7 @@ protected function testQueryParameterCollectionFormatRequest($pipe, $ioutil, $ht

// query params
if (is_array($ioutil)) {
$ioutil = ObjectSerializer::serializeCollection($ioutil, 'csv', true);
$ioutil = ObjectSerializer::serializeCollection($ioutil, 'form', true);
}
if ($ioutil !== null) {
$queryParams['ioutil'] = $ioutil;
Expand All @@ -3787,7 +3787,7 @@ protected function testQueryParameterCollectionFormatRequest($pipe, $ioutil, $ht

// query params
if (is_array($http)) {
$http = ObjectSerializer::serializeCollection($http, 'space', true);
$http = ObjectSerializer::serializeCollection($http, 'spaceDelimited', true);
}
if ($http !== null) {
$queryParams['http'] = $http;
Expand All @@ -3796,7 +3796,7 @@ protected function testQueryParameterCollectionFormatRequest($pipe, $ioutil, $ht

// query params
if (is_array($url)) {
$url = ObjectSerializer::serializeCollection($url, 'csv', true);
$url = ObjectSerializer::serializeCollection($url, 'form', true);
}
if ($url !== null) {
$queryParams['url'] = $url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ protected function findPetsByStatusRequest($status)

// query params
if (is_array($status)) {
$status = ObjectSerializer::serializeCollection($status, 'csv', true);
$status = ObjectSerializer::serializeCollection($status, 'form', true);
}
if ($status !== null) {
$queryParams['status'] = $status;
Expand Down Expand Up @@ -1082,7 +1082,7 @@ protected function findPetsByTagsRequest($tags)

// query params
if (is_array($tags)) {
$tags = ObjectSerializer::serializeCollection($tags, 'csv', true);
$tags = ObjectSerializer::serializeCollection($tags, 'form', true);
}
if ($tags !== null) {
$queryParams['tags'] = $tags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,15 @@ public static function toString($value)
* Serialize an array to a string.
*
* @param array $collection collection to serialize to a string
* @param string $collectionFormat the format use for serialization (csv,
* @param string $style the format use for serialization (csv,
* ssv, tsv, pipes, multi)
* @param bool $allowCollectionFormatMulti allow collection format to be a multidimensional array
*
* @return string
*/
public static function serializeCollection(array $collection, $style, $allowCollectionFormatMulti = false)
{
if ($allowCollectionFormatMulti && ('multi' === $collectionFormat)) {
if ($allowCollectionFormatMulti && ('multi' === $style)) {
// http_build_query() almost does the job for us. We just
// need to fix the result of multidimensional arrays.
return preg_replace('/%5B[0-9]+%5D=/', '=', http_build_query($collection, '', '&'));
Expand Down