Parameter::addProperty()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace Guzzle\Service\Description;
4
5
use Guzzle\Common\Exception\InvalidArgumentException;
6
7
/**
8
 * API parameter object used with service descriptions
9
 */
10
class Parameter
11
{
12
    protected $name;
13
    protected $description;
14
    protected $serviceDescription;
15
    protected $type;
16
    protected $required;
17
    protected $enum;
18
    protected $pattern;
19
    protected $minimum;
20
    protected $maximum;
21
    protected $minLength;
22
    protected $maxLength;
23
    protected $minItems;
24
    protected $maxItems;
25
    protected $default;
26
    protected $static;
27
    protected $instanceOf;
28
    protected $filters;
29
    protected $location;
30
    protected $sentAs;
31
    protected $data;
32
    protected $properties = array();
33
    protected $additionalProperties;
34
    protected $items;
35
    protected $parent;
36
    protected $ref;
37
    protected $format;
38
    protected $propertiesCache = null;
39
40
    /**
41
     * Create a new Parameter using an associative array of data. The array can contain the following information:
42
     * - name:          (string) Unique name of the parameter
43
     * - type:          (string|array) Type of variable (string, number, integer, boolean, object, array, numeric,
44
     *                  null, any). Types are using for validation and determining the structure of a parameter. You
45
     *                  can use a union type by providing an array of simple types. If one of the union types matches
46
     *                  the provided value, then the value is valid.
47
     * - instanceOf:    (string) When the type is an object, you can specify the class that the object must implement
48
     * - required:      (bool) Whether or not the parameter is required
49
     * - default:       (mixed) Default value to use if no value is supplied
50
     * - static:        (bool) Set to true to specify that the parameter value cannot be changed from the default
51
     * - description:   (string) Documentation of the parameter
52
     * - location:      (string) The location of a request used to apply a parameter. Custom locations can be registered
53
     *                  with a command, but the defaults are uri, query, header, body, json, xml, postField, postFile.
54
     * - sentAs:        (string) Specifies how the data being modeled is sent over the wire. For example, you may wish
55
     *                  to include certain headers in a response model that have a normalized casing of FooBar, but the
56
     *                  actual header is x-foo-bar. In this case, sentAs would be set to x-foo-bar.
57
     * - filters:       (array) Array of static method names to to run a parameter value through. Each value in the
58
     *                  array must be a string containing the full class path to a static method or an array of complex
59
     *                  filter information. You can specify static methods of classes using the full namespace class
60
     *                  name followed by '::' (e.g. Foo\Bar::baz()). Some filters require arguments in order to properly
61
     *                  filter a value. For complex filters, use a hash containing a 'method' key pointing to a static
62
     *                  method, and an 'args' key containing an array of positional arguments to pass to the method.
63
     *                  Arguments can contain keywords that are replaced when filtering a value: '@value' is replaced
64
     *                  with the value being validated, '@api' is replaced with the Parameter object.
65
     * - properties:    When the type is an object, you can specify nested parameters
66
     * - additionalProperties: (array) This attribute defines a schema for all properties that are not explicitly
67
     *                  defined in an object type definition. If specified, the value MUST be a schema or a boolean. If
68
     *                  false is provided, no additional properties are allowed beyond the properties defined in the
69
     *                  schema. The default value is an empty schema which allows any value for additional properties.
70
     * - items:         This attribute defines the allowed items in an instance array, and MUST be a schema or an array
71
     *                  of schemas. The default value is an empty schema which allows any value for items in the
72
     *                  instance array.
73
     *                  When this attribute value is a schema and the instance value is an array, then all the items
74
     *                  in the array MUST be valid according to the schema.
75
     * - pattern:       When the type is a string, you can specify the regex pattern that a value must match
76
     * - enum:          When the type is a string, you can specify a list of acceptable values
77
     * - minItems:      (int) Minimum number of items allowed in an array
78
     * - maxItems:      (int) Maximum number of items allowed in an array
79
     * - minLength:     (int) Minimum length of a string
80
     * - maxLength:     (int) Maximum length of a string
81
     * - minimum:       (int) Minimum value of an integer
82
     * - maximum:       (int) Maximum value of an integer
83
     * - data:          (array) Any additional custom data to use when serializing, validating, etc
84
     * - format:        (string) Format used to coax a value into the correct format when serializing or unserializing.
85
     *                  You may specify either an array of filters OR a format, but not both.
86
     *                  Supported values: date-time, date, time, timestamp, date-time-http
87
     * - $ref:          (string) String referencing a service description model. The parameter is replaced by the
88
     *                  schema contained in the model.
89
     *
90
     * @param array                       $data        Array of data as seen in service descriptions
91
     * @param ServiceDescriptionInterface $description Service description used to resolve models if $ref tags are found
92
     *
93
     * @throws InvalidArgumentException
94
     */
95
    public function __construct(array $data = array(), ServiceDescriptionInterface $description = null)
96
    {
97
        if ($description) {
98
            if (isset($data['$ref'])) {
99
                if ($model = $description->getModel($data['$ref'])) {
100
                    $data = $model->toArray() + $data;
101
                }
102
            } elseif (isset($data['extends'])) {
103
                // If this parameter extends from another parameter then start with the actual data
104
                // union in the parent's data (e.g. actual supersedes parent)
105
                if ($extends = $description->getModel($data['extends'])) {
106
                    $data += $extends->toArray();
107
                }
108
            }
109
        }
110
111
        // Pull configuration data into the parameter
112
        foreach ($data as $key => $value) {
113
            $this->{$key} = $value;
114
        }
115
116
        $this->serviceDescription = $description;
117
        $this->required = (bool) $this->required;
118
        $this->data = (array) $this->data;
119
120
        if ($this->filters) {
121
            $this->setFilters((array) $this->filters);
122
        }
123
124
        if ($this->type == 'object' && $this->additionalProperties === null) {
125
            $this->additionalProperties = true;
126
        }
127
    }
128
129
    /**
130
     * Convert the object to an array
131
     *
132
     * @return array
133
     */
134
    public function toArray()
135
    {
136
        static $checks = array('required', 'description', 'static', 'type', 'format', 'instanceOf', 'location', 'sentAs',
137
            'pattern', 'minimum', 'maximum', 'minItems', 'maxItems', 'minLength', 'maxLength', 'data', 'enum',
138
            'filters');
139
140
        $result = array();
141
142
        // Anything that is in the `Items` attribute of an array *must* include it's name if available
143
        if ($this->parent instanceof self && $this->parent->getType() == 'array' && isset($this->name)) {
144
            $result['name'] = $this->name;
145
        }
146
147
        foreach ($checks as $c) {
148
            if ($value = $this->{$c}) {
149
                $result[$c] = $value;
150
            }
151
        }
152
153
        if ($this->default !== null) {
154
            $result['default'] = $this->default;
155
        }
156
157
        if ($this->items !== null) {
158
            $result['items'] = $this->getItems()->toArray();
159
        }
160
161
        if ($this->additionalProperties !== null) {
162
            $result['additionalProperties'] = $this->getAdditionalProperties();
163
            if ($result['additionalProperties'] instanceof self) {
164
                $result['additionalProperties'] = $result['additionalProperties']->toArray();
165
            }
166
        }
167
168
        if ($this->type == 'object' && $this->properties) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->properties of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
169
            $result['properties'] = array();
170
            foreach ($this->getProperties() as $name => $property) {
171
                $result['properties'][$name] = $property->toArray();
172
            }
173
        }
174
175
        return $result;
176
    }
