aboutsummaryrefslogtreecommitdiffstats
path: root/includes/Settings/Source
diff options
context:
space:
mode:
authorMartin Urbanec <martin.urbanec@wikimedia.cz>2024-04-05 14:34:00 +0200
committerMartin Urbanec <martin.urbanec@wikimedia.cz>2024-04-05 15:04:56 +0200
commitdb80557776e4a32a0951da4311a5cb799ef46fa2 (patch)
tree3bb533f28b77f8615ec746e86b719878a26d49f9 /includes/Settings/Source
parent50a966a208ff4679d3351e81d0ef23e2d7f3cc41 (diff)
downloadmediawikicore-db80557776e4a32a0951da4311a5cb799ef46fa2.tar.gz
mediawikicore-db80557776e4a32a0951da4311a5cb799ef46fa2.zip
ReflectionSchemaSource: Add loadAsSchema()
Follow-up to I130326e5762e706be4889e308eeec45a6c7683c5. Bug: T357718 Change-Id: I58590f442850418752493ef78475bb1f034f6d42
Diffstat (limited to 'includes/Settings/Source')
-rw-r--r--includes/Settings/Source/ReflectionSchemaSource.php32
1 files changed, 31 insertions, 1 deletions
diff --git a/includes/Settings/Source/ReflectionSchemaSource.php b/includes/Settings/Source/ReflectionSchemaSource.php
index 1f6294eb4c63..9fcf150d9e12 100644
--- a/includes/Settings/Source/ReflectionSchemaSource.php
+++ b/includes/Settings/Source/ReflectionSchemaSource.php
@@ -58,10 +58,17 @@ class ReflectionSchemaSource implements SettingsSource {
}
/**
+ * @inheritDoc
+ */
+ public function load(): array {
+ return $this->loadAsComponents();
+ }
+
+ /**
* @throws SettingsBuilderException
* @return array
*/
- public function load(): array {
+ public function loadAsComponents(): array {
$schemas = [];
$defs = [];
$obsolete = [];
@@ -120,6 +127,29 @@ class ReflectionSchemaSource implements SettingsSource {
}
/**
+ * Load the data as a single top-level JSON Schema.
+ *
+ * Returned JSON Schema is for an object, which includes the individual config schemas. The
+ * returned schema may contain `$defs`, which then may be referenced internally in the schema
+ * via `$ref`.
+ *
+ * @return array
+ */
+ public function loadAsSchema(): array {
+ $info = $this->loadAsComponents();
+ $schema = [
+ 'type' => 'object',
+ 'properties' => $info['config-schema'],
+ ];
+
+ if ( $info['schema-definitions'] ) {
+ $schema['$defs'] = $info['schema-definitions'];
+ }
+
+ return $schema;
+ }
+
+ /**
* Returns this file source as a string.
*
* @return string