{"id":19692330,"url":"https://github.com/ddrv/php-dresscode","last_synced_at":"2025-07-17T05:36:09.010Z","repository":{"id":56964321,"uuid":"325419855","full_name":"ddrv/php-dresscode","owner":"ddrv","description":"PHP OpenAPI schema validator","archived":false,"fork":false,"pushed_at":"2021-01-29T05:22:11.000Z","size":49,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-02T08:18:33.782Z","etag":null,"topics":["library","openapi","php","swagger","validator"],"latest_commit_sha":null,"homepage":"https://dresscode.ddrv.ru/","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/ddrv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"custom":"https://www.paypal.me/ddrv","patreon":"ddrv"}},"created_at":"2020-12-30T00:53:59.000Z","updated_at":"2021-01-29T05:22:01.000Z","dependencies_parsed_at":"2022-08-21T10:20:20.501Z","dependency_job_id":null,"html_url":"https://github.com/ddrv/php-dresscode","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/ddrv/php-dresscode","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddrv%2Fphp-dresscode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddrv%2Fphp-dresscode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddrv%2Fphp-dresscode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddrv%2Fphp-dresscode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ddrv","download_url":"https://codeload.github.com/ddrv/php-dresscode/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddrv%2Fphp-dresscode/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265569452,"owners_count":23789732,"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":["library","openapi","php","swagger","validator"],"created_at":"2024-11-11T19:13:00.847Z","updated_at":"2025-07-17T05:36:08.966Z","avatar_url":"https://github.com/ddrv.png","language":"PHP","readme":"# DressCode for your data\n\n## Install\n\n```text\ncomposer require ddrv/dresscode\n```\n\n## Usage\n\n```php\n\u003c?php\n\nuse Ddrv\\DressCode\\Action;\nuse Ddrv\\DressCode\\DressCode;\n\nrequire 'vendor/autoload.php';\n\n$validator = new DressCode();\n\n$validator-\u003evalidate(Action::output(), ['type' =\u003e 'string'], 'it is ok');\n```\n\n## Check errors\n\n```php\n\u003c?php\n\nuse Ddrv\\DressCode\\Action;\nuse Ddrv\\DressCode\\DressCode;\nuse Ddrv\\DressCode\\Exception\\InvalidValueException;\nrequire 'vendor/autoload.php';\n\n$validator = new DressCode();\n\n\n$rule = [\n    'type' =\u003e 'object',\n    'properties' =\u003e [\n        'email' =\u003e [\n            'type' =\u003e 'string',\n            'format' =\u003e 'email',\n        ],\n        'login' =\u003e [\n            'type' =\u003e 'string',\n            'minLength' =\u003e 5,\n            'maxLength' =\u003e 32,\n            'pattern' =\u003e '^[a-z\\-]+$',\n        ],\n        'birthday' =\u003e [\n            'type' =\u003e 'string',\n            'format' =\u003e 'date',\n        ],\n    ],\n    'required' =\u003e ['email', 'login'],\n    'additionalProperties' =\u003e true,\n    'nullable' =\u003e true,\n];\n$data = [\n    'email' =\u003e 'ivan',\n    'login' =\u003e 'ddrv',\n    'birthday' =\u003e '2020-02-30',\n];\n\ntry {\n    $validator-\u003evalidate(Action::input(), $rule, $data);\n} catch (InvalidValueException $e) {\n    foreach ($e-\u003egetErrors() as $error) {\n        echo $error-\u003egetPath() . ': ' . $error-\u003egetMessage() . PHP_EOL;\n    }\n}\n\n/*\nemail: ivan is not a email\nlogin: string size must be between 5 to 32 symbols\nbirthday: 2020-02-30 is not a date\n*/\n```\n\n## Defining rules\n\n```php\n\u003c?php\n\nuse Ddrv\\DressCode\\Action;\nuse Ddrv\\DressCode\\DressCode;\n\nrequire 'vendor/autoload.php';\n\n$validator = new DressCode();\n$validator-\u003esetEntity('#/entities/email', [\n    'type' =\u003e 'string',\n    'format' =\u003e 'email',\n]);\n$validator-\u003esetEntity('#/entities/login', [\n    'type' =\u003e 'string',\n    'minLength' =\u003e 5,\n    'maxLength' =\u003e 32,\n    'pattern' =\u003e '^[a-z\\-]+$',\n]);\n$validator-\u003esetEntity('#/entities/date', [\n    'type' =\u003e 'string',\n    'format' =\u003e 'date',\n]);\n\n$rule = [\n    'type' =\u003e 'object',\n    'properties' =\u003e [\n        'email' =\u003e [\n            '$ref' =\u003e '#/entities/email',\n        ],\n        'login' =\u003e [\n            '$ref' =\u003e '#/entities/login',\n        ],\n        'birthday' =\u003e [\n            '$ref' =\u003e '#/entities/date',\n        ],\n        'password' =\u003e [\n            'type' =\u003e 'string',\n            'minLength' =\u003e 8,\n            'maxLength' =\u003e 32,\n            'writeOnly' =\u003e true,\n        ],\n    ],\n    'required' =\u003e ['email', 'login'],\n    'additionalProperties' =\u003e true,\n    'nullable' =\u003e true,\n];\n$data = [\n    'email' =\u003e 'ivan@ddrv.ru',\n    'login' =\u003e 'i-dudarev',\n    'password' =\u003e 'short',\n];\n\n$valid = $validator-\u003evalidate(Action::input(), $rule, $data); // Error password\n$valid = $validator-\u003evalidate(Action::output(), $rule, $data); // No error because password writeOnly\n$valid = $validator-\u003evalidate(Action::input(), ['$ref' =\u003e '#/entities/date'], '2020-12-30');\n```\n\n## Register your string formats\n\n```php\n\u003c?php\n\nuse Ddrv\\DressCode\\Action;\nuse Ddrv\\DressCode\\Exception\\WrongFormatException;\nuse Ddrv\\DressCode\\Format\\Format;\nuse Ddrv\\DressCode\\DressCode;\n\nrequire 'vendor/autoload.php';\n\n$validator = new DressCode();\n\n$myEmailFormat = new class extends Format\n{\n    public function check(string $value) : void{\n        if (!filter_var($value, FILTER_VALIDATE_EMAIL) !== false) {\n            throw new WrongFormatException('email');\n        }\n    }\n};\n$validator-\u003eregisterFormat('email', $myEmailFormat);\n\n$rule = [\n    'type' =\u003e 'string',\n    'format' =\u003e 'email',\n];\n$validator-\u003evalidate(Action::input(), $rule, 'ivan@ddrv.ru');\n```\n\n## Strict types\n\nuse `Action::input(true)` and `Action::output(true)` for strict type checking.\n\n\u003e **Warning**\n\u003e \n\u003e do not use it if you are checking data `application/x-www-form-urlencoded`\n\n## Supported types\n\n- [x] boolean\n- [x] number\n- [x] number (format `float`)\n- [x] number (format `double`)\n- [x] integer\n- [x] integer (format `int32`)\n- [x] integer (format `int64`)\n- [x] string\n- [x] string (format `binary`)\n- [x] string (format `byte`)\n- [x] string (format `date`)\n- [x] string (format `date-time`)\n- [x] string (format `email`)\n- [x] string (format `hostname`)\n- [x] string (format `ip`)\n- [x] string (format `ipv4`)\n- [x] string (format `ipv6`)\n- [x] string (format `uri`)\n- [x] string (format `uuid`)\n- [x] array\n- [x] object\n\n## Supported keywords\n\n### All types\n\n- [x] nullable\n- [x] readOnly\n- [x] writeOnly\n- [x] default (only for object properties)\n\n### Integer and number types\n\n- [x] minimum\n- [x] maximum\n- [x] exclusiveMinimum\n- [x] exclusiveMaximum\n- [x] multipleOf\n\n### String type\n\n- [x] pattern\n- [x] minLength\n- [x] maxLength\n- [x] enum\n\n### Array type\n\n- [x] items\n- [x] minItems\n- [x] maxItems\n- [x] uniqueItems\n\n### Object type\n\n- [x] properties\n- [x] required\n- [x] additionalProperties\n- [x] minProperties\n- [x] maxProperties\n\n## Support references\n\n- [x] $ref (only after call `setEntity()` method)\n\n## Supported polymorphism\n\n- [x] oneOf\n- [x] anyOf\n- [x] allOf\n- [x] not\n\n","funding_links":["https://www.paypal.me/ddrv","https://patreon.com/ddrv"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fddrv%2Fphp-dresscode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fddrv%2Fphp-dresscode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fddrv%2Fphp-dresscode/lists"}