{"id":14063326,"url":"https://github.com/php-openapi/yii2-app-api","last_synced_at":"2025-04-10T04:58:33.735Z","repository":{"id":34307883,"uuid":"175403734","full_name":"php-openapi/yii2-app-api","owner":"php-openapi","description":"OpenAPI Spec to API in 3, 2, 1... done!","archived":false,"fork":false,"pushed_at":"2024-06-06T12:23:18.000Z","size":199,"stargazers_count":107,"open_issues_count":5,"forks_count":10,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-03T01:07:37.003Z","etag":null,"topics":["api","hacktoberfest","openapi","openapi3","yii2","yii2-application-template"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/php-openapi.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-03-13T11:03:55.000Z","updated_at":"2025-03-31T06:04:57.000Z","dependencies_parsed_at":"2023-12-19T02:21:15.097Z","dependency_job_id":"9d430032-b773-4f07-9691-2099b3da191d","html_url":"https://github.com/php-openapi/yii2-app-api","commit_stats":{"total_commits":55,"total_committers":2,"mean_commits":27.5,"dds":"0.036363636363636376","last_synced_commit":"da802e5346a7cedae3596a4b57113cee6113c7e3"},"previous_names":["php-openapi/yii2-app-api","cebe/yii2-app-api"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-openapi%2Fyii2-app-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-openapi%2Fyii2-app-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-openapi%2Fyii2-app-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-openapi%2Fyii2-app-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-openapi","download_url":"https://codeload.github.com/php-openapi/yii2-app-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161265,"owners_count":21057554,"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":["api","hacktoberfest","openapi","openapi3","yii2","yii2-application-template"],"created_at":"2024-08-13T07:03:16.524Z","updated_at":"2025-04-10T04:58:33.709Z","avatar_url":"https://github.com/php-openapi.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# yii2-app-api\n\n\u003e OpenAPI Spec to API in 3, 2, 1... done!\n\nYii Framework Application Template for quickly building API-first applications.\n\nBased on [yii2-openapi](https://github.com/php-openapi/yii2-openapi) (code generator) and [php-openapi](https://github.com/php-openapi/php-openapi) (specification reader and validator).\n\n[![Latest Stable Version](https://poser.pugx.org/php-openapi/yii2-app-api/v/stable)](https://packagist.org/packages/php-openapi/yii2-app-api)\n[![Total Downloads](https://poser.pugx.org/php-openapi/yii2-app-api/downloads)](https://packagist.org/packages/php-openapi/yii2-app-api)\n[![License](https://poser.pugx.org/php-openapi/yii2-app-api/license)](https://packagist.org/packages/php-openapi/yii2-app-api)\n\n\n## Demo\n\n[![asciicast](https://asciinema.org/a/GSnZFeL0beAwLvbhIn50oVI9w.svg)](https://asciinema.org/a/GSnZFeL0beAwLvbhIn50oVI9w)\n\n\n## Overview\n\nThis application template does not contain any useful code, it only provides the [directory structure](#structure) for your API project. \nAll the code is generated from an [OpenAPI](https://www.openapis.org/about) API description file.\n\nWhen working with this template you follow the [API Design-First Approach](https://apisyouwonthate.com/blog/api-design-first-vs-code-first).\nSo to get started building an API with this application template you need an API description first.\nIf you don't have one yet, you might want to check the following resources first: \n\n- [OpenAPI 3.0 tutorial](https://idratherbewriting.com/learnapidoc/pubapis_openapi_tutorial_overview)\n- [OpenAPI Specification Version 3.0.2](http://spec.openapis.org/oas/v3.0.2) \n\nIf you have an OpenAPI description, you can continue with the next steps:\n\n1. [Setup](#setup)\n2. [Generate Code](#generate-code)\n\nMore Docs and Guides can be found in [/docs](/docs/README.md).\n\n## Setup \u003cspan id=\"setup\"\u003e\u003c/span\u003e\n\nThere are two different ways:\n\n- PHP directly on your machine\n- Using Docker\n\n### PHP directly\n\nHaving PHP and a database server installed on your machine, you can run the following commands:\n\n    composer create-project php-openapi/yii2-app-api my-api\n    cd my-api\n    cp env.php.dist env.php\n    cp config/components-ENV.local.php config/components-dev.local.php\n\nYou need to adjust `config/components-dev.local.php` to configure your database connection.\n\nAfter that, run `make start` and `make stop` to control the PHP webservers for API and backend.\n\nYou may use `XDEBUGW=1` to enable xdebug for the webserver, e.g. `make XDEBUGW=1 start`.\n\nYou can now continue with [generating code](#generate-code).\n\n### Using Docker\n\nYou need [Docker](https://docs.docker.com/install/) and [Docker Compose](https://docs.docker.com/compose/install/) installed.\n\nCreate the repository:\n\n    composer create-project php-openapi/yii2-app-api my-api\n\nFor the easiest way you need GNU make, then run:\n\n    make start-docker\n    \nThis uses `docker-compose` to start docker containers for the API and the backend including a database.\n\nYou can now continue with [generating code](#generate-code).\n\n\u003e Note: If you don't have GNU make, you need to copy the configuration files as in the PHP directly section, then run:\n\u003e \n\u003e     cp docker-compose.override.dist.yml docker-compose.override.yml\n\u003e     docker-compose up -d\n\u003e     docker-compose exec backend-php sh -c 'cd /app \u0026\u0026 composer install'\n\n\n## Generate Code \u003cspan id=\"generate-code\"\u003e\u003c/span\u003e\n\nAt this point you can start generating your API code to play with it by following the instructions below.\nIf you'd like to start a real project instead of just playing around you can find more detailed\ndocumentation in [docs/README.md](docs/README.md) specifically the [\"Getting Started\"-Section](docs/getting-started.md).\n\n### Console\n\n\u003e Tip: If you use Docker, run `make cli` before running any of these commands.\n\nRun `./yii gii/api` to generate your API code. The `--openApiPath` parameter specifies the path to your OpenAPI\nspec file. The following example will generate API code for the [OpenAPI petstore example](https://github.com/OAI/OpenAPI-Specification/blob/3.0.2/examples/v3.0/petstore-expanded.yaml).\n\n    ./yii gii/api --openApiPath=https://raw.githubusercontent.com/OAI/OpenAPI-Specification/3.0.2/examples/v3.0/petstore-expanded.yaml\n\n\u003e Note: If the OpenAPI spec file is present locally on the file system, then `openApiPath` must be specified as an absolute path, relative paths will not work correctly.\n\u003e On UNIX based OS it must start with `/`. Example: `/home/user/documents/MyProjectOpenAPISpec.yml`\n\nRun `./yii gii/api --help` for a list of configuration options. You may also adjust the configuration in `config/gii-generators.php`.\n\nThen set up the database:\n\n    ./yii migrate/up\n    ./yii faker\n\n### Web\n\nTo use the web generator, open \u003chttp://localhost:8338/gii\u003e and select the `REST API Generator`.\n\n![Gii - REST API Generator](docs/img/gii-generator.png)\n\nEnter the path or URL to the \"OpenAPI 3 Spec file\", e.g. `https://raw.githubusercontent.com/OAI/OpenAPI-Specification/3.0.2/examples/v3.0/petstore-expanded.yaml`.\n\nClick \"Preview\":\n\n![Gii - REST API Generator - Generated files](docs/img/gii-generator-files.png)\n\nClick \"Generate\" to generate API files.\n\nThen set up the database by running the following commands on the command line:\n\n    ./yii migrate/up\n    ./yii faker\n\n## Try it\n\n    cd api\n    make start\n\nYour API is now available at `http://localhost:8337/`. Try to access an endpoint of your spec via `curl`:\n\n    $ curl http://localhost:8337/pets\n    [\n        {\n            \"name\": \"Eos rerum modi et quaerat voluptatibus.\",\n            \"tag\": \"Totam in commodi in est nisi nihil aut et.\"\n        },\n        {\n            \"name\": \"Voluptas quia eos nisi deleniti itaque aspernatur aspernatur.\",\n            \"tag\": \"Temporibus id culpa dolorem sequi aut.\"\n        },\n        {\n            \"name\": \"Facere aut similique laboriosam omnis perferendis et.\",\n            \"tag\": \"Quo harum quo et ea distinctio non quam.\"\n        },\n        ...\n    ]\n\n\n## Linting the OpenAPI specification\n\nYou can run a linter to check the validity of your OpenAPI specification file:\n\n    make lint-js  # run spectral lint\n    make lint-php # run php-openapi validate\n    make lint     # run both of the above commands\n\nYou can find more information on spectral at \u003chttps://www.npmjs.com/package/@stoplight/spectral-cli#-documentation-and-community\u003e.\n\n\n## Application structure \u003cspan id=\"structure\"\u003e\u003c/span\u003e\n\nThis application template consists of 3 application tiers:\n\n- `api`, contains the Yii application for the REST API.\n- `console`, contains the Yii application for console commands, cronjobs or queues (`yii` command).\n- `backend`, contains the Yii application for a CRUD backend on the API data.\n\nThe following list explains the directory structure in more detail:\n\n- `api/` - API application tier\n  - `config/` - configuration for API tier\n    - `url-rules.php` - custom URL rules\n    - `url-rules.rest.php` - URL rules **generated** from OpenAPI Description\n    - `components.php` - application components\n    - `app.php` - Yii application config (+ overrides for different environments `app-*.php`)\n  - `controllers/` - Controller classes **generated** from OpenAPI Description\n  - `web/` - public web directory for API application\n\n- `backend/` - Backend application tier\n  - `config/` - configuration for Backend tier\n    - `components.php` - application components\n    - `app.php` - Yii application config (+ overrides for different environments `app-*.php`)\n  - `controllers/` - Controller classes\n  - `views/` - View files\n  - `web/` - public web directory for Backend application\n\n- `common/` - common code files\n  - `models/` - model classes **generated** from OpenAPI Description\n  - `migrations/` - database migrations **generated** from OpenAPI Description\n\n- `config/` - Common configuration for all application tiers\n  - `components.php` - Yii application components (+ overrides for different environments `components-*.php`)\n  - `env.php` - Environment setup (YII_DEBUG, YII_ENV, path aliases, composer autoloader)\n  - `events.php` - Class wide event listeners\n  - `gii-generators.php` - configuration for the Gii code generator (allows to set default values for the ApiGenerator)\n  - `params.php` - Configuration for `Yii::$app-\u003eparams`\n\n- `console/` - Console application tier\n  - `config/` - configuration for Console tier\n    - `components.php` - application components\n    - `app.php` - Yii application config (+ overrides for different environments `app-*.php`)\n\n- `logs/` - log files\n- `runtime/` - temporary runtime files\n\n\n# Development\n\nBelow commands are helpful while developing this project:\n\n```bash\n./yii gii/api --openApiPath=/app/openapi/schema.yaml --generateMigrations=0  --generateControllers=0 --generateUrls=0\n\n./yii gii/api --openApiPath=/app/openapi/schema.yaml --generateMigrations=1  --generateControllers=0 --generateUrls=0 --generateModels=0 --generateModelFaker=0\n```\n\n\n# Support\n\n**Need help with your API project?**\n\nProfessional support, consulting as well as software development services are available:\n\nhttps://www.cebe.cc/en/contact\n\nDevelopment of this library is sponsored by [cebe.:cloud: \"Your Professional Deployment Platform\"](https://cebe.cloud).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-openapi%2Fyii2-app-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-openapi%2Fyii2-app-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-openapi%2Fyii2-app-api/lists"}