177
178
    /**
179
     * Get the default or static value of the command based on a value
180
     *
181
     * @param string $value Value that is currently set
182
     *
183
     * @return mixed Returns the value, a static value if one is present, or a default value
184
     */
185
    public function getValue($value)
186
    {
187
        if ($this->static || ($this->default !== null && $value === null)) {
188
            return $this->default;
189
        }
190
191
        return $value;
192
    }
193
194
    /**
195
     * Run a value through the filters OR format attribute associated with the parameter
196
     *
197
     * @param mixed $value Value to filter
198
     *
199
     * @return mixed Returns the filtered value
200
     */
201
    public function filter($value)
202
    {
203
        // Formats are applied exclusively and supersed filters
204
        if ($this->format) {
205
            return SchemaFormatter::format($this->format, $value);
206
        }
207
208
        // Convert Boolean values
209
        if ($this->type == 'boolean' && !is_bool($value)) {
210
            $value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
211
        }
212
213
        // Apply filters to the value
214
        if ($this->filters) {
215
            foreach ($this->filters as $filter) {
216
                if (is_array($filter)) {
217
                    // Convert complex filters that hold value place holders
218
                    foreach ($filter['args'] as &$data) {
219
                        if ($data == '@value') {
220
                            $data = $value;
221
                        } elseif ($data == '@api') {
222
                            $data = $this;
223
                        }
224
                    }
225
                    $value = call_user_func_array($filter['method'], $filter['args']);
226
                } else {
227
                    $value = call_user_func($filter, $value);
228
                }
229
            }
230
        }
231
232
        return $value;
233
    }
