{"id":15044598,"url":"https://github.com/elastic/openapi-codegen-php","last_synced_at":"2025-04-13T09:07:23.452Z","repository":{"id":34933519,"uuid":"190342406","full_name":"elastic/openapi-codegen-php","owner":"elastic","description":"Components shared across different PHP clients (Site Search, App Search, ...).","archived":false,"fork":false,"pushed_at":"2024-08-08T15:41:26.000Z","size":104,"stargazers_count":6,"open_issues_count":4,"forks_count":23,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-04-13T09:07:12.252Z","etag":null,"topics":["elastic","elastic-app-search","elastic-site-search","php","swiftype"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elastic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-05T06:58:44.000Z","updated_at":"2023-05-01T14:25:12.000Z","dependencies_parsed_at":"2024-12-16T13:27:30.681Z","dependency_job_id":"5cfc2671-2243-4baa-8e69-59fefe0c34b2","html_url":"https://github.com/elastic/openapi-codegen-php","commit_stats":{"total_commits":63,"total_committers":5,"mean_commits":12.6,"dds":0.2063492063492064,"last_synced_commit":"bcb9955b663e2d63a326938d849f766f4af507a2"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elastic%2Fopenapi-codegen-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elastic%2Fopenapi-codegen-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elastic%2Fopenapi-codegen-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elastic%2Fopenapi-codegen-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elastic","download_url":"https://codeload.github.com/elastic/openapi-codegen-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248688568,"owners_count":21145766,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elastic","elastic-app-search","elastic-site-search","php","swiftype"],"created_at":"2024-09-24T20:50:46.915Z","updated_at":"2025-04-13T09:07:23.425Z","avatar_url":"https://github.com/elastic.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Elastic OpenAPI PHP client generator.\n\n\u003cp align=\"center\"\u003e\u003ca href=\"https://circleci.com/gh/elastic/openapi-codegen-php\"\u003e\u003cimg src=\"https://circleci.com/gh/elastic/openapi-codegen-php.svg?style=svg\" alt=\"CircleCI build\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n\u003e Make easier clients creation by generating most of the code from an Open API specification.\n\u003e\n\u003e Projects using the Elastic OpenAPI PHP client generator:\n\u003e\n\u003e * [Elastic Site Search Official PHP client](https://github.com/elastic/site-search-php/)\n\u003e * [Elastic App Search Official PHP client](https://github.com/elastic/app-search-php/)\n\n\n## Contents\n\n- [Getting started](#getting-started-with-the-generator-)\n- [Using the client](#Using-the-client)\n- [FAQ](#faq-)\n- [Contribute](#contribute-)\n- [License](#license-)\n\n***\n\n## Getting started with the generator 🐣\n\n### Requirements\n\nWe assume you have the following components installed and available in your environment :\n\n\u003e * Docker (used to run the code generator)\n\u003e * composer\n\n### Initiliaze project\n\nWhen you want to create a new client you have first to create a new composer project :\n\n```bash\ncomposer create-project my-new-fancy-client\n```\n\nOnce the project is created you should pimp up your `composer.json` file (package name, author, ...).\nMake sure the autoload section contains the PHP namespace you want to use for your client (here `Fancy\\Client`):\n\n```json\n\"autoload\": {\n  \"psr-4\": {\n    \"Fancy\\\\Client\\\\\": \"\"\n  }\n}\n```\n\nOnce the project is created , you have to append the code generator as a requirement of the project:\n\n```bash\ncomposer require elastic/openapi-codegen\n```\n\n### Configuring the generator\n\nBy convention, the code generator expect the `resources/api` folder containing two files :\n\n* **`api-spec.yml`** : The OpenAPI specification that describe the server API. You can find a full featured example at : https://github.com/swiftype/swiftype-site-search-php/blob/master/resources/api/api-spec.yml\n\n* **`config.json`** : A configuration file contains important variable variables that allow to configure both code and documentation generation :\n\n```json\n{\n    \"gitUserId\": \"myorg\",\n    \"gitRepoId\": \"my-new-fancy-client\",\n    \"artifactVersion\": \"1.0.0\",\n    \"invokerPackage\": \"Fancy\\\\Client\",\n    \"helpUrl\": \"https://discuss.elastic.co/c/site-search\",\n    \"copyright\": \"© [Elastic](https://github.com/elastic)\"\n}\n```\n\n### Running the generator\n\nOnce the project is setup and the generator is configured, you can run code generation by using the launcher script from the root of your project :\n\n```\nvendor/bin/elastic-openapi-codegen.sh\n```\n\nThe generator will create or update the following files in your project :\n\n- **`Client.php`**: The client class that contains one method for each paths / operation of your specification.\n\n- **`Endpoint/*.php`**: One endpoint class for each path / operation of your specification.\n\n- **`README.md`**: The Readme of your project (see [here](#Customize-Documentation) for how to customize the documentation)\n\n### Create the client builder\n\nClient instantiation logic is very specific for each project and need to be customized for each project (authentication management, error handling). At the same time end users of your client expect a very easy to use method to instantiate the client.\n\nHere is a code for providing a very basic client builder to end users:\n\n```php\nnamespace Fancy\\Client;\n\nclass ClientBuilder extends \\Elastic\\OpenApi\\Codegen\\AbstractClientBuilder\n{\n    /**\n     * Return the configured client.\n     *\n     * @return \\Fancy\\Client\\Client\n     */\n    public function build()\n    {\n        return new Client($this-\u003egetEndpointBuilder(), $this-\u003egetConnection());\n    }\n\n    /**\n     * Endpoint builder is in charge of resolving the endpoint classes.\n     * Need to be configured with your own namespace.\n     */\n    protected function getEndpointBuilder()\n    {\n        return new \\Elastic\\OpenApi\\Codegen\\Endpoint\\Builder(__NAMESPACE__ . '\\Endpoint');\n    }\n}\n```\n\n## Using the client\n\nOnce you will have fulfilled the tasks above, it is very simple for end user to get client they can use :\n\n```php\n$clientBuilder = new \\Fancy\\Client\\ClientBuilder();\n$client = $clientBuilder-\u003ebuild();\n```\n\n### Customization\n\nNow you have a working client, there is several things that you may want to customize :\n\n- Client and Endpoint code generation\n- Documentation generation\n- Connection logic : request and response handling, authentication, ...\n\nYou can find a full documentation of available extension point in the [Customization documentation](docs/Customization.md).\n\n## FAQ 🔮\n\n### Where do I report issues with the client?\n\nIf something is not working as expected, please open an [issue](https://github.com/elastic/openapi-codegen-php/issues/new).\n\n\n## Contribute 🚀\n\nWe welcome contributors to the project. Before you begin, a couple notes...\n\n+ Before opening a pull request, please create an issue to [discuss the scope of your proposal](https://github.com/elastic/openapi-codegen-php/issues).\n+ Please write simple code and concise documentation, when appropriate.\n\n## License 📗\n\n[Apache 2.0](https://github.com/elastic/openapi-codegen-php/blob/master/LICENSE) © [Elastic](https://github.com/elastic)\n\nThank you to all the [contributors](https://github.com/elastic/openapi-codegen-php/graphs/contributors)!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felastic%2Fopenapi-codegen-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felastic%2Fopenapi-codegen-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felastic%2Fopenapi-codegen-php/lists"}