Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- UriRetriever: Include actual media type in InvalidSchemaMediaTypeException message ([#872](https://github.com/jsonrainbow/json-schema/pull/872))

## [6.6.4] - 2025-12-19
### Changed
Expand Down
2 changes: 1 addition & 1 deletion src/JsonSchema/Uri/UriRetriever.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function confirmMediaType($uriRetriever, $uri)
}
}

throw new InvalidSchemaMediaTypeException(sprintf('Media type %s expected', Validator::SCHEMA_MEDIA_TYPE));
throw new InvalidSchemaMediaTypeException(sprintf('Media type %s expected, but %s given', Validator::SCHEMA_MEDIA_TYPE, $contentType));
}

/**
Expand Down
14 changes: 14 additions & 0 deletions tests/Uri/UriRetrieverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,20 @@ public function testConfirmMediaTypeThrowsExceptionForUnsupportedTypes(): void
$retriever->confirmMediaType($uriRetriever, null);
}

public function testConfirmMediaTypeExceptionIncludesActualMediaType(): void
{
$uriRetriever = $this->createMock(\JsonSchema\Uri\Retrievers\UriRetrieverInterface::class);
$retriever = new UriRetriever();
$uriRetriever->expects($this->at(0))
->method('getContentType')
->willReturn('text/html');

$this->expectException(InvalidSchemaMediaTypeException::class);
$this->expectExceptionMessage('Media type application/schema+json expected, but text/html given');

$retriever->confirmMediaType($uriRetriever, null);
}

private function mockRetriever($schema): void
{
$retrieverMock = $this->getRetrieverMock($schema);
Expand Down
Loading