Skip to content

Commit

Permalink
Updated both js and PHP Swagger packages to last versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Piazza committed Sep 27, 2024
1 parent e2595e6 commit c28e2d5
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 44 deletions.
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@
<br>
</p>

Swagger/OpenAPI Documentation Generator for Yii2 Framework.
This is a fork from https://github.com/yii2mod/yii2-swagger.

[![Latest Stable Version](https://poser.pugx.org/yii2mod/yii2-swagger/v/stable)](https://packagist.org/packages/yii2mod/yii2-swagger)
[![Total Downloads](https://poser.pugx.org/yii2mod/yii2-swagger/downloads)](https://packagist.org/packages/yii2mod/yii2-swagger)
[![License](https://poser.pugx.org/yii2mod/yii2-swagger/license)](https://packagist.org/packages/yii2mod/yii2-swagger)
[![Build Status](https://travis-ci.org/yii2mod/yii2-swagger.svg?branch=master)](https://travis-ci.org/yii2mod/yii2-swagger)
Swagger/OpenAPI Documentation Generator for Yii2 Framework.

Installation
------------
Expand All @@ -21,13 +18,13 @@ The preferred way to install this extension is through [composer](http://getcomp
Either run

```
php composer.phar require --prefer-dist yii2mod/yii2-swagger "*"
php composer.phar require --prefer-dist yetopen/yii2-swagger "*"
```

or add

```
"yii2mod/yii2-swagger": "*"
"yetopen/yii2-swagger": "*"
```

to the require section of your composer.json.
Expand Down Expand Up @@ -62,11 +59,11 @@ class SiteController extends Controller
{
return [
'docs' => [
'class' => 'yii2mod\swagger\SwaggerUIRenderer',
'class' => 'yetopen\swagger\SwaggerUIRenderer',
'restUrl' => Url::to(['site/json-schema']),
],
'json-schema' => [
'class' => 'yii2mod\swagger\OpenAPIRenderer',
'class' => 'yetopen\swagger\OpenAPIRenderer',
// Тhe list of directories that contains the swagger annotations.
'scanDir' => [
Yii::getAlias('@app/controllers'),
Expand Down Expand Up @@ -179,7 +176,7 @@ http://localhost/path/to/index.php?r=site/docs
![Alt text](http://res.cloudinary.com/igor-chepurnoi/image/upload/v1507979787/Swagger_UI_ps89ih.png "Swagger Documentation")


## Support us
## Support Yii2mod

Does your business depend on our contributions? Reach out and support us on [Patreon](https://www.patreon.com/yii2mod).
All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.
14 changes: 9 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "yii2mod/yii2-swagger",
"name": "yetopen/yii2-swagger",
"description": "Swagger Documentation Generator for Yii2 Framework",
"type": "yii2-extension",
"keywords": [
Expand All @@ -12,21 +12,25 @@
{
"name": "Igor Chepurnoi",
"email": "[email protected]"
},
{
"name": "YetOpen S.r.l.",
"email": "[email protected]"
}
],
"require": {
"php": ">=7.1.0",
"php": ">=7.4.0",
"yiisoft/yii2": "~2.0.12",
"zircote/swagger-php": "^2.0",
"bower-asset/swagger-ui": "^3.1"
"zircote/swagger-php": "^4.10.6",
"npm-asset/swagger-ui-dist": "^5.17"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~2.0",
"phpunit/phpunit": "~6.0"
},
"autoload": {
"psr-4": {
"yii2mod\\swagger\\": ""
"yetopen\\swagger\\": "src"
}
},
"repositories": [
Expand Down
18 changes: 10 additions & 8 deletions OpenAPIRenderer.php → src/OpenAPIRenderer.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

namespace yii2mod\swagger;
namespace yetopen\swagger;

use Swagger\Annotations\Swagger;
use OpenApi\Annotations\OpenApi;
use OpenApi\Generator;
use Symfony\Component\Finder\Finder;
use Yii;
use yii\base\Action;
use yii\caching\Cache;
Expand All @@ -12,12 +14,12 @@
/**
* Class OpenAPIRenderer is responsible for generating the JSON spec.
*
* @package yii2mod\swagger\actions
* @package yetopen\swagger\actions
*/
class OpenAPIRenderer extends Action
{
/**
* @var string|array|\Symfony\Component\Finder\Finder The directory(s) or filename(s).
* @var string|array|Finder The directory(s) or filename(s).
* If you configured the directory must be full path of the directory.
*/
public $scanDir;
Expand Down Expand Up @@ -73,16 +75,16 @@ public function run(): Response
/**
* Scan the filesystem for swagger annotations and build swagger-documentation.
*
* @return Swagger
* @return OpenApi
*/
protected function getSwaggerDocumentation(): Swagger
protected function getSwaggerDocumentation(): OpenApi
{
if (!$this->cache instanceof Cache) {
return \Swagger\scan($this->scanDir, $this->scanOptions);
return Generator::scan($this->scanDir, $this->scanOptions);
}

return $this->cache->getOrSet($this->cacheKey, function () {
return \Swagger\scan($this->scanDir, $this->scanOptions);
return Generator::scan($this->scanDir, $this->scanOptions);
}, $this->cacheDuration);
}

Expand Down
6 changes: 3 additions & 3 deletions SwaggerAsset.php → src/SwaggerAsset.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?php

namespace yii2mod\swagger;
namespace yetopen\swagger;

use yii\web\AssetBundle;

/**
* Class SwaggerAsset
*
* @package yii2mod\swagger
* @package yetopen\swagger
*/
class SwaggerAsset extends AssetBundle
{
/**
* @var string the directory that contains the source asset files for this asset bundle
*/
public $sourcePath = '@bower/swagger-ui/dist';
public $sourcePath = '@npm/swagger-ui-dist';

/**
* @var array list of JavaScript files that this bundle contains
Expand Down
6 changes: 3 additions & 3 deletions SwaggerUIRenderer.php → src/SwaggerUIRenderer.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace yii2mod\swagger;
namespace yetopen\swagger;

use yii\base\Action;

/**
* Class SwaggerUIRenderer renders the UI (HTML/JS/CSS).
*
* @package yii2mod\swagger
* @package yetopen\swagger
*/
class SwaggerUIRenderer extends Action
{
Expand All @@ -19,7 +19,7 @@ class SwaggerUIRenderer extends Action
/**
* @var string base swagger template
*/
public $view = '@vendor/yii2mod/yii2-swagger/views/index';
public $view = '@vendor/yetopen/yii2-swagger/src/views/index';

/**
* @var null|string|false the name of the layout to be applied to this controller's views.
Expand Down
4 changes: 2 additions & 2 deletions views/index.php → src/views/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use yii2mod\swagger\SwaggerAsset;
use yetopen\swagger\SwaggerAsset;

/* @var $this \yii\web\View */
/* @var $restUrl string */
Expand Down Expand Up @@ -38,7 +38,7 @@

<body>
<?php $this->beginBody(); ?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
<svg xmlns="http://www.w3.org/2000/svg"
style="position:absolute;width:0;height:0">
<defs>
<symbol viewBox="0 0 20 20" id="unlocked">
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace yii2mod\swagger\tests;
namespace yetopen\swagger\tests;

use yetopen\swagger\tests\data\Controller;
use Yii;
use yii\helpers\ArrayHelper;
use yii2mod\swagger\tests\data\Controller;

/**
* This is the base class for all yii framework unit tests.
Expand Down
12 changes: 6 additions & 6 deletions tests/actions/OpenAPIRendererTest.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?php

namespace yii2mod\swagger\tests\actions;
namespace yetopen\swagger\tests\actions;

use Swagger\Annotations\Info;
use Swagger\Annotations\Path;
use yetopen\swagger\OpenAPIRenderer;
use yetopen\swagger\tests\TestCase;
use Yii;
use yii\web\Response;
use yii2mod\swagger\OpenAPIRenderer;
use yii2mod\swagger\tests\TestCase;

class OpenAPIRendererTest extends TestCase
{
public function testCheckApiInfo()
{
$response = $this->runAction([
'scanDir' => [
Yii::getAlias('@yii2mod/tests/unit/swagger/data'),
Yii::getAlias('@yetopen/tests/unit/swagger/data'),
],
]);

Expand All @@ -28,7 +28,7 @@ public function testCheckPaths()
{
$response = $this->runAction([
'scanDir' => [
Yii::getAlias('@yii2mod/tests/unit/swagger/data'),
Yii::getAlias('@yetopen/tests/unit/swagger/data'),
],
]);

Expand All @@ -43,7 +43,7 @@ public function testDisableCache()
{
$response = $this->runAction([
'scanDir' => [
Yii::getAlias('@yii2mod/tests/unit/swagger/data'),
Yii::getAlias('@yetopen/tests/unit/swagger/data'),
],
'cache' => null,
]);
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
require_once(__DIR__ . '/../vendor/autoload.php');
require_once(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');

Yii::setAlias('@yii2mod/tests/unit/swagger', __DIR__);
Yii::setAlias('@yetopen/tests/unit/swagger', __DIR__);
2 changes: 1 addition & 1 deletion tests/data/Controller.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace yii2mod\swagger\tests\data;
namespace yetopen\swagger\tests\data;

/**
* @SWG\Swagger(
Expand Down
4 changes: 2 additions & 2 deletions tests/data/UserController.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace yii2mod\swagger\tests\data;
namespace yetopen\swagger\tests\data;

use yii\rest\Controller;

/**
* Class UserController
*
* @package yii2mod\swagger\tests\data
* @package yetopen\swagger\tests\data
*/
class UserController extends Controller
{
Expand Down
2 changes: 1 addition & 1 deletion tests/data/definitions/User.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace yii2mod\swagger\tests\data\definitions;
namespace yetopen\swagger\tests\data\definitions;

/**
* @SWG\Definition(required={"username", "email"})
Expand Down

0 comments on commit c28e2d5

Please sign in to comment.