[php] replace $collectionFormat with $style (#5517)

* php - remove $collectionFormat

* update php openapi3 petstore sample
This commit is contained in:
William Cheng 2020-03-04 15:54:44 +08:00 committed by GitHub
parent 3e5fb670e2
commit 6db09f40be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 24 additions and 32 deletions

View File

@ -16,23 +16,15 @@
package org.openapitools.codegen.languages; package org.openapitools.codegen.languages;
import io.swagger.v3.oas.models.Operation; import org.openapitools.codegen.CliOption;
import io.swagger.v3.oas.models.security.SecurityScheme; import org.openapitools.codegen.CodegenConstants;
import io.swagger.v3.oas.models.servers.Server; import org.openapitools.codegen.SupportingFile;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.*;
import org.openapitools.codegen.meta.GeneratorMetadata; import org.openapitools.codegen.meta.GeneratorMetadata;
import org.openapitools.codegen.meta.Stability; import org.openapitools.codegen.meta.Stability;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File; 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 { public class PhpSlim4ServerCodegen extends PhpSlimServerCodegen {
private static final Logger LOGGER = LoggerFactory.getLogger(PhpSlim4ServerCodegen.class); private static final Logger LOGGER = LoggerFactory.getLogger(PhpSlim4ServerCodegen.class);

View File

@ -34,7 +34,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.*; import java.util.*;
import static org.openapitools.codegen.utils.StringUtils.*; import static org.openapitools.codegen.utils.StringUtils.camelize;
public class PhpSlimServerCodegen extends AbstractPhpCodegen { public class PhpSlimServerCodegen extends AbstractPhpCodegen {
private static final Logger LOGGER = LoggerFactory.getLogger(PhpSlimServerCodegen.class); private static final Logger LOGGER = LoggerFactory.getLogger(PhpSlimServerCodegen.class);
@ -241,7 +241,7 @@ public class PhpSlimServerCodegen extends AbstractPhpCodegen {
.replace("\\/", "/")) .replace("\\/", "/"))
.replaceAll("[\\t\\n\\r]", " ") .replaceAll("[\\t\\n\\r]", " ")
.replace("\\", "\\\\")); .replace("\\", "\\\\"));
// .replace("\"", "\\\"")); // .replace("\"", "\\\""));
// from AbstractPhpCodegen.java // from AbstractPhpCodegen.java
// Trim the string to avoid leading and trailing spaces. // Trim the string to avoid leading and trailing spaces.

View File

@ -96,7 +96,7 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg
SchemaSupportFeature.Polymorphism SchemaSupportFeature.Polymorphism
) )
); );
// clear import mapping (from default generator) as php does not use it // clear import mapping (from default generator) as php does not use it
// at the moment // at the moment
importMapping.clear(); importMapping.clear();

View File