234
235
    /**
236
     * Get the name of the parameter
237
     *
238
     * @return string
239
     */
240
    public function getName()
241
    {
242
        return $this->name;
243
    }
244
245
    /**
246
     * Get the key of the parameter, where sentAs will supersede name if it is set
247
     *
248
     * @return string
249
     */
250
    public function getWireName()
251
    {
252
        return $this->sentAs ?: $this->name;
253
    }
254
255
    /**
256
     * Set the name of the parameter
257
     *
258
     * @param string $name Name to set
259
     *
260
     * @return self
261
     */
262
    public function setName($name)
263
    {
264
        $this->name = $name;
265
266
        return $this;
267
    }
268
269
    /**
270
     * Get the type(s) of the parameter
271
     *
272
     * @return string|array
273
     */
274
    public function getType()
275
    {
276
        return $this->type;
277
    }
278
279
    /**
280
     * Set the type(s) of the parameter
281
     *
282
     * @param string|array $type Type of parameter or array of simple types used in a union
283
     *
284
     * @return self
285
     */
286
    public function setType($type)
287
    {
288
        $this->type = $type;
289
290
        return $this;
291
    }
292
293
    /**
294
     * Get if the parameter is required
295
     *
296
     * @return bool
297
     */
298
    public function getRequired()
299
    {
300
        return $this->required;
301
    }
302
303
    /**
304
     * Set if the parameter is required
305
     *
306
     * @param bool $isRequired Whether or not the parameter is required
307
     *
308
     * @return self
309
     */
310
    public function setRequired($isRequired)
311
    {
312
        $this->required = (bool) $isRequired;
313
314
        return $this;
315
    }
316
317
    /**
318
     * Get the default value of the parameter
319
     *
320
     * @return string|null
321
     */
322
    public function getDefault()
323
    {
324
        return $this->default;
325
    }
326
327
    /**
328
     * Set the default value of the parameter
329
     *
330
     * @param string|null $default Default value to set
331
     *
332
     * @return self
333
     */
334
    public function setDefault($default)
335
    {
336
        $this->default = $default;
337
338
        return $this;
339
    }
340
341
    /**
342
     * Get the description of the parameter
343
     *
344
     * @return string|null
345
     */
346
    public function getDescription()
347
    {
348
        return $this->description;
349
    }
350
351
    /**
352
     * Set the description of the parameter
353
     *
354
     * @param string $description Description
355
     *
356
     * @return self
357
     */
358
    public function setDescription($description)
359
    {
360
        $this->description = $description;
361
362
        return $this;
363
    }
364
365
    /**
366
     * Get the minimum acceptable value for an integer
367
     *
368
     * @return int|null
369
     */
370
    public function getMinimum()
371
    {
372
        return $this->minimum;
373
    }
374
375
    /**
376
     * Set the minimum acceptable value for an integer
377
     *
378
     * @param int|null $min Minimum
379
     *
380
     * @return self
381
     */
382
    public function setMinimum($min)
383
    {
384
        $this->minimum = $min;
385
386
        return $this;
387
    }
388
389
    /**
390
     * Get the maximum acceptable value for an integer
391
     *
392
     * @return int|null
393
     */
