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-symfony] Symfony6 support #11810

Merged
merged 27 commits into from
May 25, 2022
Merged
Changes from 4 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
@@ -450,7 +450,7 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
// Add operation's authentication methods to whole interface
if (op.authMethods != null) {
for (CodegenSecurity am : op.authMethods) {
if (!authMethods.contains(am)) {
if (authMethods.stream().noneMatch(m -> Objects.equals(m.name, am.name))) {
authMethods.add(am);
}
}
Original file line number Diff line number Diff line change
@@ -90,15 +90,15 @@ class {{baseName}}Api implements {{classname}} // An interface is autogenerated
/**
* Configure API key authorization: {{{name}}}
*/
public function set_api_key_auth($apiKey)
public function set{{name}}($apiKey)
{
// Retrieve logged in user from $apiKey ...
}
{{/isApiKey}}{{#isOAuth}}
/**
* Configure OAuth2 access token for authorization: {{{name}}}
*/
public function set_oAuth_auth($oauthToken)
public function set{{name}}($oauthToken)
{
// Retrieve logged in user from $oauthToken ...
}
Original file line number Diff line number Diff line change
@@ -36,13 +36,13 @@ interface {{classname}}
{{#authMethods}}

/**
* Sets authentication method {{#isBasic}}basic{{/isBasic}}{{#isApiKey}}api_key{{/isApiKey}}{{#isOAuth}}oAuth{{/isOAuth}}
* Sets authentication method {{name}}
*
* @param string $value Value of the {{#isBasic}}basic{{/isBasic}}{{#isApiKey}}api_key{{/isApiKey}}{{#isOAuth}}oAuth{{/isOAuth}} authentication method.
* @param string $value Value of the {{name}} authentication method.
*
* @return void
*/
public function set_{{#isBasic}}basic{{/isBasic}}{{#isApiKey}}api_key{{/isApiKey}}{{#isOAuth}}oAuth{{/isOAuth}}_auth($value);
public function set{{name}}($value);
{{/authMethods}}
{{#operation}}

Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ class {{controllerName}} extends Controller
{{/returnType}}
// Handle authentication
{{#authMethods}}
// Authentication '{{#isBasic}}basic{{/isBasic}}{{#isApiKey}}api_key{{/isApiKey}}{{#isOAuth}}oAuth{{/isOAuth}}' required
// Authentication '{{name}}' required
{{#isApiKey}}
{{#isKeyInHeader}}
// Set key with prefix in header
@@ -168,8 +168,8 @@ class {{controllerName}} extends Controller
$handler = $this->getApiHandler();

{{#authMethods}}
// Set authentication method '{{#isBasic}}basic{{/isBasic}}{{#isApiKey}}api_key{{/isApiKey}}{{#isOAuth}}oAuth{{/isOAuth}}'
$handler->set_{{#isBasic}}basic{{/isBasic}}{{#isApiKey}}api_key{{/isApiKey}}{{#isOAuth}}oAuth{{/isOAuth}}_auth($security{{name}});
// Set authentication method '{{name}}'
$handler->set{{name}}($security{{name}});
{{/authMethods}}

// Make the call to the business logic
Original file line number Diff line number Diff line change
@@ -43,15 +43,15 @@ class {{baseName}}Api implements {{classname}}
/**
* Configure API key authorization: {{{name}}}
*/
public function set_api_key_auth($apiKey)
public function set{{name}}($apiKey)
{
// Retrieve logged in user from $apiKey ...
}
{{/isApiKey}}{{#isOAuth}}
/**
* Configure OAuth2 access token for authorization: {{{name}}}
*/
public function set_oAuth_auth($oauthToken)
public function set{{name}}($oauthToken)
{
// Retrieve logged in user from $oauthToken ...
}
Original file line number Diff line number Diff line change
@@ -53,15 +53,6 @@ interface PetApiInterface
*/
public function setpetstore_auth($value);

/**
* Sets authentication method petstore_auth
*
* @param string $value Value of the petstore_auth authentication method.
*
* @return void
*/
public function setpetstore_auth($value);

/**
* Sets authentication method api_key
*
29 changes: 11 additions & 18 deletions samples/server/petstore/php-symfony/SymfonyBundle-php/README.md
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ This [Symfony](https://symfony.com/) bundle is automatically generated by the [O

## Requirements

PHP 8.1.1 and later
PHP 8.0 and later

## Installation & Usage

@@ -45,26 +45,20 @@ composer install

Step 1: Please follow the [installation procedure](#installation--usage) first.

Step 2: Enable the bundle in the kernel:
Step 2: Enable the bundle in the bundle configuration:

```php
<?php
// app/AppKernel.php

public function registerBundles()
{
$bundles = array(
// ...
new OpenAPI\Server\OpenAPIServerBundle(),
// ...
);
}
// app/config/bundles.php
return [
// ...
OpenAPI\Server\OpenAPIServerBundle::class => ['all' => true],
];
```

Step 3: Register the routes:

```yaml
# app/config/routing.yml
# app/config/routes.yaml
open_api_server:
resource: "@OpenAPIServerBundle/Resources/config/routing.yml"
```
@@ -93,7 +87,7 @@ class PetApi implements PetApiInterface // An interface is autogenerated
/**
* Implementation of PetApiInterface#addPet
*/
public function addPet(Pet $pet): array|\OpenAPI\Server\Model\Pet
public function addPet(Pet $pet, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Pet
{
// Implement the operation ...
}
@@ -105,11 +99,10 @@ class PetApi implements PetApiInterface // An interface is autogenerated
Step 5: Tag your API implementation:

```yaml
# src/Acme/MyBundle/Resources/services.yml
# config/services.yml
services:
# ...
acme.my_bundle.api.pet:
class: Acme\MyBundle\Api\PetApi
Acme\MyBundle\Api\PetApi:
tags:
- { name: "open_api_server.api", api: "pet" }
# ...
Original file line number Diff line number Diff line change
@@ -16,11 +16,10 @@ Method | HTTP request | Description

## Service Declaration
```yaml
# src/Acme/MyBundle/Resources/services.yml
# config/services.yml
services:
# ...
acme.my_bundle.api.pet:
class: Acme\MyBundle\Api\PetApi
Acme\MyBundle\Api\PetApi:
tags:
- { name: "open_api_server.api", api: "pet" }
# ...
@@ -56,7 +55,7 @@ class PetApi implements PetApiInterface
/**
* Implementation of PetApiInterface#addPet
*/
public function addPet(Pet $pet): array|\OpenAPI\Server\Model\Pet
public function addPet(Pet $pet, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Pet
{
// Implement the operation ...
}
@@ -116,7 +115,7 @@ class PetApi implements PetApiInterface
/**
* Implementation of PetApiInterface#deletePet
*/
public function deletePet($petId, $apiKey = null): array|void
public function deletePet($petId, $apiKey = null, &$responseCode, array &$responseHeaders): void
{
// Implement the operation ...
}
@@ -179,7 +178,7 @@ class PetApi implements PetApiInterface
/**
* Implementation of PetApiInterface#findPetsByStatus
*/
public function findPetsByStatus(array $status): iterable
public function findPetsByStatus(array $status, &$responseCode, array &$responseHeaders): iterable
{
// Implement the operation ...
}
@@ -241,7 +240,7 @@ class PetApi implements PetApiInterface
/**
* Implementation of PetApiInterface#findPetsByTags
*/
public function findPetsByTags(array $tags): iterable
public function findPetsByTags(array $tags, &$responseCode, array &$responseHeaders): iterable
{
// Implement the operation ...
}
@@ -303,7 +302,7 @@ class PetApi implements PetApiInterface
/**
* Implementation of PetApiInterface#getPetById
*/
public function getPetById($petId): array|\OpenAPI\Server\Model\Pet
public function getPetById($petId, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Pet
{
// Implement the operation ...
}
@@ -363,7 +362,7 @@ class PetApi implements PetApiInterface
/**
* Implementation of PetApiInterface#updatePet
*/
public function updatePet(Pet $pet): array|\OpenAPI\Server\Model\Pet
public function updatePet(Pet $pet, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Pet
{
// Implement the operation ...
}
@@ -423,7 +422,7 @@ class PetApi implements PetApiInterface
/**
* Implementation of PetApiInterface#updatePetWithForm
*/
public function updatePetWithForm($petId, $name = null, $status = null): array|void
public function updatePetWithForm($petId, $name = null, $status = null, &$responseCode, array &$responseHeaders): void
{
// Implement the operation ...
}
@@ -485,7 +484,7 @@ class PetApi implements PetApiInterface
/**
* Implementation of PetApiInterface#uploadFile
*/
public function uploadFile($petId, $additionalMetadata = null, UploadedFile $file = null): array|\OpenAPI\Server\Model\ApiResponse
public function uploadFile($petId, $additionalMetadata = null, UploadedFile $file = null, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\ApiResponse
{
// Implement the operation ...
}
Original file line number Diff line number Diff line change
@@ -12,11 +12,10 @@ Method | HTTP request | Description

## Service Declaration
```yaml
# src/Acme/MyBundle/Resources/services.yml
# config/services.yml
services:
# ...
acme.my_bundle.api.store:
class: Acme\MyBundle\Api\StoreApi
Acme\MyBundle\Api\StoreApi:
tags:
- { name: "open_api_server.api", api: "store" }
# ...
@@ -46,7 +45,7 @@ class StoreApi implements StoreApiInterface
/**
* Implementation of StoreApiInterface#deleteOrder
*/
public function deleteOrder($orderId): array|void
public function deleteOrder($orderId, &$responseCode, array &$responseHeaders): void
{
// Implement the operation ...
}
@@ -108,7 +107,7 @@ class StoreApi implements StoreApiInterface
/**
* Implementation of StoreApiInterface#getInventory
*/
public function getInventory(): array|\int
public function getInventory(, &$responseCode, array &$responseHeaders): array|\int
{
// Implement the operation ...
}
@@ -159,7 +158,7 @@ class StoreApi implements StoreApiInterface
/**
* Implementation of StoreApiInterface#getOrderById
*/
public function getOrderById($orderId): array|\OpenAPI\Server\Model\Order
public function getOrderById($orderId, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Order
{
// Implement the operation ...
}
@@ -211,7 +210,7 @@ class StoreApi implements StoreApiInterface
/**
* Implementation of StoreApiInterface#placeOrder
*/
public function placeOrder(Order $order): array|\OpenAPI\Server\Model\Order
public function placeOrder(Order $order, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Order
{
// Implement the operation ...
}
Original file line number Diff line number Diff line change
@@ -16,11 +16,10 @@ Method | HTTP request | Description

## Service Declaration
```yaml
# src/Acme/MyBundle/Resources/services.yml
# config/services.yml
services:
# ...
acme.my_bundle.api.user:
class: Acme\MyBundle\Api\UserApi
Acme\MyBundle\Api\UserApi:
tags:
- { name: "open_api_server.api", api: "user" }
# ...
@@ -58,7 +57,7 @@ class UserApi implements UserApiInterface
/**
* Implementation of UserApiInterface#createUser
*/
public function createUser(User $user): array|void
public function createUser(User $user, &$responseCode, array &$responseHeaders): void
{
// Implement the operation ...
}
@@ -118,7 +117,7 @@ class UserApi implements UserApiInterface
/**
* Implementation of UserApiInterface#createUsersWithArrayInput
*/
public function createUsersWithArrayInput(array $user): array|void
public function createUsersWithArrayInput(array $user, &$responseCode, array &$responseHeaders): void
{
// Implement the operation ...
}
@@ -178,7 +177,7 @@ class UserApi implements UserApiInterface
/**
* Implementation of UserApiInterface#createUsersWithListInput
*/
public function createUsersWithListInput(array $user): array|void
public function createUsersWithListInput(array $user, &$responseCode, array &$responseHeaders): void
{
// Implement the operation ...
}
@@ -240,7 +239,7 @@ class UserApi implements UserApiInterface
/**
* Implementation of UserApiInterface#deleteUser
*/
public function deleteUser($username): array|void
public function deleteUser($username, &$responseCode, array &$responseHeaders): void
{
// Implement the operation ...
}
@@ -292,7 +291,7 @@ class UserApi implements UserApiInterface
/**
* Implementation of UserApiInterface#getUserByName
*/
public function getUserByName($username): array|\OpenAPI\Server\Model\User
public function getUserByName($username, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\User
{
// Implement the operation ...
}
@@ -344,7 +343,7 @@ class UserApi implements UserApiInterface
/**
* Implementation of UserApiInterface#loginUser
*/
public function loginUser($username, $password): array|\string
public function loginUser($username, $password, &$responseCode, array &$responseHeaders): array|\string
{
// Implement the operation ...
}
@@ -405,7 +404,7 @@ class UserApi implements UserApiInterface
/**
* Implementation of UserApiInterface#logoutUser
*/
public function logoutUser(): array|void
public function logoutUser(, &$responseCode, array &$responseHeaders): void
{
// Implement the operation ...
}
@@ -464,7 +463,7 @@ class UserApi implements UserApiInterface
/**
* Implementation of UserApiInterface#updateUser
*/
public function updateUser($username, User $user): array|void
public function updateUser($username, User $user, &$responseCode, array &$responseHeaders): void
{
// Implement the operation ...
}