{"id":15026609,"url":"https://github.com/giann/schematics","last_synced_at":"2025-04-09T20:21:31.517Z","repository":{"id":83813355,"uuid":"472659220","full_name":"giann/schematics","owner":"giann","description":"Translates PHP classes to JSON Schema by annotating them with attributes. Provides also validation.","archived":false,"fork":false,"pushed_at":"2024-09-27T08:26:04.000Z","size":261,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-23T22:13:25.052Z","etag":null,"topics":["api","json","json-schema","php","php74","php81"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/giann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-22T07:35:35.000Z","updated_at":"2024-09-27T08:25:52.000Z","dependencies_parsed_at":"2024-06-24T08:43:16.871Z","dependency_job_id":"4e391bdc-e7e5-4637-b22f-d2a0541c1e4e","html_url":"https://github.com/giann/schematics","commit_stats":null,"previous_names":[],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giann%2Fschematics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giann%2Fschematics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giann%2Fschematics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giann%2Fschematics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/giann","download_url":"https://codeload.github.com/giann/schematics/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248104349,"owners_count":21048327,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","json","json-schema","php","php74","php81"],"created_at":"2024-09-24T20:04:45.914Z","updated_at":"2025-04-09T20:21:31.474Z","avatar_url":"https://github.com/giann.png","language":"PHP","readme":"# schematics\n\nTranslates PHP classes to JSON Schema and back.\n\n## Supported Drafts\n\nOnly commonly used drafts `draft-04` and `2020-12` are supported.\n\n## Example\n\n```php\nenum Sex: string\n{\n    case Male = 'male';\n    case Female = 'female';\n    case Other = 'other';\n}\n\n#[ObjectSchema]\nclass Person\n{\n    public function __construct(\n        #[StringSchema(format: Format::Uuid)]\n        #[Description('unique id of the person')]\n        public string $id,\n\n        #[ArraySchema(\n            items: new StringSchema(),\n            minContains: 1\n        )]\n        public array $names,\n\n        #[IntegerSchema(minimum: 0)]\n        public int $age,\n\n        #[StringSchema(enumClass: Sex::class)]\n        public string $sex,\n\n        // Inferred $ref to self\n        public ?Person $father = null\n    ) {\n\t}\n}\n\nenum Power: string\n{\n    case Fly = 'weeeee!';\n    case Strong = 'smash!';\n    case Psychic = 'hummmm!';\n}\n\n// Infer $allOf Person\n#[ObjectSchema]\nclass Hero extends Person\n{\n    public function __construct(\n        string $id,\n        array $names,\n        int $age,\n        string $sex,\n        ?Person $father = null,\n\n        // Infers string property\n        public string $superName,\n\n        #[StringSchema(enumClass: Power::class)]\n        public string $power\n    ) {\n        parent::__construct($id, $names, $age, $sex, $father);\n    }\n}\n```\n\nResults in the following JSON Schema:\n\n```json\n{\n  \"type\": \"object\",\n  \"$defs\": {\n    \"Person\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"id\": {\n          \"type\": \"string\",\n          \"description\": \"unique id of the person\",\n          \"format\": \"uuid\"\n        },\n        \"names\": {\n          \"type\": \"array\",\n          \"items\": {\n            \"type\": \"string\"\n          },\n          \"minContains\": 1\n        },\n        \"age\": {\n          \"type\": \"integer\",\n          \"minimum\": 0\n        },\n        \"sex\": {\n          \"type\": \"string\",\n          \"enum\": [\"male\", \"female\", \"other\"]\n        },\n        \"father\": {\n          \"oneOf\": [\n            {\n              \"type\": \"null\"\n            },\n            {\n              \"$ref\": \"#/$defs/Person\"\n            }\n          ]\n        }\n      },\n      \"required\": [\"id\", \"names\", \"age\", \"sex\", \"father\"]\n    }\n  },\n  \"allOf\": [\n    {\n      \"$ref\": \"#/$defs/Person\"\n    }\n  ],\n  \"properties\": {\n    \"superName\": {\n      \"type\": \"string\"\n    },\n    \"power\": {\n      \"type\": \"string\",\n      \"enum\": [\"weeeee!\", \"smash!\", \"hummmm!\"]\n    }\n  },\n  \"required\": [\"superName\", \"power\"]\n}\n```\n\n## Not Yet Supported\n\n- `$dynamicRef`\n- `$dynamicAnchor`","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgiann%2Fschematics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgiann%2Fschematics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgiann%2Fschematics/lists"}