@ -337,7 +337,7 @@ public class PhpZendExpressivePathHandlerServerCodegen extends AbstractPhpCodege
op.httpMethod = httpMethodDeclaration; op.httpMethod = httpMethodDeclaration;
//Producing content with media type "*/*" is not supported //Producing content with media type "*/*" is not supported
if (op.produces != null) { if (op.produces != null) {
for (Map<String, String> p: op.produces) { for (Map<String, String> p : op.produces) {
if (p.replace("mediaType", "*/*", "n/a")) { if (p.replace("mediaType", "*/*", "n/a")) {
LOGGER.warn("Media type range '*/*' is not supported, using 'n/a' for code generation instead"); LOGGER.warn("Media type range '*/*' is not supported, using 'n/a' for code generation instead");
} }

View File

@ -203,7 +203,7 @@ class ObjectSerializer
* Serialize an array to a string. * Serialize an array to a string.
* *
* @param array $collection collection to serialize 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) * ssv, tsv, pipes, multi)
* @param bool $allowCollectionFormatMulti allow collection format to be a multidimensional array * @param bool $allowCollectionFormatMulti allow collection format to be a multidimensional array
* *
@ -211,7 +211,7 @@ class ObjectSerializer
*/ */
public static function serializeCollection(array $collection, $style, $allowCollectionFormatMulti = false) 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 // http_build_query() almost does the job for us. We just
// need to fix the result of multidimensional arrays. // need to fix the result of multidimensional arrays.
return preg_replace('/%5B[0-9]+%5D=/', '=', http_build_query($collection, '', '&')); return preg_replace('/%5B[0-9]+%5D=/', '=', http_build_query($collection, '', '&'));

View File

@ -2677,7 +2677,7 @@ class FakeApi
// query params // query params
if (is_array($enum_query_string_array)) { 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) { if ($enum_query_string_array !== null) {
$queryParams['enum_query_string_array'] = $enum_query_string_array; $queryParams['enum_query_string_array'] = $enum_query_string_array;
@ -3761,7 +3761,7 @@ class FakeApi
// query params // query params
if (is_array($pipe)) { if (is_array($pipe)) {
$pipe = ObjectSerializer::serializeCollection($pipe, 'csv', true); $pipe = ObjectSerializer::serializeCollection($pipe, 'form', true);
} }
if ($pipe !== null) { if ($pipe !== null) {
$queryParams['pipe'] = $pipe; $queryParams['pipe'] = $pipe;
@ -3779,7 +3779,7 @@ class FakeApi
// query params // query params
if (is_array($http)) { if (is_array($http)) {
$http = ObjectSerializer::serializeCollection($http, 'space', true); $http = ObjectSerializer::serializeCollection($http, 'spaceDelimited', true);
} }
if ($http !== null) { if ($http !== null) {
$queryParams['http'] = $http; $queryParams['http'] = $http;
@ -3788,7 +3788,7 @@ class FakeApi
// query params // query params
if (is_array($url)) { if (is_array($url)) {
$url = ObjectSerializer::serializeCollection($url, 'csv', true); $url = ObjectSerializer::serializeCollection($url, 'form', true);
} }
if ($url !== null) { if ($url !== null) {
$queryParams['url'] = $url; $queryParams['url'] = $url;

View File

@ -778,7 +778,7 @@ class PetApi
// query params // query params
if (is_array($status)) { if (is_array($status)) {
$status = ObjectSerializer::serializeCollection($status, 'csv', true); $status = ObjectSerializer::serializeCollection($status, 'form', true);
} }
if ($status !== null) { if ($status !== null) {
$queryParams['status'] = $status; $queryParams['status'] = $status;
@ -1056,7 +1056,7 @@ class PetApi
// query params // query params
if (is_array($tags)) { if (is_array($tags)) {
$tags = ObjectSerializer::serializeCollection($tags, 'csv', true); $tags = ObjectSerializer::serializeCollection($tags, 'form', true);
} }
if ($tags !== null) { if ($tags !== null) {
$queryParams['tags'] = $tags; $queryParams['tags'] = $tags;

View File

@ -213,7 +213,7 @@ class ObjectSerializer
* Serialize an array to a string. * Serialize an array to a string.
* *
* @param array $collection collection to serialize 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) * ssv, tsv, pipes, multi)
* @param bool $allowCollectionFormatMulti allow collection format to be a multidimensional array * @param bool $allowCollectionFormatMulti allow collection format to be a multidimensional array
* *
@ -221,7 +221,7 @@ class ObjectSerializer
*/ */
public static function serializeCollection(array $collection, $style, $allowCollectionFormatMulti = false) 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 // http_build_query() almost does the job for us. We just
// need to fix the result of multidimensional arrays. // need to fix the result of multidimensional arrays.
return preg_replace('/%5B[0-9]+%5D=/', '=', http_build_query($collection, '', '&')); return preg_replace('/%5B[0-9]+%5D=/', '=', http_build_query($collection, '', '&'));

View File

@ -3778,7 +3778,7 @@ class FakeApi
// query params // query params
if (is_array($ioutil)) { if (is_array($ioutil)) {
$ioutil = ObjectSerializer::serializeCollection($ioutil, 'csv', true); $ioutil = ObjectSerializer::serializeCollection($ioutil, 'form', true);
} }
if ($ioutil !== null) { if ($ioutil !== null) {
$queryParams['ioutil'] = $ioutil; $queryParams['ioutil'] = $ioutil;
@ -3787,7 +3787,7 @@ class FakeApi
// query params // query params
if (is_array($http)) { if (is_array($http)) {
$http = ObjectSerializer::serializeCollection($http, 'space', true); $http = ObjectSerializer::serializeCollection($http, 'spaceDelimited', true);
} }
if ($http !== null) { if ($http !== null) {
$queryParams['http'] = $http; $queryParams['http'] = $http;
@ -3796,7 +3796,7 @@ class FakeApi
// query params // query params
if (is_array($url)) { if (is_array($url)) {
$url = ObjectSerializer::serializeCollection($url, 'csv', true); $url = ObjectSerializer::serializeCollection($url, 'form', true);
} }
if ($url !== null) { if ($url !== null) {
$queryParams['url'] = $url; $queryParams['url'] = $url;

View File

@ -804,7 +804,7 @@ class PetApi
// query params // query params
if (is_array($status)) { if (is_array($status)) {
$status = ObjectSerializer::serializeCollection($status, 'csv', true); $status = ObjectSerializer::serializeCollection($status, 'form', true);
} }
if ($status !== null) { if ($status !== null) {
$queryParams['status'] = $status; $queryParams['status'] = $status;
@ -1082,7 +1082,7 @@ class PetApi
// query params // query params
if (is_array($tags)) { if (is_array($tags)) {
$tags = ObjectSerializer::serializeCollection($tags, 'csv', true); $tags = ObjectSerializer::serializeCollection($tags, 'form', true);
} }
if ($tags !== null) { if ($tags !== null) {
$queryParams['tags'] = $tags; $queryParams['tags'] = $tags;

View File

@ -213,7 +213,7 @@ class ObjectSerializer
* Serialize an array to a string. * Serialize an array to a string.
* *
* @param array $collection collection to serialize 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) * ssv, tsv, pipes, multi)
* @param bool $allowCollectionFormatMulti allow collection format to be a multidimensional array * @param bool $allowCollectionFormatMulti allow collection format to be a multidimensional array
* *
@ -221,7 +221,7 @@ class ObjectSerializer
*/ */
public static function serializeCollection(array $collection, $style, $allowCollectionFormatMulti = false) 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 // http_build_query() almost does the job for us. We just
// need to fix the result of multidimensional arrays. // need to fix the result of multidimensional arrays.
return preg_replace('/%5B[0-9]+%5D=/', '=', http_build_query($collection, '', '&')); return preg_replace('/%5B[0-9]+%5D=/', '=', http_build_query($collection, '', '&'));