swaggest / php-json-schema

High definition PHP structures with JSON-schema based validation
MIT License
451 stars 51 forks source link

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

Open jpwijbenga opened 5 months ago

jpwijbenga commented 5 months ago

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 commented 5 months ago

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

jpwijbenga commented 5 months ago

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

ArrayIterator commented 2 months ago

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.