Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace core\router\schema\objects;
18
 
19
use core\param;
20
use core\router\schema\example;
21
use core\router\schema\referenced_object;
22
use core\router\schema\specification;
23
 
24
/**
25
 * A standard response for user preferences.
26
 *
27
 * @package    core
28
 * @copyright  2023 Andrew Lyons <andrew@nicols.co.uk>
29
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 */
31
class stacktrace extends type_base implements referenced_object {
32
    /** @var array The stacks in the trace */
33
    protected array $content;
34
 
35
    /**
36
     * Constructor for a new stacktrace object.
37
     */
38
    public function __construct() {
39
        $this->content = [
40
            'file' => new scalar_type(param::PATH),
41
            'line' => new scalar_type(param::INT),
42
            'function' => new scalar_type(param::RAW),
43
            'args' => new array_of_things(),
44
            'class' => new scalar_type(param::RAW),
45
            'type' => new scalar_type(param::RAW),
46
        ];
47
 
48
        $pathroot = '/Users/example/Sites/moodle';
49
        parent::__construct(
50
            examples: [
51
                new example(
52
                    name: 'A sample stacktrace',
53
                    value: [
54
                        [
55
                            "file" => "{$pathroot}/lib/classes/router/schema/objects/array_of_strings.php",
56
                            "line" => 48,
57
                            "function" => "validate_param",
58
                            "args" => [
59
                                "string",
60
                                "int",
61
                                false,
62
                                "The value 'string' was not of type string.",
63
                            ],
64
                        ],
65
                        [
66
                            "file" => "{$pathroot}/lib/classes/router/schema/objects/schema_object.php",
67
                            "line" => 85,
68
                            "function" => "validate_data",
69
                            "class" => "core\\router\\schema\\objects\\array_of_strings",
70
                            "type" => "->",
71
                            "args" => [
72
                                [
73
                                    "additionalProp1" => "string",
74
                                    "additionalProp2" => "string",
75
                                    "additionalProp3" => "string",
76
                                ],
77
                            ],
78
                        ],
79
                        [
80
                            "file" => "{$pathroot}/lib/classes/router/route.php",
81
                            "line" => 264,
82
                            "function" => "validate_data",
83
                            "class" => "core\\router\\schema\\objects\\schema_object",
84
                            "type" => "->",
85
                            "args" => [
86
                                [
87
                                    "preferences" => [
88
                                        "additionalProp1" => "string",
89
                                        "additionalProp2" => "string",
90
                                        "additionalProp3" => "string",
91
                                    ],
92
                                ],
93
                            ],
94
                        ],
95
                    ],
96
                ),
97
            ],
98
        );
99
    }
100
 
101
    #[\Override]
102
    public function get_openapi_description(
103
        specification $api,
104
        ?string $path = null,
105
    ): ?\stdClass {
106
        $additionalproperties = new \stdClass();
107
 
108
        foreach ($this->content as $name => $content) {
109
            $additionalproperties->{$name} = $content->get_openapi_description($api, $path);
110
        }
111
 
112
        $data = parent::get_openapi_description($api, $path);
113
        $data->type = 'array';
114
        $data->items = (object) [
115
            'type' => 'object',
116
            'properties' => $additionalproperties,
117
        ];
118
 
119
        return $data;
120
    }
121
 
122
    #[\Override]
123
    public function validate_data($data) {
124
        // Do not validate the data at all.
125
        // Stacktraces tend to be used with exceptions and we want whatever was passed through to come out.
126
        return $data;
127
    }
128
}