From 448ecf7c4703d7d8770936eefceb51da8fd17d55 Mon Sep 17 00:00:00 2001 From: Eddie Chayes <35413716+eddiechayes@users.noreply.github.com> Date: Tue, 27 Feb 2024 17:26:59 -0800 Subject: [PATCH] php template changes for carbon (#596) * php template changes for carbon - support prefix in headers - support for useSecurityKeyNameAsPropertyName * run php integration tests --- .../src/main/java/com/konfigthis/api/GenerateApi.java | 3 +++ .../src/main/resources/php/Configuration.mustache | 7 +++++-- .../src/main/resources/php/api.mustache | 2 +- .../src/main/resources/php/api_key_name.mustache | 2 +- .../sdks/php-snaptrade/sdks/php/lib/Configuration.php | 2 +- .../sdks/splitit/php-splitit/php/lib/Configuration.php | 2 +- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/generator/konfig-generator-api/src/main/java/com/konfigthis/api/GenerateApi.java b/generator/konfig-generator-api/src/main/java/com/konfigthis/api/GenerateApi.java index da1dd9942..f7bbbcdbf 100644 --- a/generator/konfig-generator-api/src/main/java/com/konfigthis/api/GenerateApi.java +++ b/generator/konfig-generator-api/src/main/java/com/konfigthis/api/GenerateApi.java @@ -369,6 +369,9 @@ default Map transformAdditionalPropertiesToMap(AdditionalPropert putIfPresent(map, "useSecurityKeyNameAsPropertyName", true); putIfPresent(map, "removeDefaultConfigurationParameters", true); } + if (generator.equals("php") && existingCustomers.stream().noneMatch(packageName::contains)) { + putIfPresent(map, "useSecurityKeyNameAsPropertyName", true); + } if (additionalProperties.getObjectPropertyNamingConvention() != null) { putIfPresent(map, "useCamelCase", additionalProperties.getObjectPropertyNamingConvention().equals("camelCase")); diff --git a/generator/konfig-generator-api/src/main/resources/php/Configuration.mustache b/generator/konfig-generator-api/src/main/resources/php/Configuration.mustache index 59e02b247..9e69f4269 100644 --- a/generator/konfig-generator-api/src/main/resources/php/Configuration.mustache +++ b/generator/konfig-generator-api/src/main/resources/php/Configuration.mustache @@ -217,7 +217,10 @@ class Configuration $this->{{setter}}(${{state}}); {{/clientStateWithExamplesSetterGetterCamelCase}} {{#apiKeyMethods}} - $this->setApiKey("{{keyParamName}}", ${{> api_key_name}}); + $this->setApiKey("{{> api_key_name}}", ${{> api_key_name}}); + {{#vendorExtensions.x-konfig-prefix}} + $this->setApiKeyPrefix("{{> api_key_name}}", "{{vendorExtensions.x-konfig-prefix}}"); + {{/vendorExtensions.x-konfig-prefix}} {{/apiKeyMethods}} } @@ -598,7 +601,7 @@ class Configuration if ($prefix === null) { $keyWithPrefix = $apiKey; } else { - $keyWithPrefix = $prefix . ' ' . $apiKey; + $keyWithPrefix = $prefix . $apiKey; } return $keyWithPrefix; diff --git a/generator/konfig-generator-api/src/main/resources/php/api.mustache b/generator/konfig-generator-api/src/main/resources/php/api.mustache index c402ef013..56226ff99 100644 --- a/generator/konfig-generator-api/src/main/resources/php/api.mustache +++ b/generator/konfig-generator-api/src/main/resources/php/api.mustache @@ -792,7 +792,7 @@ use {{invokerPackage}}\ObjectSerializer; {{#authMethods}} {{#isApiKey}} // this endpoint requires API key authentication - $apiKey = $this->config->getApiKeyWithPrefix('{{keyParamName}}'); + $apiKey = $this->config->getApiKeyWithPrefix('{{> api_key_name}}'); if ($apiKey !== null) { {{#isKeyInHeader}}$headers['{{keyParamName}}'] = $apiKey;{{/isKeyInHeader}}{{#isKeyInQuery}}$queryParams['{{keyParamName}}'] = $apiKey;{{/isKeyInQuery}} } diff --git a/generator/konfig-generator-api/src/main/resources/php/api_key_name.mustache b/generator/konfig-generator-api/src/main/resources/php/api_key_name.mustache index 42385eb92..c3065bb5d 100644 --- a/generator/konfig-generator-api/src/main/resources/php/api_key_name.mustache +++ b/generator/konfig-generator-api/src/main/resources/php/api_key_name.mustache @@ -1 +1 @@ -{{^hasMultipleApiKeys}}apiKey{{/hasMultipleApiKeys}}{{#hasMultipleApiKeys}}{{{keyParamName}}}{{/hasMultipleApiKeys}} \ No newline at end of file +{{#useSecurityKeyNameAsPropertyName}}{{{nameInPascalCase}}}{{/useSecurityKeyNameAsPropertyName}}{{^useSecurityKeyNameAsPropertyName}}{{^hasMultipleApiKeys}}apiKey{{/hasMultipleApiKeys}}{{#hasMultipleApiKeys}}{{{keyParamName}}}{{/hasMultipleApiKeys}}{{/useSecurityKeyNameAsPropertyName}} \ No newline at end of file diff --git a/generator/konfig-integration-tests/sdks/php-snaptrade/sdks/php/lib/Configuration.php b/generator/konfig-integration-tests/sdks/php-snaptrade/sdks/php/lib/Configuration.php index 81750e3b6..f2be30e72 100644 --- a/generator/konfig-integration-tests/sdks/php-snaptrade/sdks/php/lib/Configuration.php +++ b/generator/konfig-integration-tests/sdks/php-snaptrade/sdks/php/lib/Configuration.php @@ -512,7 +512,7 @@ public function getApiKeyWithPrefix($apiKeyIdentifier) if ($prefix === null) { $keyWithPrefix = $apiKey; } else { - $keyWithPrefix = $prefix . ' ' . $apiKey; + $keyWithPrefix = $prefix . $apiKey; } return $keyWithPrefix; diff --git a/generator/konfig-integration-tests/sdks/splitit/php-splitit/php/lib/Configuration.php b/generator/konfig-integration-tests/sdks/splitit/php-splitit/php/lib/Configuration.php index 1f5983bbd..3a0490a56 100644 --- a/generator/konfig-integration-tests/sdks/splitit/php-splitit/php/lib/Configuration.php +++ b/generator/konfig-integration-tests/sdks/splitit/php-splitit/php/lib/Configuration.php @@ -526,7 +526,7 @@ public function getApiKeyWithPrefix($apiKeyIdentifier) if ($prefix === null) { $keyWithPrefix = $apiKey; } else { - $keyWithPrefix = $prefix . ' ' . $apiKey; + $keyWithPrefix = $prefix . $apiKey; } return $keyWithPrefix;