{"id":14966343,"url":"https://github.com/yiisoft/yii-swagger","last_synced_at":"2025-03-03T01:08:37.634Z","repository":{"id":37790090,"uuid":"298594453","full_name":"yiisoft/yii-swagger","owner":"yiisoft","description":"Swagger integration for Yii","archived":false,"fork":false,"pushed_at":"2024-09-04T21:55:59.000Z","size":181,"stargazers_count":30,"open_issues_count":4,"forks_count":8,"subscribers_count":18,"default_branch":"master","last_synced_at":"2024-10-29T14:35:34.795Z","etag":null,"topics":["api","hacktoberfest","openapi","swagger","swagger-ui","yii3"],"latest_commit_sha":null,"homepage":"https://www.yiiframework.com/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yiisoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"open_collective":"yiisoft","github":["yiisoft"]}},"created_at":"2020-09-25T14:21:56.000Z","updated_at":"2024-09-04T21:56:00.000Z","dependencies_parsed_at":"2024-01-11T14:15:16.649Z","dependency_job_id":"669def75-6e5f-4fe9-b0e1-6494b7a8224d","html_url":"https://github.com/yiisoft/yii-swagger","commit_stats":{"total_commits":141,"total_committers":17,"mean_commits":8.294117647058824,"dds":0.6808510638297872,"last_synced_commit":"45e0059257e5732780c8724c13a36abbf48e9a17"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":"yiisoft/package-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fyii-swagger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fyii-swagger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fyii-swagger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fyii-swagger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yiisoft","download_url":"https://codeload.github.com/yiisoft/yii-swagger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241592136,"owners_count":19987311,"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","swagger","swagger-ui","yii3"],"created_at":"2024-09-24T13:36:14.928Z","updated_at":"2025-03-03T01:08:37.573Z","avatar_url":"https://github.com/yiisoft.png","language":"PHP","funding_links":["https://opencollective.com/yiisoft","https://github.com/sponsors/yiisoft"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/yiisoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://yiisoft.github.io/docs/images/yii_logo.svg\" height=\"100px\" alt=\"Yii\"\u003e\n    \u003c/a\u003e\n    \u003ch1 align=\"center\"\u003eYii Swagger\u003c/h1\u003e\n    \u003cbr\u003e\n\u003c/p\u003e\n\n[![Latest Stable Version](https://poser.pugx.org/yiisoft/yii-swagger/v)](https://packagist.org/packages/yiisoft/yii-swagger)\n[![Total Downloads](https://poser.pugx.org/yiisoft/yii-swagger/downloads)](https://packagist.org/packages/yiisoft/yii-swagger)\n[![Build status](https://github.com/yiisoft/yii-swagger/actions/workflows/build.yml/badge.svg)](https://github.com/yiisoft/yii-swagger/actions/workflows/build.yml)\n[![Code Coverage](https://codecov.io/gh/yiisoft/yii-swagger/graph/badge.svg?token=K86U931ZRK)](https://codecov.io/gh/yiisoft/yii-swagger)\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fyii-swagger%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/yii-swagger/master)\n[![static analysis](https://github.com/yiisoft/yii-swagger/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/yii-swagger/actions?query=workflow%3A%22static+analysis%22)\n[![type-coverage](https://shepherd.dev/github/yiisoft/yii-swagger/coverage.svg)](https://shepherd.dev/github/yiisoft/yii-swagger)\n\nOpenAPI Swagger for Yii Framework.\n\n## Requirements\n\n- PHP 8.0 or higher.\n\n## Installation\n\nThe package could be installed with [Composer](https://getcomposer.org):\n\n```shell\ncomposer require yiisoft/yii-swagger\n```\n\n## Configuration\n\n### 1. Add route configuration to `config/routes.php`\n\n```php\nuse Yiisoft\\DataResponse\\Middleware\\FormatDataResponseAsHtml;\nuse Yiisoft\\DataResponse\\Middleware\\FormatDataResponseAsJson;\nuse Yiisoft\\Router\\Group;\nuse Yiisoft\\Router\\Route;\nuse Yiisoft\\Swagger\\Middleware\\SwaggerUi;\nuse Yiisoft\\Swagger\\Action\\SwaggerJson;\n\n// Swagger routes\nGroup::create('/swagger', [\n    Route::get('')\n        -\u003emiddleware(FormatDataResponseAsHtml::class)\n        -\u003eaction(fn (SwaggerUi $swaggerUi) =\u003e $swaggerUi-\u003ewithJsonUrl('/swagger/json-url')),\n    Route::get('/json-url')\n        -\u003emiddleware(FormatDataResponseAsJson::class)\n        -\u003eaction(SwaggerJson::class),\n]),\n```\n\n### 2. Add annotations to default API controller\n\n```php\nuse OpenApi\\Annotations as OA;\n\n/**\n * @OA\\Info(title=\"My first API\", version=\"1.0\")\n */\nclass DefaultController {\n    // ...\n}\n```\n\nand before actions\n\n```php\n/**\n * @OA\\Get(\n *     path=\"/api/endpoint\",\n *     @OA\\Response(response=\"200\", description=\"Get default action\")\n * )\n */\npublic function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface\n{\n    // ...\n}\n```\n\nSee [Swagger-PHP documentation](https://zircote.github.io/swagger-php/guide/annotations.html) for details\non how to annotate your code.\n\n### 3. Configure `SwaggerJson` action\n\nFor annotations to be registered you need to configure `SwaggerJson`.\n\nYou can use the parameters in `config/params.php` to configure `SwaggerJson`:\n\n```php\n//...\n'yiisoft/yii-swagger' =\u003e [\n    'annotation-paths' =\u003e [\n        '@src/Controller' // Directory where annotations are used\n    ],\n    'cacheTTL' =\u003e 60 // Enables caching and sets TTL, \"null\" value means infinite cache TTL.\n],\n//...\n```\n\n### 4. (Optional) Add config for aliases and asset manager\n\n```php\nuse Yiisoft\\Definitions\\Reference;\nuse Yiisoft\\Assets\\AssetManager;\n\nreturn [\n    //...\n    'yiisoft/aliases' =\u003e [\n        'aliases' =\u003e [\n            //...\n            '@views' =\u003e '@root/views',\n            '@assets' =\u003e '@public/assets',\n            '@assetsUrl' =\u003e '@baseUrl/assets',\n        ],\n    ],\n    'yiisoft/view' =\u003e [\n        'basePath' =\u003e '@views',\n        'defaultParameters' =\u003e [\n            'assetManager' =\u003e Reference::to(AssetManager::class),\n        ]\n    ],\n    //...\n];\n```\n\n### 5. (Optional) Configure `SwaggerUi` action\n\nYou can use the parameters in `config/params.php` to configure `SwaggerUi`.\n\nFor example, you can enable persisting authorization by setting the `persistAuthorization` parameter to `true`.\n\n```php\n//...\n'yiisoft/yii-swagger' =\u003e [\n    'ui-params' =\u003e [\n        'persistAuthorization' =\u003e true,\n    ],\n],\n//...\n```\n\nYou can find a complete list of parameters by [following the link](https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/).\n\n### 6. (Optional) Configure `SwaggerService`\n\nYou can specify options for generation an `OpenApi\\Annotations\\OpenApi`\ninstance in `config/params.php` to configure `SwaggerService`:\n\n```php\n//...\n'yiisoft/yii-swagger' =\u003e [\n    // Default values are specified.\n    'open-api-options' =\u003e [\n        'aliases' =\u003e OpenApi\\Generator::DEFAULT_ALIASES,\n        'namespaces' =\u003e OpenApi\\Generator::DEFAULT_NAMESPACES,\n        'analyser' =\u003e null,\n        'analysis' =\u003e null,\n        'processors' =\u003e null,\n        'logger' =\u003e null,\n        'validate' =\u003e true,\n        'version' =\u003e OpenApi\\Annotations\\OpenApi::DEFAULT_VERSION,\n    ],\n],\n//...\n```\n\nFor more information about generation an `OpenApi\\Annotations\\OpenApi` instance, see the\ndocumentation of the [zircote/swagger-php](https://github.com/zircote/swagger-php) package.\n\n## Documentation\n\n- [Internals](docs/internals.md)\n\nIf you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that.\nYou may also check out other [Yii Community Resources](https://www.yiiframework.com/community).\n\n## License\n\nThe Yii Swagger is free software. It is released under the terms of the BSD License.\nPlease see [`LICENSE`](./LICENSE.md) for more information.\n\nMaintained by [Yii Software](https://www.yiiframework.com/).\n\n## Support the project\n\n[![Open Collective](https://img.shields.io/badge/Open%20Collective-sponsor-7eadf1?logo=open%20collective\u0026logoColor=7eadf1\u0026labelColor=555555)](https://opencollective.com/yiisoft)\n\n## Follow updates\n\n[![Official website](https://img.shields.io/badge/Powered_by-Yii_Framework-green.svg?style=flat)](https://www.yiiframework.com/)\n[![Twitter](https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter\u0026logoColor=1DA1F2\u0026labelColor=555555?style=flat)](https://twitter.com/yiiframework)\n[![Telegram](https://img.shields.io/badge/telegram-join-1DA1F2?style=flat\u0026logo=telegram)](https://t.me/yii3en)\n[![Facebook](https://img.shields.io/badge/facebook-join-1DA1F2?style=flat\u0026logo=facebook\u0026logoColor=ffffff)](https://www.facebook.com/groups/yiitalk)\n[![Slack](https://img.shields.io/badge/slack-join-1DA1F2?style=flat\u0026logo=slack)](https://yiiframework.com/go/slack)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Fyii-swagger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyiisoft%2Fyii-swagger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Fyii-swagger/lists"}