[php-nextgen] Serialize booleans in query strings as true/false by default
php-nextgen serializes booleans in query strings as 1/0 by default. Every other client generator sends true/false. APIs that expect true/false reject or misinterpret 1/0, so with php-nextgen users have to know about Configuration::setBooleanFormatForQueryString() before booleans are sent the way the OpenAPI spec describes them.
1/0 only became the default in #12385 because guzzlehttp/psr7 encodes booleans as 1/0, and changing it at the time would have broken existing clients.
Changes
Configuration::$booleanFormatForQueryStringnow defaults toConfiguration::BOOLEAN_FORMAT_STRING, so booleans are sent astrue/false.BOOLEAN_FORMAT_INT,BOOLEAN_FORMAT_STRING, the property,setBooleanFormatForQueryString()andgetBooleanFormatForQueryString()are marked@deprecated since 7.27.0, to be removed in 8.0.0, when booleans will always be serialized astrue/false.
Breaking change (with fallback)
Clients that rely on 1/0 can restore the previous behavior:
$config = (new Configuration())
->setBooleanFormatForQueryString(Configuration::BOOLEAN_FORMAT_INT);
$api = new SomeApi(null, $config);
// or globally
Configuration::getDefaultConfiguration()
->setBooleanFormatForQueryString(Configuration::BOOLEAN_FORMAT_INT);
The per-API configuration only takes effect together with #25311. Without #25311, only the global variant works.
Tests
PhpNextgenClientCodegenTest::testBooleanFormatForQueryStringDefaultsToStringchecks the default in the generatedConfiguration.- The petstore sample's
ObjectSerializerTestnow covers:true/falsefor boolean query params viatoQueryValue(), using the default configuration- raw booleans and boolean arrays in
buildQuery() testBooleanFormatString: an explicitly set string formattestBooleanFormatInt: the deprecated int format still produces1/0
Notes
- This PR is independent of #25311
PR checklist
- Read the contribution guidelines.
- Run the following to build the project and update samples:
./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit - If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
@jebentier @dkarlovi @mandrean @jfastnacht @ybelenko @renepardon
Summary by cubic
Changes php-nextgen to serialize booleans in query strings as true/false by default, matching every other client generator. Previously php-nextgen sent 1/0, which APIs expecting true/false would reject or misinterpret.
Migration
- Clients that rely on
1/0can restore the previous behavior by callingsetBooleanFormatForQueryString(Configuration::BOOLEAN_FORMAT_INT). - The format constants, the
$booleanFormatForQueryStringproperty, and its getter and setter are deprecated since 7.27.0 and will be removed in 8.0.0, whentrue/falsebecomes the only option.