[PHP-Symfony] Encurage Symfony 5 bundle directory structure best practices (#13014)

* use .yaml instead of .yml

This is recommended by Symfony standards

* save Bundle files also to src path

* add test for generate ping

* add package imports

* fix expected file names

* why is Api/ApiServer.php missing

* output filenames

* use getAbsolutePath for debug purpose

* do not use punctuation as current directory

* refactor: remove todos

* use also .yaml in test to fix it

* add test for setting a different source directory

* use correct const for setting source dir property in tests

* import the AbstractPhpCodegen in test class

* put also Resources to source path

* save docs not to Resources

* update samples and improve src path in autoload.php and composer.json

* update moved samples
This commit is contained in:
Luka Dschaak
2022-09-18 09:16:27 +02:00
committed by GitHub
parent 43375b9392
commit c4a3866e75
31 changed files with 204 additions and 79 deletions

View File

@@ -18,7 +18,7 @@
!var/sessions/.gitkeep
# Parameters
/app/config/parameters.yml
/app/config/parameters.yaml
/app/config/parameters.ini
# Managed by Composer

View File

@@ -20,17 +20,8 @@ Model/Tag.php
Model/User.php
OpenAPIServerBundle.php
README.md
Resources/config/routing.yml
Resources/config/services.yml
Resources/docs/Api/PetApiInterface.md
Resources/docs/Api/StoreApiInterface.md
Resources/docs/Api/UserApiInterface.md
Resources/docs/Model/ApiResponse.md
Resources/docs/Model/Category.md
Resources/docs/Model/Order.md
Resources/docs/Model/Pet.md
Resources/docs/Model/Tag.md
Resources/docs/Model/User.md
Resources/config/routing.yaml
Resources/config/services.yaml
Service/JmsSerializer.php
Service/SerializerInterface.php
Service/StrictJsonDeserializationVisitor.php
@@ -40,8 +31,17 @@ Service/TypeMismatchException.php
Service/ValidatorInterface.php
Tests/AppKernel.php
Tests/Controller/ControllerTest.php
Tests/test_config.yml
Tests/test_config.yaml
autoload.php
composer.json
docs/Api/PetApiInterface.md
docs/Api/StoreApiInterface.md
docs/Api/UserApiInterface.md
docs/Model/ApiResponse.md
docs/Model/Category.md
docs/Model/Order.md
docs/Model/Pet.md
docs/Model/Tag.md
docs/Model/User.md
git_push.sh
phpunit.xml.dist

View File

@@ -47,7 +47,7 @@ class OpenAPIServerExtension extends Extension
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
$loader->load('services.yaml');
}
public function getAlias(): string

View File

