Page MenuHomePhabricator

Referenced definitions are not normalized
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

  • Provide the following schema in a provider:

ExampleSchema.php

<?php

namespace CommunityConfigurationExample\Schemas;

use MediaWiki\Extension\CommunityConfiguration\Schema\JsonSchema;
use MediaWiki\Extension\CommunityConfiguration\Schemas\MediaWiki\MediaWikiDefinitions;

class ExampleSchema extends JsonSchema {
	public const CCExamplePageTitles = [
		self::REF => [ 'class' => MediaWikiDefinitions::class, 'field' => 'PageTitles' ],
	];
}

MediaWikiDefinitions.php

<?php

namespace MediaWiki\Extension\CommunityConfiguration\Schemas\MediaWiki;

use MediaWiki\Extension\CommunityConfiguration\Schema\JsonSchema;

// phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase
class MediaWikiDefinitions extends JsonSchema {
	public const PageTitle = [
		self::TYPE => self::TYPE_STRING
	];

	public const PageTitles = [
		self::TYPE => self::TYPE_ARRAY,
		self::ITEMS => [
			self::REF => [ 'class' => self::class, 'field' => 'PageTitle' ]
		]
	];

}

config.json

{
  "CCExamplePageTitles": ["A"]
}

What happens?:
The serialized schema has de-normalized references in array items properties (and any definition which references another schema):

{
    "$schema": "https://json-schema.org/draft-04/schema#",
    "$id": "CommunityConfigurationExample/Schemas/ExampleSchema/1.0.0",
    "additionalProperties": false,
    "type": "object",
    "properties": {
        "CCExamplePageTitles": {
            "$ref": "#/$defs/MediaWiki.Extension.CommunityConfiguration.Schemas.MediaWiki.MediaWikiDefinitions::PageTitles",
            "default": null
        }
    },
    "$defs": {
        "MediaWiki.Extension.CommunityConfiguration.Schemas.MediaWiki.MediaWikiDefinitions::PageTitles": {
            "type": "array",
            "items": {
                // Should be a full path
                "$ref": {
                    "class": "MediaWiki\\Extension\\CommunityConfiguration\\Schemas\\MediaWiki\\MediaWikiDefinitions",
                    "field": "PageTitle"
                }
            }
        }
    }
}

What should have happened instead?:

$ref should have an absolute URI as its reference: #/$defs/MediaWiki.Extension.CommunityConfiguration.Schemas.MediaWiki.MediaWikiDefinitions::PageTitle

Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Change #1023108 had a related patch set uploaded (by Sergio Gimeno; author: Sergio Gimeno):

[mediawiki/core@master] [WIP] resolve and normalize array items references

https://gerrit.wikimedia.org/r/1023108

Sgs raised the priority of this task from Medium to High.Tue, Apr 23, 4:25 PM
Sgs renamed this task from Array items references are not normalized to Referenced definitions are not normalized.Thu, Apr 25, 10:46 AM

Change #1024639 had a related patch set uploaded (by Sergio Gimeno; author: Sergio Gimeno):

[mediawiki/core@master] JsonSchemaTrait: test cycle detection and references normalization

https://gerrit.wikimedia.org/r/1024639

I pushed a test patch 1024639 to prove the miss-behavior and a possible fix 1023108. @daniel, if you have the time your input would be much appreciated.

Change #1024639 abandoned by Sergio Gimeno:

[mediawiki/core@master] JsonSchemaTrait: test cycle detection and references normalization

Reason:

Squashed in Ic1b11eddebcdd546412ea9f27f3e037d5c242d64

https://gerrit.wikimedia.org/r/1024639

Change #1023108 merged by jenkins-bot:

[mediawiki/core@master] JsonSchemaTrait: normalize resolved references

https://gerrit.wikimedia.org/r/1023108