{"id":16101605,"url":"https://github.com/bjansen/swagger-schema-validator","last_synced_at":"2025-03-16T08:32:28.627Z","repository":{"id":29493455,"uuid":"121847367","full_name":"bjansen/swagger-schema-validator","owner":"bjansen","description":"Validates JSON objects against Swagger 2 definitions","archived":false,"fork":false,"pushed_at":"2025-02-24T09:01:16.000Z","size":173,"stargazers_count":19,"open_issues_count":6,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-27T05:55:57.728Z","etag":null,"topics":["json-schema","json-validation","swagger","swagger-validator"],"latest_commit_sha":null,"homepage":null,"language":"Java","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/bjansen.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":"2018-02-17T10:50:13.000Z","updated_at":"2025-01-16T10:14:47.000Z","dependencies_parsed_at":"2023-01-14T15:03:24.173Z","dependency_job_id":"7d963d63-97cd-42f8-8ac9-56ab9fae4b28","html_url":"https://github.com/bjansen/swagger-schema-validator","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjansen%2Fswagger-schema-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjansen%2Fswagger-schema-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjansen%2Fswagger-schema-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjansen%2Fswagger-schema-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bjansen","download_url":"https://codeload.github.com/bjansen/swagger-schema-validator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243806071,"owners_count":20350775,"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":["json-schema","json-validation","swagger","swagger-validator"],"created_at":"2024-10-09T18:50:26.934Z","updated_at":"2025-03-16T08:32:28.297Z","avatar_url":"https://github.com/bjansen.png","language":"Java","readme":"# Swagger schema validator ![](https://img.shields.io/maven-central/v/com.github.bjansen/swagger-schema-validator.svg?style=flat) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=swagger-schema-validator\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=swagger-schema-validator)\n\nThis library validates JSON objects against models defined in the `definitions` section of a Swagger 2 specification.\n\n```java\nInputStream spec = getClass().getResourceAsStream(\"mySpec.yaml\");\nSwaggerValidator validator = SwaggerValidator.forYamlSchema(spec);\n\nProcessingReport report = validator.validate(\"{\\\"name\\\": \\\"Bob\\\"}\", \"/definitions/User\");\n\nif (report.isSuccess()) {\n    doStuff();\n}\n```\n\n## Installation\n\nThis library is available on Maven Central:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.bjansen\u003c/groupId\u003e\n    \u003cartifactId\u003eswagger-schema-validator\u003c/artifactId\u003e\n    \u003cversion\u003e1.0.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Additional schema validations\n\nIn addition to the subset of [JSON-Schema Draft 4](https://tools.ietf.org/html/draft-zyp-json-schema-04) already \nsupported by Swagger 2 specifications, this library adds support for the following JSON-Schema validation keywords:\n\n| Keyword             | Description                                                                                           |\n|---------------------|-------------------------------------------------------------------------------------------------------|\n| `additionalItems`   | See [#rfc.section.6.4.2](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.4.2) |\n| `contains`          | See [#rfc.section.6.4.6](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.4.6) |\n| `patternProperties` | See [#rfc.section.6.5.5](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.5.5) |\n| `dependencies`      | See [#rfc.section.6.5.7](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.5.7) |\n| `propertyNames`     | See [#rfc.section.6.5.8](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.5.8) |\n| `if`                | See [#rfc.section.6.6.1](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.6.1) |\n| `then`              | See [#rfc.section.6.6.2](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.6.2) |\n| `else`              | See [#rfc.section.6.6.3](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.6.3) |\n| `allOf`             | See [#rfc.section.6.7.1](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.7.1) |\n| `anyOf`             | See [#rfc.section.6.7.2](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.7.2) |\n| `oneOf`             | See [#rfc.section.6.7.3](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.7.3) |\n| `not`               | See [#rfc.section.6.7.4](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.7.4) |\n\nTo use them in a Swagger 2 spec, simply prefix them with `x-`, like this:\n\n```yaml\ndefinitions:\n  User:\n    x-oneOf: [{required: [\"id\"]}, {required: [\"name\"]}]\n    properties:\n      id:\n        type: integer\n      name:\n        type: string\n```\n\nIn the example above, a `User` will be valid if it contains either an `id` or a `name`.\n\n## Custom schemas and validation keywords\n\nIn case you need more than the default factory methods to parse JSON/YAML schemas, or need to do extra keywords\ntransformations (like automatically renaming `x-oneof` to `x-oneOf` in schemas you don't control), you can use\nthis factory method that was introduced in 1.0.0:\n\n```java\nJsonNode schema = Json.mapper().readTree(getClass().getResourceAsStream(\"schema.json\"));\nMap\u003cString, String\u003e transformations = Map.of(\"x-oneof\", \"x-oneOf\");\n\nSwaggerValidator validator = SwaggerValidator.forJsonNode(schema, transformations);\n```\n\nCustom transformations will be applied before built-in ones, so in this case it will go `x-oneof` -\u003e `x-oneOf` -\u003e `oneOf`.\n\n## How it works\n\nThis library is a bridge between a Swagger schema parser provided by [swagger-core](https://github.com/swagger-api/swagger-core)\nand a general-purpose JSON schema validator provided by [json-schema-validator](https://github.com/java-json-tools/json-schema-validator).\n\nAs a consequence, it is pretty much limited to the features these two libraries offer.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjansen%2Fswagger-schema-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbjansen%2Fswagger-schema-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjansen%2Fswagger-schema-validator/lists"}