php-json-schema icon indicating copy to clipboard operation
php-json-schema copied to clipboard

Cant get exporter to set `$id` instead of `id` for schema id.

Open jpwijbenga opened this issue 1 year ago • 3 comments

I'm trying to export a given schema to generate draft 7, which means use '$id' instead of 'id'. Trying with context passed to exporter, but it will keep generating id not $id.

image

Bug or am I doing it wrong?

jpwijbenga avatar Jun 24 '24 14:06 jpwijbenga

So the picture I posted is the fix because it doesn't work without third ande fourth line.

jpwijbenga avatar Jun 24 '24 14:06 jpwijbenga

Also, I looked through readme and tests, but couldn't find anything about setting version wrt. export.

jpwijbenga avatar Jun 24 '24 14:06 jpwijbenga

Any info?

I also just try to manually set to $ownerSchema->{'$id'} and this is so weird.

https://github.com/swaggest/php-json-schema/blob/2b99251f31046f682b120fb807fea8ab688a493e/src/Structure/ClassStructureTrait.php#L106

image

I found that, even we've already set key data mapping :

$ownerSchema->addPropertyMapping(Schema::PROP_ID, 'id');

On json serialize wil use id rather than setted data mapping, because the previous key data mapped has been ignored or not substitute with current data key set.

ArrayIterator avatar Sep 19 '24 13:09 ArrayIterator