FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
php-openapi/src/spec/Encoding.php at master · php-openapi/php-openapi · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
php-openapi
/
php-openapi
Public
forked from
cebe/php-openapi
Notifications
You must be signed in to change notification settings
Fork
0
Star
5
Code
Pull requests
0
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
php-openapi
/
src
/
spec
/
Encoding.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
96 lines (87 loc) · 3.13 KB
Breadcrumbs
php-openapi
/
src
/
spec
/
Encoding.php
Copy path
File metadata and controls
96 lines (87 loc) · 3.13 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
<?php
/**
* @copyright Copyright (c) 2018 Carsten Brandt <mail@cebe.cc> and contributors
* @license https://github.com/cebe/php-openapi/blob/master/LICENSE
*/
namespace
cebe
\
openapi
\
spec
;
use
cebe
\
openapi
\
exceptions
\
TypeErrorException
;
use
cebe
\
openapi
\
SpecBaseObject
;
/**
* A single encoding definition applied to a single schema property.
*
* @link https://github.com/OAI/OpenAPI-Specification/blob/3.0.2/versions/3.0.2.md#encodingObject
*
* @property string $contentType
* @property Header[]|Reference[] $headers
* @property string $style
* @property boolean $explode
* @property boolean $allowReserved
*/
class
Encoding
extends
SpecBaseObject
{
/**
* @return array array of attributes available in this object.
*/
protected
function
attributes
():
array
{
return
[
'
contentType
'
=> Type::
STRING
,
'
headers
'
=> [Type::
STRING
, Header::class],
// TODO implement default values for style
// https://github.com/OAI/OpenAPI-Specification/blob/3.0.2/versions/3.0.2.md#encodingObject
'
style
'
=> Type::
STRING
,
'
explode
'
=> Type::
BOOLEAN
,
'
allowReserved
'
=> Type::
BOOLEAN
,
];
}
private
$
_attributeDefaults
= [];
/**
* @return array array of attributes default values.
*/
protected
function
attributeDefaults
():
array
{
return
$
this
->
_attributeDefaults
;
}
/**
* Create an object from spec data.
* @param array $data spec data read from YAML or JSON
* @throws TypeErrorException in case invalid data is supplied.
*/
public
function
__construct
(
array
$
data
, ?
Schema
$
schema
=
null
)
{
if
(
isset
(
$
data
[
'
style
'
])) {
// Spec: When style is form, the default value is true.
$
this
->
_attributeDefaults
[
'
explode
'
] = (
$
data
[
'
style
'
] ===
'
form
'
);
}
if
(
$
schema
!==
null
) {
// Spec: Default value depends on the property type:
// for string with format being binary – application/octet-stream;
// for other primitive types – text/plain;
// for object - application/json;
// for array – the default is defined based on the inner type.
switch
(
$
schema
->
type
===
'
array
'
? (
$
schema
->
items
->
type
??
'
array
'
) :
$
schema
->
type
) {
case
Type::
STRING
:
if
(
$
schema
->
format
===
'
binary
'
) {
$
this
->
_attributeDefaults
[
'
contentType
'
] =
'
application/octet-stream
'
;
break
;
}
// no break here
case
Type::
BOOLEAN
:
case
Type::
INTEGER
:
case
Type::
NUMBER
:
$
this
->
_attributeDefaults
[
'
contentType
'
] =
'
text/plain
'
;
break
;
case
'
object
'
:
$
this
->
_attributeDefaults
[
'
contentType
'
] =
'
application/json
'
;
break
;
}
}
parent
::
__construct
(
$
data
);
}
/**
* Perform validation on this object, check data against OpenAPI Specification rules.
*/
protected
function
performValidation
()
{
}
}
Back
|
FazBrowse Home
|
New Git URL