@@ -60,7 +60,7 @@ Step 3: Register the routes:
```yaml
# app/config/routes.yaml
open_api_server:
resource: "@OpenAPIServerBundle/Resources/config/routing.yml"
resource: "@OpenAPIServerBundle/Resources/config/routing.yaml"
```
Step 4: Implement the API calls:
@@ -99,7 +99,7 @@ class PetApi implements PetApiInterface // An interface is autogenerated
Step 5: Tag your API implementation:
```yaml
# config/services.yml
# config/services.yaml
services:
# ...
Acme\MyBundle\Api\PetApi:
@@ -117,36 +117,36 @@ All URIs are relative to *http://petstore.swagger.io/v2*
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*PetApiInterface* | [**addPet**](Resources/docs/Api/PetApiInterface.md#addpet) | **POST** /pet | Add a new pet to the store
*PetApiInterface* | [**deletePet**](Resources/docs/Api/PetApiInterface.md#deletepet) | **DELETE** /pet/{petId} | Deletes a pet
*PetApiInterface* | [**findPetsByStatus**](Resources/docs/Api/PetApiInterface.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status
*PetApiInterface* | [**findPetsByTags**](Resources/docs/Api/PetApiInterface.md#findpetsbytags) | **GET** /pet/findByTags | Finds Pets by tags
*PetApiInterface* | [**getPetById**](Resources/docs/Api/PetApiInterface.md#getpetbyid) | **GET** /pet/{petId} | Find pet by ID
*PetApiInterface* | [**updatePet**](Resources/docs/Api/PetApiInterface.md#updatepet) | **PUT** /pet | Update an existing pet
*PetApiInterface* | [**updatePetWithForm**](Resources/docs/Api/PetApiInterface.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data
*PetApiInterface* | [**uploadFile**](Resources/docs/Api/PetApiInterface.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image
*StoreApiInterface* | [**deleteOrder**](Resources/docs/Api/StoreApiInterface.md#deleteorder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
*StoreApiInterface* | [**getInventory**](Resources/docs/Api/StoreApiInterface.md#getinventory) | **GET** /store/inventory | Returns pet inventories by status
*StoreApiInterface* | [**getOrderById**](Resources/docs/Api/StoreApiInterface.md#getorderbyid) | **GET** /store/order/{orderId} | Find purchase order by ID
*StoreApiInterface* | [**placeOrder**](Resources/docs/Api/StoreApiInterface.md#placeorder) | **POST** /store/order | Place an order for a pet
*UserApiInterface* | [**createUser**](Resources/docs/Api/UserApiInterface.md#createuser) | **POST** /user | Create user
*UserApiInterface* | [**createUsersWithArrayInput**](Resources/docs/Api/UserApiInterface.md#createuserswitharrayinput) | **POST** /user/createWithArray | Creates list of users with given input array
*UserApiInterface* | [**createUsersWithListInput**](Resources/docs/Api/UserApiInterface.md#createuserswithlistinput) | **POST** /user/createWithList | Creates list of users with given input array
*UserApiInterface* | [**deleteUser**](Resources/docs/Api/UserApiInterface.md#deleteuser) | **DELETE** /user/{username} | Delete user
*UserApiInterface* | [**getUserByName**](Resources/docs/Api/UserApiInterface.md#getuserbyname) | **GET** /user/{username} | Get user by user name
*UserApiInterface* | [**loginUser**](Resources/docs/Api/UserApiInterface.md#loginuser) | **GET** /user/login | Logs user into the system
*UserApiInterface* | [**logoutUser**](Resources/docs/Api/UserApiInterface.md#logoutuser) | **GET** /user/logout | Logs out current logged in user session
*UserApiInterface* | [**updateUser**](Resources/docs/Api/UserApiInterface.md#updateuser) | **PUT** /user/{username} | Updated user
*PetApiInterface* | [**addPet**](docs/Api/PetApiInterface.md#addpet) | **POST** /pet | Add a new pet to the store
*PetApiInterface* | [**deletePet**](docs/Api/PetApiInterface.md#deletepet) | **DELETE** /pet/{petId} | Deletes a pet
*PetApiInterface* | [**findPetsByStatus**](docs/Api/PetApiInterface.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status
*PetApiInterface* | [**findPetsByTags**](docs/Api/PetApiInterface.md#findpetsbytags) | **GET** /pet/findByTags | Finds Pets by tags
*PetApiInterface* | [**getPetById**](docs/Api/PetApiInterface.md#getpetbyid) | **GET** /pet/{petId} | Find pet by ID
*PetApiInterface* | [**updatePet**](docs/Api/PetApiInterface.md#updatepet) | **PUT** /pet | Update an existing pet
*PetApiInterface* | [**updatePetWithForm**](docs/Api/PetApiInterface.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data
*PetApiInterface* | [**uploadFile**](docs/Api/PetApiInterface.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image
*StoreApiInterface* | [**deleteOrder**](docs/Api/StoreApiInterface.md#deleteorder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
*StoreApiInterface* | [**getInventory**](docs/Api/StoreApiInterface.md#getinventory) | **GET** /store/inventory | Returns pet inventories by status
*StoreApiInterface* | [**getOrderById**](docs/Api/StoreApiInterface.md#getorderbyid) | **GET** /store/order/{orderId} | Find purchase order by ID
*StoreApiInterface* | [**placeOrder**](docs/Api/StoreApiInterface.md#placeorder) | **POST** /store/order | Place an order for a pet
*UserApiInterface* | [**createUser**](docs/Api/UserApiInterface.md#createuser) | **POST** /user | Create user
*UserApiInterface* | [**createUsersWithArrayInput**](docs/Api/UserApiInterface.md#createuserswitharrayinput) | **POST** /user/createWithArray | Creates list of users with given input array
*UserApiInterface* | [**createUsersWithListInput**](docs/Api/UserApiInterface.md#createuserswithlistinput) | **POST** /user/createWithList | Creates list of users with given input array
*UserApiInterface* | [**deleteUser**](docs/Api/UserApiInterface.md#deleteuser) | **DELETE** /user/{username} | Delete user
*UserApiInterface* | [**getUserByName**](docs/Api/UserApiInterface.md#getuserbyname) | **GET** /user/{username} | Get user by user name
*UserApiInterface* | [**loginUser**](docs/Api/UserApiInterface.md#loginuser) | **GET** /user/login | Logs user into the system
*UserApiInterface* | [**logoutUser**](docs/Api/UserApiInterface.md#logoutuser) | **GET** /user/logout | Logs out current logged in user session
*UserApiInterface* | [**updateUser**](docs/Api/UserApiInterface.md#updateuser) | **PUT** /user/{username} | Updated user
## Documentation For Models
- [ApiResponse](Resources/docs/Model/ApiResponse.md)
- [Category](Resources/docs/Model/Category.md)
- [Order](Resources/docs/Model/Order.md)
- [Pet](Resources/docs/Model/Pet.md)
- [Tag](Resources/docs/Model/Tag.md)
- [User](Resources/docs/Model/User.md)
- [ApiResponse](docs/Model/ApiResponse.md)
- [Category](docs/Model/Category.md)
- [Order](docs/Model/Order.md)
- [Pet](docs/Model/Pet.md)
- [Tag](docs/Model/Tag.md)
- [User](docs/Model/User.md)
## Documentation For Authorization

View File

@@ -24,6 +24,6 @@ class AppKernel extends Kernel
*/
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/test_config.yml');
$loader->load(__DIR__.'/test_config.yaml');
}
}

View File

@@ -1,8 +1,8 @@
imports:
- { resource: "../Resources/config/services.yml" }
- { resource: "../Resources/config/services.yaml" }
framework:
secret: "testsecret"
test: ~
router:
resource: "%kernel.project_dir%/Resources/config/routing.yml"
resource: "%kernel.project_dir%/Resources/config/routing.yaml"

View File

@@ -16,7 +16,7 @@
*
* After registering this autoload function with SPL, the following line
* would cause the function to attempt to load the \OpenAPI\Server\Baz\Qux class
* from /path/to/project/./Baz/Qux.php:
* from /path/to/project/Baz/Qux.php:
*
* new \OpenAPI\Server\Baz\Qux;
*
@@ -30,7 +30,7 @@ spl_autoload_register(function ($class) {
$prefix = 'OpenAPI\\Server\\';
// base directory for the namespace prefix
$base_dir = __DIR__ . '/./';
$base_dir = __DIR__ . '/';
// does the class use the namespace prefix?
$len = strlen($prefix);

View File

@@ -33,7 +33,7 @@
},
"autoload": {
"psr-4": {
"OpenAPI\\Server\\" : "./"
"OpenAPI\\Server\\" : ""
}
}
}

View File

@@ -16,7 +16,7 @@ Method | HTTP request | Description
## Service Declaration
```yaml
# config/services.yml
# config/services.yaml
services:
# ...
Acme\MyBundle\Api\PetApi:

View File

@@ -12,7 +12,7 @@ Method | HTTP request | Description
## Service Declaration
```yaml
# config/services.yml
# config/services.yaml
services:
# ...
Acme\MyBundle\Api\StoreApi:

View File

@@ -16,7 +16,7 @@ Method | HTTP request | Description
## Service Declaration
```yaml
# config/services.yml
# config/services.yaml
services:
# ...
Acme\MyBundle\Api\UserApi:

View File

@@ -9,9 +9,9 @@
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">././Api</directory>
<directory suffix=".php">././Model</directory>
<directory suffix=".php">././Controller</directory>
<directory suffix=".php">./Api</directory>
<directory suffix=".php">./Model</directory>
<directory suffix=".php">./Controller</directory>
</include>
</coverage>
<testsuites>