Proposal: Json Schema using PHP Type Declarations #146
bruceoutdoors
started this conversation in
Ideas
Replies: 1 comment
-
This looks like a great modernization idea and an improvement to API usability. Do you think it would be possible to guard such functionality with some feature checks (or options) to keep backwards compatibility? (Sorry, I wasn't really following recent PHP development and lost some fluency.) 😅 |
Beta Was this translation helpful? Give feedback.
0 replies
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
-
Hi @vearutop,
I figured this library could leverage PHP type declarations to build the JSON schema, and use attributes for everything else; this would largely replace what
setUpProperties
is doing.Here's a basic example:
Using PHP's Reflection API we can infer the following JSON schema:
To add other constraints, use attributes:
And this will result in the following schema:
Of course, implementation could be rather complex when you factor inheritance, union types, arrays, and enums. I have a working POC that extends
ClassStructure
in this GitHub Gist. It utilizes features in PHP 8.1, so such a feature would break compatibility with all older PHP versions.I will be open to contribute this feature, but do let me know your thoughts on this!
Beta Was this translation helpful? Give feedback.
All reactions