[php-nextgen] Serialize booleans in query strings as true/false by default

PA
1d ago
+166-4

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::$booleanFormatForQueryString now defaults to Configuration::BOOLEAN_FORMAT_STRING, so booleans are sent as true/false.
  • BOOLEAN_FORMAT_INT, BOOLEAN_FORMAT_STRING, the property, setBooleanFormatForQueryString() and getBooleanFormatForQueryString() are marked @deprecated since 7.27.0, to be removed in 8.0.0, when booleans will always be serialized as true/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::testBooleanFormatForQueryStringDefaultsToString checks the default in the generated Configuration.
  • The petstore sample's ObjectSerializerTest now covers:
    • true/false for boolean query params via toQueryValue(), using the default configuration
    • raw booleans and boolean arrays in buildQuery()
    • testBooleanFormatString: an explicitly set string format
    • testBooleanFormatInt: the deprecated int format still produces 1/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/0 can restore the previous behavior by calling setBooleanFormatForQueryString(Configuration::BOOLEAN_FORMAT_INT).
  • The format constants, the $booleanFormatForQueryString property, and its getter and setter are deprecated since 7.27.0 and will be removed in 8.0.0, when true/false becomes the only option.