swaggest / php-json-schema

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

Can I infer json schema ? #110

Closed ilazaridis closed 3 years ago

ilazaridis commented 3 years ago

Is there a way to do that out of json sample or in any other way that I couldn't find yet ?

Thanks

vearutop commented 3 years ago

You can try https://github.com/swaggest/json-schema-maker (https://github.com/swaggest/json-cli#buildschema).

https://app.quicktype.io this tool also can make schema from JSON sample.

ilazaridis commented 3 years ago

Thanks! I expected that this would be possible once you implement public static function setUpProperties($properties, Schema $ownerSchema), to somehow export it out of this. Is this possible ?

vearutop commented 3 years ago

Yes, it is also possible to export schema of a class that implements setupProperties.

        $schema = MyClass::schema();
        $schemaData = Schema::export($schema);

See test for example.

ilazaridis commented 3 years ago

Awesome, thank you!

That's what I was looking for.