394
    public function getMaximum()
395
    {
396
        return $this->maximum;
397
    }
398
399
    /**
400
     * Set the maximum acceptable value for an integer
401
     *
402
     * @param int $max Maximum
403
     *
404
     * @return self
405
     */
406
    public function setMaximum($max)
407
    {
408
        $this->maximum = $max;
409
410
        return $this;
411
    }
412
413
    /**
414
     * Get the minimum allowed length of a string value
415
     *
416
     * @return int
417
     */
418
    public function getMinLength()
419
    {
420
        return $this->minLength;
421
    }
422
423
    /**
424
     * Set the minimum allowed length of a string value
425
     *
426
     * @param int|null $min Minimum
427
     *
428
     * @return self
429
     */
430
    public function setMinLength($min)
431
    {
432
        $this->minLength = $min;
433
434
        return $this;
435
    }
436
437
    /**
438
     * Get the maximum allowed length of a string value
439
     *
440
     * @return int|null
441
     */
442
    public function getMaxLength()
443
    {
444
        return $this->maxLength;
445
    }
446
447
    /**
448
     * Set the maximum allowed length of a string value
449
     *
450
     * @param int $max Maximum length
451
     *
452
     * @return self
453
     */
454
    public function setMaxLength($max)
455
    {
456
        $this->maxLength = $max;
457
458
        return $this;
459
    }
460
461
    /**
462
     * Get the maximum allowed number of items in an array value
463
     *
464
     * @return int|null
465
     */
466
    public function getMaxItems()
467
    {
468
        return $this->maxItems;
469
    }
470
471
    /**
472
     * Set the maximum allowed number of items in an array value
473
     *
474
     * @param int $max Maximum
475
     *
476
     * @return self
477
     */
478
    public function setMaxItems($max)
479
    {
480
        $this->maxItems = $max;
481
482
        return $this;
483
    }
484
485
    /**
486
     * Get the minimum allowed number of items in an array value
487
     *
488
     * @return int
489
     */
490
    public function getMinItems()
491
    {
492
        return $this->minItems;
493
    }
494
495
    /**
496
     * Set the minimum allowed number of items in an array value
497
     *
498
     * @param int|null $min Minimum
499
     *
500
     * @return self
501
     */
502
    public function setMinItems($min)
503
    {
504
        $this->minItems = $min;
505
506
        return $this;
507
    }
508
509
    /**
510
     * Get the location of the parameter
511
     *
512
     * @return string|null
513
     */
514
    public function getLocation()
515
    {
516
        return $this->location;
517
    }
518
519
    /**
520
     * Set the location of the parameter
521
     *
522
     * @param string|null $location Location of the parameter
523
     *
524
     * @return self
525
     */
526
    public function setLocation($location)
527
    {
528
        $this->location = $location;
529
530
        return $this;
531
    }
532
533
    /**
534
     * Get the sentAs attribute of the parameter that used with locations to sentAs an attribute when it is being
535
     * applied to a location.
536
     *
537
     * @return string|null
538
     */
539
    public function getSentAs()
540
    {
541
        return $this->sentAs;
542
    }
543
544
    /**
545
     * Set the sentAs attribute
546
     *
547
     * @param string|null $name Name of the value as it is sent over the wire
548
     *
549
     * @return self
550
     */
551
    public function setSentAs($name)
552
    {
553
        $this->sentAs = $name;
554
555
        return $this;
556
    }
557
558
    /**
559
     * Retrieve a known property from the parameter by name or a data property by name. When not specific name value
560
     * is specified, all data properties will be returned.
561
     *
562
     * @param string|null $name Specify a particular property name to retrieve
563
     *
564
     * @return array|mixed|null
565
     */
566
    public function getData($name = null)
567
    {
568
        if (!$name) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $name of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
569
            return $this->data;
570
        }
571
572
        if (isset($this->data[$name])) {
573
            return $this->data[$name];
574
        } elseif (isset($this->{$name})) {
575
            return $this->{$name};
576
        }
577
578
        return null;
579
    }
