1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Webapi\Model\Rest;
use Magento\Webapi\Model\Config as ModelConfig;
/**
* Webapi Swagger Specification Model
*
* @link https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md Swagger specification
*
* @method Swagger setHost(string $host)
* @method Swagger setDefinitions(array $definitions)
* @method Swagger setSchemes(array $schemes)
*/
class Swagger extends \Magento\Framework\DataObject
{
/**
* Swagger specification version
*/
const SWAGGER_VERSION = '2.0';
/**
* Constructor
*/
public function __construct()
{
$data = [
'swagger' => self::SWAGGER_VERSION,
'info' => [
'version' => '',
'title' => '',
],
];
parent::__construct($data);
}
/**
* Add a path
*
* @param string $path
* @param string $httpOperation
* @param string[] $pathInfo
* @return $this
*/
public function addPath($path, $httpOperation, $pathInfo)
{
$this->_data['paths'][$path][$httpOperation] = $pathInfo;
return $this;
}
/**
* Add a tag
*
* @param string $tagInfo
* @return $this
*/
public function addTag($tagInfo)
{
$this->_data['tags'][] = $tagInfo;
return $this;
}
/**
* Get JSON encoded REST schema
*
* @return string
*/
public function toSchema()
{
return json_encode($this->toArray(), JSON_UNESCAPED_SLASHES);
}
/**
* Add Info section data
*
* @param array $info
* @return $this
*/
public function setInfo($info)
{
if (! is_array($info)) {
return $this;
}
if (isset($info['title'])) {
$this->_data['info']['title'] = $info['title'];
}
if (isset($info['version'])) {
$this->_data['info']['version'] = $info['version'];
}
return $this;
}
/**
* Set base path
*
* @param string $basePath
* @return $this
*/
public function setBasePath($basePath)
{
$this->_data['basePath'] = $basePath;
return $this;
}
}