diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java index ec90775f38a..98fd8f92217 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java @@ -245,21 +245,22 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg return packageName; } - public String toSrcPath(String packageName, String basePath) { - packageName = packageName.replace(invokerPackage, ""); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. - if (basePath != null && basePath.length() > 0) { - basePath = basePath.replaceAll("[\\\\/]?$", "") + File.separator; // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. + public String toSrcPath(final String packageName, final String basePath) { + String modifiedPackageName = packageName.replace(invokerPackage, ""); + String modifiedBasePath = basePath; + if (basePath != null && !basePath.isEmpty()) { + modifiedBasePath = basePath.replaceAll("[\\\\/]?$", "") + File.separator; } // Trim prefix file separators from package path String packagePath = StringUtils.removeStart( // Replace period, backslash, forward slash with file separator in package name - packageName.replaceAll("[\\.\\\\/]", Matcher.quoteReplacement("/")), + modifiedPackageName.replaceAll("[\\.\\\\/]", Matcher.quoteReplacement("/")), File.separator ); // Trim trailing file separators from the overall path - return StringUtils.removeEnd(basePath + packagePath, File.separator); + return StringUtils.removeEnd(modifiedBasePath + packagePath, File.separator); } @Override diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java index 7f187f1d70a..4d1fb30fa29 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java @@ -106,12 +106,12 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg importMapping.clear(); supportsInheritance = true; - srcBasePath = "."; + srcBasePath = ""; setInvokerPackage("OpenAPI\\Server"); setBundleName("OpenAPIServer"); setBundleAlias("open_api_server"); modelDirName = "Model"; - docsBasePath = "Resources" + "/" + "docs"; + docsBasePath = "docs"; apiDocPath = docsBasePath + "/" + apiDirName; modelDocPath = docsBasePath + "/" + modelDirName; outputFolder = "generated-code" + File.separator + "php"; @@ -316,6 +316,9 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg additionalProperties.put("bundleExtensionName", bundleExtensionName); additionalProperties.put("bundleAlias", bundleAlias); + // add trailing slash for mustache templates + additionalProperties.put("relativeSrcBasePath", srcBasePath.isEmpty() ? "" : srcBasePath + "/"); + // make api and model src path available in mustache template additionalProperties.put("apiSrcPath", "." + "/" + toSrcPath(apiPackage, srcBasePath)); additionalProperties.put("modelSrcPath", "." + "/" + toSrcPath(modelPackage, srcBasePath)); @@ -336,11 +339,12 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg final String configDir = "Resources" + File.separator + "config"; final String dependencyInjectionDir = "DependencyInjection"; + final String compilerDir = dependencyInjectionDir + File.separator + "Compiler"; supportingFiles.add(new SupportingFile("Controller.mustache", toSrcPath(controllerPackage, srcBasePath), "Controller.php")); - supportingFiles.add(new SupportingFile("Bundle.mustache", "", bundleClassName + ".php")); - supportingFiles.add(new SupportingFile("Extension.mustache", dependencyInjectionDir, bundleExtensionName + ".php")); - supportingFiles.add(new SupportingFile("ApiPass.mustache", dependencyInjectionDir + File.separator + "Compiler", bundleName + "ApiPass.php")); + supportingFiles.add(new SupportingFile("Bundle.mustache", toSrcPath("", srcBasePath), bundleClassName + ".php")); + supportingFiles.add(new SupportingFile("Extension.mustache", toSrcPath(dependencyInjectionDir, srcBasePath), bundleExtensionName + ".php")); + supportingFiles.add(new SupportingFile("ApiPass.mustache", toSrcPath(compilerDir, srcBasePath), bundleName + "ApiPass.php")); supportingFiles.add(new SupportingFile("ApiServer.mustache", toSrcPath(apiPackage, srcBasePath), "ApiServer.php")); // Serialization components @@ -357,10 +361,10 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg supportingFiles.add(new SupportingFile("testing/phpunit.xml.mustache", "", "phpunit.xml.dist")); supportingFiles.add(new SupportingFile("testing/AppKernel.mustache", toSrcPath(testsPackage, srcBasePath), "AppKernel.php")); supportingFiles.add(new SupportingFile("testing/ControllerTest.mustache", toSrcPath(controllerTestsPackage, srcBasePath), "ControllerTest.php")); - supportingFiles.add(new SupportingFile("testing/test_config.yml", toSrcPath(testsPackage, srcBasePath), "test_config.yml")); + supportingFiles.add(new SupportingFile("testing/test_config.yml", toSrcPath(testsPackage, srcBasePath), "test_config.yaml")); - supportingFiles.add(new SupportingFile("routing.mustache", configDir, "routing.yml")); - supportingFiles.add(new SupportingFile("services.mustache", configDir, "services.yml")); + supportingFiles.add(new SupportingFile("routing.mustache", toSrcPath(configDir, srcBasePath), "routing.yaml")); + supportingFiles.add(new SupportingFile("services.mustache", toSrcPath(configDir, srcBasePath), "services.yaml")); supportingFiles.add(new SupportingFile("composer.mustache", "", "composer.json")); supportingFiles.add(new SupportingFile("autoload.mustache", "", "autoload.php")); supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); diff --git a/modules/openapi-generator/src/main/resources/php-symfony/Extension.mustache b/modules/openapi-generator/src/main/resources/php-symfony/Extension.mustache index dffd4cbb33a..43914fe6728 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/Extension.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/Extension.mustache @@ -37,7 +37,7 @@ class {{bundleExtensionName}} 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 diff --git a/modules/openapi-generator/src/main/resources/php-symfony/README.mustache b/modules/openapi-generator/src/main/resources/php-symfony/README.mustache index 7cc1cda4719..186feb62732 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/README.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/README.mustache @@ -71,7 +71,7 @@ Step 3: Register the routes: ```yaml # app/config/routes.yaml {{bundleAlias}}: - resource: "@{{bundleName}}Bundle/Resources/config/routing.yml" + resource: "@{{bundleName}}Bundle/Resources/config/routing.yaml" ``` Step 4: Implement the API calls: @@ -119,7 +119,7 @@ class {{baseName}}Api implements {{classname}} // An interface is autogenerated Step 5: Tag your API implementation: ```yaml -# config/services.yml +# config/services.yaml services: # ... Acme\MyBundle\Api\{{baseName}}Api: diff --git a/modules/openapi-generator/src/main/resources/php-symfony/api_doc.mustache b/modules/openapi-generator/src/main/resources/php-symfony/api_doc.mustache index 67bedf3ed78..e244934ae97 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/api_doc.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/api_doc.mustache @@ -11,7 +11,7 @@ Method | HTTP request | Description {{#operations}} ## Service Declaration ```yaml -# config/services.yml +# config/services.yaml services: # ... Acme\MyBundle\Api\{{baseName}}Api: diff --git a/modules/openapi-generator/src/main/resources/php-symfony/autoload.mustache b/modules/openapi-generator/src/main/resources/php-symfony/autoload.mustache index 28ce32ae50a..0171bf4bd7f 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/autoload.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/autoload.mustache @@ -6,7 +6,7 @@ * * After registering this autoload function with SPL, the following line * would cause the function to attempt to load the \{{invokerPackage}}\Baz\Qux class - * from /path/to/project/{{srcBasePath}}/Baz/Qux.php: + * from /path/to/project/{{relativeSrcBasePath}}Baz/Qux.php: * * new \{{invokerPackage}}\Baz\Qux; * @@ -20,7 +20,7 @@ spl_autoload_register(function ($class) { $prefix = '{{escapedInvokerPackage}}\\'; // base directory for the namespace prefix - $base_dir = __DIR__ . '/{{srcBasePath}}/'; + $base_dir = __DIR__ . '/{{relativeSrcBasePath}}'; // does the class use the namespace prefix? $len = strlen($prefix); diff --git a/modules/openapi-generator/src/main/resources/php-symfony/composer.mustache b/modules/openapi-generator/src/main/resources/php-symfony/composer.mustache index b337e44bb82..e4ecd72994d 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/composer.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/composer.mustache @@ -36,7 +36,7 @@ }, "autoload": { "psr-4": { - "{{escapedInvokerPackage}}\\" : "{{srcBasePath}}/" + "{{escapedInvokerPackage}}\\" : "{{relativeSrcBasePath}}" } } } diff --git a/modules/openapi-generator/src/main/resources/php-symfony/gitignore b/modules/openapi-generator/src/main/resources/php-symfony/gitignore index 3f90ef253e2..6070e9bfda9 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/gitignore +++ b/modules/openapi-generator/src/main/resources/php-symfony/gitignore @@ -18,7 +18,7 @@ !var/sessions/.gitkeep # Parameters -/app/config/parameters.yml +/app/config/parameters.yaml /app/config/parameters.ini # Managed by Composer diff --git a/modules/openapi-generator/src/main/resources/php-symfony/testing/AppKernel.mustache b/modules/openapi-generator/src/main/resources/php-symfony/testing/AppKernel.mustache index dfd5e83f1f1..acc95055796 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/testing/AppKernel.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/testing/AppKernel.mustache @@ -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'); } } diff --git a/modules/openapi-generator/src/main/resources/php-symfony/testing/test_config.yml b/modules/openapi-generator/src/main/resources/php-symfony/testing/test_config.yml index 4c7970ab71a..9cd9521cbcf 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/testing/test_config.yml +++ b/modules/openapi-generator/src/main/resources/php-symfony/testing/test_config.yml @@ -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" diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/php/PhpSymfonyServerCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/php/PhpSymfonyServerCodegenTest.java index c8bad04db1c..b5144ff7627 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/php/PhpSymfonyServerCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/php/PhpSymfonyServerCodegenTest.java @@ -17,11 +17,23 @@ package org.openapitools.codegen.php; +import java.io.File; +import java.nio.file.Files; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.openapitools.codegen.ClientOptInput; import org.openapitools.codegen.CodegenConstants; +import org.openapitools.codegen.DefaultGenerator; +import org.openapitools.codegen.TestUtils; +import org.openapitools.codegen.config.CodegenConfigurator; +import org.openapitools.codegen.languages.AbstractPhpCodegen; import org.openapitools.codegen.languages.PhpSymfonyServerCodegen; import org.testng.Assert; import org.testng.annotations.Test; + public class PhpSymfonyServerCodegenTest { @Test @@ -53,4 +65,112 @@ public class PhpSymfonyServerCodegenTest { Assert.assertEquals(codegen.isHideGenerationTimestamp(), false); } + @Test + public void testGeneratePing() throws Exception { + Map properties = new HashMap<>(); + + File output = Files.createTempDirectory("test").toFile(); + + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("php-symfony") + .setAdditionalProperties(properties) + .setInputSpec("src/test/resources/3_0/ping.yaml") + .setOutputDir(output.getAbsolutePath().replace("\\", "/")); + + final ClientOptInput clientOptInput = configurator.toClientOptInput(); + DefaultGenerator generator = new DefaultGenerator(); + List files = generator.opts(clientOptInput).generate(); + + Assert.assertEquals(files.size(), 33); + TestUtils.ensureContainsFile(files, output, ".coveralls.yml"); + TestUtils.ensureContainsFile(files, output, ".gitignore"); + TestUtils.ensureContainsFile(files, output, ".openapi-generator-ignore"); + TestUtils.ensureContainsFile(files, output, ".openapi-generator/FILES"); + TestUtils.ensureContainsFile(files, output, ".openapi-generator/VERSION"); + TestUtils.ensureContainsFile(files, output, ".php_cs.dist"); + TestUtils.ensureContainsFile(files, output, ".travis.yml"); + TestUtils.ensureContainsFile(files, output, "autoload.php"); + TestUtils.ensureContainsFile(files, output, "composer.json"); + TestUtils.ensureContainsFile(files, output, "git_push.sh"); + TestUtils.ensureContainsFile(files, output, "phpunit.xml.dist"); + TestUtils.ensureContainsFile(files, output, "README.md"); + TestUtils.ensureContainsFile(files, output, "Api/ApiServer.php"); + TestUtils.ensureContainsFile(files, output, "Api/DefaultApiInterface.php"); + TestUtils.ensureContainsFile(files, output, "Controller/Controller.php"); + TestUtils.ensureContainsFile(files, output, "Controller/DefaultController.php"); + TestUtils.ensureContainsFile(files, output, "DependencyInjection/Compiler/OpenAPIServerApiPass.php"); + TestUtils.ensureContainsFile(files, output, "DependencyInjection/OpenAPIServerExtension.php"); + TestUtils.ensureContainsFile(files, output, "docs/Api/DefaultApiInterface.md"); + TestUtils.ensureContainsFile(files, output, "OpenAPIServerBundle.php"); + TestUtils.ensureContainsFile(files, output, "Resources/config/routing.yaml"); + TestUtils.ensureContainsFile(files, output, "Resources/config/services.yaml"); + TestUtils.ensureContainsFile(files, output, "Service/JmsSerializer.php"); + TestUtils.ensureContainsFile(files, output, "Service/SerializerInterface.php"); + TestUtils.ensureContainsFile(files, output, "Service/StrictJsonDeserializationVisitor.php"); + TestUtils.ensureContainsFile(files, output, "Service/StrictJsonDeserializationVisitorFactory.php"); + TestUtils.ensureContainsFile(files, output, "Service/SymfonyValidator.php"); + TestUtils.ensureContainsFile(files, output, "Service/TypeMismatchException.php"); + TestUtils.ensureContainsFile(files, output, "Service/ValidatorInterface.php"); + TestUtils.ensureContainsFile(files, output, "Tests/Api/DefaultApiInterfaceTest.php"); + TestUtils.ensureContainsFile(files, output, "Tests/AppKernel.php"); + TestUtils.ensureContainsFile(files, output, "Tests/Controller/ControllerTest.php"); + TestUtils.ensureContainsFile(files, output, "Tests/test_config.yaml"); + + output.deleteOnExit(); + } + + @Test + public void testGeneratePingWithDifferentSourceDirectory() throws Exception { + Map properties = new HashMap<>(); + properties.put(AbstractPhpCodegen.SRC_BASE_PATH, "src"); + + File output = Files.createTempDirectory("test").toFile(); + + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("php-symfony") + .setAdditionalProperties(properties) + .setInputSpec("src/test/resources/3_0/ping.yaml") + .setOutputDir(output.getAbsolutePath().replace("\\", "/")); + + final ClientOptInput clientOptInput = configurator.toClientOptInput(); + DefaultGenerator generator = new DefaultGenerator(); + List files = generator.opts(clientOptInput).generate(); + + Assert.assertEquals(files.size(), 33); + TestUtils.ensureContainsFile(files, output, ".coveralls.yml"); + TestUtils.ensureContainsFile(files, output, ".gitignore"); + TestUtils.ensureContainsFile(files, output, ".openapi-generator-ignore"); + TestUtils.ensureContainsFile(files, output, ".openapi-generator/FILES"); + TestUtils.ensureContainsFile(files, output, ".openapi-generator/VERSION"); + TestUtils.ensureContainsFile(files, output, ".php_cs.dist"); + TestUtils.ensureContainsFile(files, output, ".travis.yml"); + TestUtils.ensureContainsFile(files, output, "autoload.php"); + TestUtils.ensureContainsFile(files, output, "composer.json"); + TestUtils.ensureContainsFile(files, output, "git_push.sh"); + TestUtils.ensureContainsFile(files, output, "phpunit.xml.dist"); + TestUtils.ensureContainsFile(files, output, "README.md"); + TestUtils.ensureContainsFile(files, output, "docs/Api/DefaultApiInterface.md"); + TestUtils.ensureContainsFile(files, output, "src/Api/ApiServer.php"); + TestUtils.ensureContainsFile(files, output, "src/Api/DefaultApiInterface.php"); + TestUtils.ensureContainsFile(files, output, "src/Controller/Controller.php"); + TestUtils.ensureContainsFile(files, output, "src/Controller/DefaultController.php"); + TestUtils.ensureContainsFile(files, output, "src/DependencyInjection/Compiler/OpenAPIServerApiPass.php"); + TestUtils.ensureContainsFile(files, output, "src/DependencyInjection/OpenAPIServerExtension.php"); + TestUtils.ensureContainsFile(files, output, "src/OpenAPIServerBundle.php"); + TestUtils.ensureContainsFile(files, output, "src/Resources/config/routing.yaml"); + TestUtils.ensureContainsFile(files, output, "src/Resources/config/services.yaml"); + TestUtils.ensureContainsFile(files, output, "src/Service/JmsSerializer.php"); + TestUtils.ensureContainsFile(files, output, "src/Service/SerializerInterface.php"); + TestUtils.ensureContainsFile(files, output, "src/Service/StrictJsonDeserializationVisitor.php"); + TestUtils.ensureContainsFile(files, output, "src/Service/StrictJsonDeserializationVisitorFactory.php"); + TestUtils.ensureContainsFile(files, output, "src/Service/SymfonyValidator.php"); + TestUtils.ensureContainsFile(files, output, "src/Service/TypeMismatchException.php"); + TestUtils.ensureContainsFile(files, output, "src/Service/ValidatorInterface.php"); + TestUtils.ensureContainsFile(files, output, "src/Tests/Api/DefaultApiInterfaceTest.php"); + TestUtils.ensureContainsFile(files, output, "src/Tests/AppKernel.php"); + TestUtils.ensureContainsFile(files, output, "src/Tests/Controller/ControllerTest.php"); + TestUtils.ensureContainsFile(files, output, "src/Tests/test_config.yaml"); + + output.deleteOnExit(); + } } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/.gitignore b/samples/server/petstore/php-symfony/SymfonyBundle-php/.gitignore index 3f90ef253e2..6070e9bfda9 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/.gitignore +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/.gitignore @@ -18,7 +18,7 @@ !var/sessions/.gitkeep # Parameters -/app/config/parameters.yml +/app/config/parameters.yaml /app/config/parameters.ini # Managed by Composer diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/.openapi-generator/FILES b/samples/server/petstore/php-symfony/SymfonyBundle-php/.openapi-generator/FILES index 6c8bb72be2c..e1b272ff1e1 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/.openapi-generator/FILES +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/.openapi-generator/FILES @@ -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 diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/DependencyInjection/OpenAPIServerExtension.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/DependencyInjection/OpenAPIServerExtension.php index 02bd9b82fc8..f964670958c 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/DependencyInjection/OpenAPIServerExtension.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/DependencyInjection/OpenAPIServerExtension.php @@ -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 diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/README.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/README.md index c89ec4ed4fd..08ffab23264 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/README.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/README.md @@ -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 diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/config/routing.yml b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/config/routing.yaml similarity index 100% rename from samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/config/routing.yml rename to samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/config/routing.yaml diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/config/services.yml b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/config/services.yaml similarity index 100% rename from samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/config/services.yml rename to samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/config/services.yaml diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/AppKernel.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/AppKernel.php index 608b63fdc09..2ce8342f343 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/AppKernel.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/AppKernel.php @@ -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'); } } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/test_config.yml b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/test_config.yaml similarity index 68% rename from samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/test_config.yml rename to samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/test_config.yaml index 4c7970ab71a..9cd9521cbcf 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/test_config.yml +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/test_config.yaml @@ -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" diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/autoload.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/autoload.php index b3f278620a2..9a070af6107 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/autoload.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/autoload.php @@ -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); diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/composer.json b/samples/server/petstore/php-symfony/SymfonyBundle-php/composer.json index 7683bf2cc88..3641be84330 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/composer.json +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/composer.json @@ -33,7 +33,7 @@ }, "autoload": { "psr-4": { - "OpenAPI\\Server\\" : "./" + "OpenAPI\\Server\\" : "" } } } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Api/PetApiInterface.md similarity index 99% rename from samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md rename to samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Api/PetApiInterface.md index 7b690ea767b..6912d640301 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Api/PetApiInterface.md @@ -16,7 +16,7 @@ Method | HTTP request | Description ## Service Declaration ```yaml -# config/services.yml +# config/services.yaml services: # ... Acme\MyBundle\Api\PetApi: diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Api/StoreApiInterface.md similarity index 99% rename from samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md rename to samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Api/StoreApiInterface.md index f7c5893d0d0..c9aedf55e38 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Api/StoreApiInterface.md @@ -12,7 +12,7 @@ Method | HTTP request | Description ## Service Declaration ```yaml -# config/services.yml +# config/services.yaml services: # ... Acme\MyBundle\Api\StoreApi: diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Api/UserApiInterface.md similarity index 99% rename from samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md rename to samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Api/UserApiInterface.md index 24eb29aa6bb..2c7e3ba2626 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Api/UserApiInterface.md @@ -16,7 +16,7 @@ Method | HTTP request | Description ## Service Declaration ```yaml -# config/services.yml +# config/services.yaml services: # ... Acme\MyBundle\Api\UserApi: diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/ApiResponse.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Model/ApiResponse.md similarity index 100% rename from samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/ApiResponse.md rename to samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Model/ApiResponse.md diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/Category.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Model/Category.md similarity index 100% rename from samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/Category.md rename to samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Model/Category.md diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/Order.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Model/Order.md similarity index 100% rename from samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/Order.md rename to samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Model/Order.md diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/Pet.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Model/Pet.md similarity index 100% rename from samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/Pet.md rename to samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Model/Pet.md diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/Tag.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Model/Tag.md similarity index 100% rename from samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/Tag.md rename to samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Model/Tag.md diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/User.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Model/User.md similarity index 100% rename from samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/User.md rename to samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Model/User.md diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/phpunit.xml.dist b/samples/server/petstore/php-symfony/SymfonyBundle-php/phpunit.xml.dist index a12d3c3c870..01645d7450c 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/phpunit.xml.dist +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/phpunit.xml.dist @@ -9,9 +9,9 @@ xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> - ././Api - ././Model - ././Controller + ./Api + ./Model + ./Controller