580
581
    /**
582
     * Set the extra data properties of the parameter or set a specific extra property
583
     *
584
     * @param string|array|null $nameOrData The name of a specific extra to set or an array of extras to set
585
     * @param mixed|null        $data       When setting a specific extra property, specify the data to set for it
586
     *
587
     * @return self
588
     */
589
    public function setData($nameOrData, $data = null)
590
    {
591
        if (is_array($nameOrData)) {
592
            $this->data = $nameOrData;
593
        } else {
594
            $this->data[$nameOrData] = $data;
595
        }
596
597
        return $this;
598
    }
599
600
    /**
601
     * Get whether or not the default value can be changed
602
     *
603
     * @return mixed|null
604
     */
605
    public function getStatic()
606
    {
607
        return $this->static;
608
    }
609
610
    /**
611
     * Set to true if the default value cannot be changed
612
     *
613
     * @param bool $static True or false
614
     *
615
     * @return self
616
     */
617
    public function setStatic($static)
618
    {
619
        $this->static = (bool) $static;
620
621
        return $this;
622
    }
623
624
    /**
625
     * Get an array of filters used by the parameter
626
     *
627
     * @return array
628
     */
629
    public function getFilters()
630
    {
631
        return $this->filters ?: array();
632
    }
633
634
    /**
635
     * Set the array of filters used by the parameter
636
     *
637
     * @param array $filters Array of functions to use as filters
638
     *
639
     * @return self
640
     */
641
    public function setFilters(array $filters)
642
    {
643
        $this->filters = array();
644
        foreach ($filters as $filter) {
645
            $this->addFilter($filter);
646
        }
647
648
        return $this;
649
    }
650
651
    /**
652
     * Add a filter to the parameter
653
     *
654
     * @param string|array $filter Method to filter the value through
655
     *
656
     * @return self
657
     * @throws InvalidArgumentException
658
     */
659
    public function addFilter($filter)
660
    {
661
        if (is_array($filter)) {
662
            if (!isset($filter['method'])) {
663
                throw new InvalidArgumentException('A [method] value must be specified for each complex filter');
664
            }
665
        }
666
667
        if (!$this->filters) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->filters of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
668
            $this->filters = array($filter);
669
        } else {
670
            $this->filters[] = $filter;
671
        }
672
673
        return $this;
674
    }
675
676
    /**
677
     * Get the parent object (an {@see OperationInterface} or {@see Parameter}
678
     *
679
     * @return OperationInterface|Parameter|null
680
     */
681
    public function getParent()
682
    {
683
        return $this->parent;
684
    }
685
686
    /**
687
     * Set the parent object of the parameter
688
     *
689
     * @param OperationInterface|Parameter|null $parent Parent container of the parameter
690
     *
691
     * @return self
692
     */
693
    public function setParent($parent)
694
    {
695
        $this->parent = $parent;
696
697
        return $this;
698
    }
699
700
    /**
701
     * Get the properties of the parameter
702
     *
703
     * @return array
704
     */
705
    public function getProperties()
706
    {
707
        if (!$this->propertiesCache) {
708
            $this->propertiesCache = array();
709
            foreach (array_keys($this->properties) as $name) {
710
                $this->propertiesCache[$name] = $this->getProperty($name);
711
            }
712
        }
713
714
        return $this->propertiesCache;
715
    }
716
717
    /**
718
     * Get a specific property from the parameter
719
     *
720
     * @param string $name Name of the property to retrieve
721
     *
722
     * @return null|Parameter
723
     */
724
    public function getProperty($name)
725
    {
726
        if (!isset($this->properties[$name])) {
727
            return null;
728
        }
729
730
        if (!($this->properties[$name] instanceof self)) {
731
            $this->properties[$name]['name'] = $name;
732
            $this->properties[$name] = new static($this->properties[$name], $this->serviceDescription);
733
            $this->properties[$name]->setParent($this);
734
        }
735
736
        return $this->properties[$name];
737
    }
738
739
    /**
740
     * Remove a property from the parameter
741
     *
742
     * @param string $name Name of the property to remove
743
     *
744
     * @return self
745
     */
746
    public function removeProperty($name)
747
    {
748
        unset($this->properties[$name]);
749
        $this->propertiesCache = null;
750
751
        return $this;
752
    }
