Skip to content

Include actual media type in InvalidSchemaMediaTypeException#872

Merged
DannyvdSluijs merged 4 commits intomainfrom
copilot/report-media-type-in-uri-retriever
Jan 23, 2026
Merged

Include actual media type in InvalidSchemaMediaTypeException#872
DannyvdSluijs merged 4 commits intomainfrom
copilot/report-media-type-in-uri-retriever

Conversation

Copy link
Contributor

Copilot AI commented Jan 23, 2026

Fix InvalidSchemaMediaTypeException to include actual media type

  • Update the exception message in UriRetriever::confirmMediaType() to include the actual media type discovered
  • Add a test to verify the new exception message includes both expected and actual media types
  • Add a changelog entry documenting this improvement
  • Run existing tests to ensure no regressions
  • Request code review
  • Run security scan
  • Address review feedback - Add PR link to CHANGELOG

Summary

This PR fixes the issue where InvalidSchemaMediaTypeException only reported what media type was expected but not what was actually received.

Changes:

  • Updated exception message from "Media type application/schema+json expected" to "Media type application/schema+json expected, but text/html given" (example)
  • Added test to verify the new exception message format
  • Updated CHANGELOG.md with PR link

Testing:

  • All 27 tests in UriRetrieverTest pass
  • New test specifically validates the exception message includes the actual media type
Original prompt

This section details on the original issue you should resolve

<issue_title>UriRetriever: Report what Media type is</issue_title>
<issue_description>https://github.com/jsonrainbow/json-schema/blob/53725e0/src/JsonSchema/Uri/UriRetriever.php#L94

Seen at https://integration.wikimedia.org/ci/job/quibble-for-mediawiki-core-vendor-mysql-php83/4583/console when trying to upgrade the OpenApi spec we're using in testing (so on 5.3.1, currently) from 3.0.3 to 3.0.4.

https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1229635/1/tests/phpunit/integration/includes/Rest/Handler/data/OpenApi-3.0.json

While it's helpful to be told what media type something isn't... It's not very helpful if you're not also told what media type something apparently is.

18:42:26 There were 6 errors:
18:42:26 
18:42:26 1) RestStructureTest::testModuleDefinitionFiles with data set "/workspace/src/includes/Rest/content.v1.json" (stdClass Object (...))
18:42:26 JsonSchema\Exception\InvalidSchemaMediaTypeException: Media type application/schema+json expected
18:42:26 
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/UriRetriever.php:92
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/UriRetriever.php:209
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/UriRetriever.php:181
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/SchemaStorage.php:52
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/SchemaStorage.php:115
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/SchemaStorage.php:138
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/SchemaStorage.php:162
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Constraint.php:123
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/ObjectConstraint.php:145
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/ObjectConstraint.php:47
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Constraint.php:90
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/UndefinedConstraint.php:74
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/UndefinedConstraint.php:52
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Constraint.php:123
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/UndefinedConstraint.php:319
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/UndefinedConstraint.php:49
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Constraint.php:123
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/ObjectConstraint.php:145
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/ObjectConstraint.php:47
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Constraint.php:90
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/UndefinedConstraint.php:74
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/UndefinedConstraint.php:52
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Constraint.php:123
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/SchemaConstraint.php:92
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Validator.php:61
18:42:26 /workspace/src/tests/phpunit/JsonSchemaAssertionTrait.php:70
18:42:26 /workspace/src/tests/phpunit/structure/RestStructureTest.php:361
Logs generated by test
18:42:26 
18:42:26 2) RestStructureTest::testModuleDefinitionFiles with data set "/workspace/src/includes/Rest/site.v1.json" (stdClass Object (...))
18:42:26 JsonSchema\Exception\InvalidSchemaMediaTypeException: Media type application/schema+json expected
18:42:26 
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/UriRetriever.php:92
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/UriRetriever.php:209
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/UriRetriever.php:181
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/SchemaStorage.php:52
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/SchemaStorage.php:115
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/SchemaStorage.php:138
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/SchemaStorage.php:162
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Constraint.php:123
18:42:26 /workspace/src/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/ObjectConstraint.php:145
18:42:26 /workspace/src/vendor/justinrainbow...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes jsonrainbow/json-schema#871

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.

Copilot AI and others added 2 commits January 23, 2026 08:07
Co-authored-by: DannyvdSluijs <618940+DannyvdSluijs@users.noreply.github.com>
Co-authored-by: DannyvdSluijs <618940+DannyvdSluijs@users.noreply.github.com>
Copilot AI changed the title [WIP] Report what media type is in UriRetriever Include actual media type in InvalidSchemaMediaTypeException Jan 23, 2026
Copilot AI requested a review from DannyvdSluijs January 23, 2026 08:11
Co-authored-by: DannyvdSluijs <618940+DannyvdSluijs@users.noreply.github.com>
@DannyvdSluijs DannyvdSluijs marked this pull request as ready for review January 23, 2026 10:26
@DannyvdSluijs DannyvdSluijs merged commit 241016c into main Jan 23, 2026
18 checks passed
@DannyvdSluijs DannyvdSluijs deleted the copilot/report-media-type-in-uri-retriever branch January 23, 2026 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants