Skip to content

Commit 80575f3

Browse files
Copilottymondesigns
andcommitted
Update getContentFeatures to report ContentEncoding and ContentMediaType
Co-authored-by: tymondesigns <1801923+tymondesigns@users.noreply.github.com>
1 parent 9895ab1 commit 80575f3

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/Types/StringSchema.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,14 @@ protected function getContentFeatures(): array
201201
{
202202
$features = [];
203203

204+
if ($this->contentEncoding !== null) {
205+
$features[] = SchemaFeature::ContentEncoding;
206+
}
207+
208+
if ($this->contentMediaType !== null) {
209+
$features[] = SchemaFeature::ContentMediaType;
210+
}
211+
204212
if ($this->contentSchema !== null) {
205213
$features[] = SchemaFeature::ContentSchema;
206214
}

tests/Unit/Types/StringSchemaTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
namespace Cortex\JsonSchema\Tests\Unit\Types;
66

7+
use ReflectionClass;
78
use Cortex\JsonSchema\Schema;
89
use Cortex\JsonSchema\Enums\SchemaFormat;
910
use Cortex\JsonSchema\Types\StringSchema;
1011
use Cortex\JsonSchema\Enums\SchemaVersion;
12+
use Cortex\JsonSchema\Enums\SchemaFeature;
1113
use Cortex\JsonSchema\Exceptions\SchemaException;
1214

1315
covers(StringSchema::class);
@@ -275,3 +277,27 @@
275277
'Feature "Schema for decoded content" is not supported in Draft 7. Minimum version required: Draft 2019-09.',
276278
);
277279
});
280+
281+
it('detects content features correctly', function (): void {
282+
$stringSchema = Schema::string('payload', SchemaVersion::Draft_2019_09);
283+
$stringSchema->contentEncoding('base64')
284+
->contentMediaType('application/json')
285+
->contentSchema(Schema::object());
286+
287+
$reflection = new ReflectionClass($stringSchema);
288+
$contentFeaturesMethod = $reflection->getMethod('getContentFeatures');
289+
290+
$contentFeatures = $contentFeaturesMethod->invoke($stringSchema);
291+
292+
expect($contentFeatures)->toContain(SchemaFeature::ContentEncoding);
293+
expect($contentFeatures)->toContain(SchemaFeature::ContentMediaType);
294+
expect($contentFeatures)->toContain(SchemaFeature::ContentSchema);
295+
296+
// Test that features are included in overall feature detection
297+
$getUsedMethod = $reflection->getMethod('getUsedFeatures');
298+
299+
$allFeatures = $getUsedMethod->invoke($stringSchema);
300+
expect($allFeatures)->toContain(SchemaFeature::ContentEncoding);
301+
expect($allFeatures)->toContain(SchemaFeature::ContentMediaType);
302+
expect($allFeatures)->toContain(SchemaFeature::ContentSchema);
303+
});

0 commit comments

Comments
 (0)