753
754
    /**
755
     * Add a property to the parameter
756
     *
757
     * @param Parameter $property Properties to set
758
     *
759
     * @return self
760
     */
761
    public function addProperty(Parameter $property)
762
    {
763
        $this->properties[$property->getName()] = $property;
764
        $property->setParent($this);
765
        $this->propertiesCache = null;
766
767
        return $this;
768
    }
769
770
    /**
771
     * Get the additionalProperties value of the parameter
772
     *
773
     * @return bool|Parameter|null
774
     */
775 View Code Duplication
    public function getAdditionalProperties()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
776
    {
777
        if (is_array($this->additionalProperties)) {
778
            $this->additionalProperties = new static($this->additionalProperties, $this->serviceDescription);
779
            $this->additionalProperties->setParent($this);
780
        }
781
782
        return $this->additionalProperties;
783
    }
784
785
    /**
786
     * Set the additionalProperties value of the parameter
787
     *
788
     * @param bool|Parameter|null $additional Boolean to allow any, an Parameter to specify a schema, or false to disallow
789
     *
790
     * @return self
791
     */
792
    public function setAdditionalProperties($additional)
793
    {
794
        $this->additionalProperties = $additional;
795
796
        return $this;
797
    }
798
799
    /**
800
     * Set the items data of the parameter
801
     *
802
     * @param Parameter|null $items Items to set
803
     *
804
     * @return self
805
     */
806
    public function setItems(Parameter $items = null)
807
    {
808
        if ($this->items = $items) {
809
            $this->items->setParent($this);
810
        }
811
812
        return $this;
813
    }
814
815
    /**
816
     * Get the item data of the parameter
817
     *
818
     * @return Parameter|null
819
     */
820 View Code Duplication
    public function getItems()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
821
    {
822
        if (is_array($this->items)) {
823
            $this->items = new static($this->items, $this->serviceDescription);
824
            $this->items->setParent($this);
825
        }
826
827
        return $this->items;
828
    }
829
830
    /**
831
     * Get the class that the parameter must implement
832
     *
833
     * @return null|string
834
     */
835
    public function getInstanceOf()
836
    {
837
        return $this->instanceOf;
838
    }
839
840
    /**
841
     * Set the class that the parameter must be an instance of
842
     *
843
     * @param string|null $instanceOf Class or interface name
844
     *
845
     * @return self
846
     */
847
    public function setInstanceOf($instanceOf)
848
    {
849
        $this->instanceOf = $instanceOf;
850
851
        return $this;
852
    }
853
854
    /**
855
     * Get the enum of strings that are valid for the parameter
856
     *
857
     * @return array|null
858
     */
859
    public function getEnum()
860
    {
861
        return $this->enum;
862
    }
863
864
    /**
865
     * Set the enum of strings that are valid for the parameter
866
     *
867
     * @param array|null $enum Array of strings or null
868
     *
869
     * @return self
870
     */
871
    public function setEnum(array $enum = null)
872
    {
873
        $this->enum = $enum;
874
875
        return $this;
876
    }
877
878
    /**
879
     * Get the regex pattern that must match a value when the value is a string
880
     *
881
     * @return string
882
     */
883
    public function getPattern()
884
    {
885
        return $this->pattern;
886
    }
887
888
    /**
889
     * Set the regex pattern that must match a value when the value is a string
890
     *
891
     * @param string $pattern Regex pattern
892
     *
893
     * @return self
894
     */
895
    public function setPattern($pattern)
896
    {
897
        $this->pattern = $pattern;
898
899
        return $this;
900
    }
901
902
    /**
903
     * Get the format attribute of the schema
904
     *
905
     * @return string
906
     */
907
    public function getFormat()
908
    {
909
        return $this->format;
910
    }
911
912
    /**
913
     * Set the format attribute of the schema
914
     *
915
     * @param string $format Format to set (e.g. date, date-time, timestamp, time, date-time-http)
916
     *
917
     * @return self
918
     */
919
    public function setFormat($format)
920
    {
921
        $this->format = $format;
922
923
        return $this;
924
    }
925
}
926