{"id":21678498,"url":"https://github.com/jc21/cypress-swagger-validation","last_synced_at":"2025-04-12T05:36:21.922Z","repository":{"id":35143484,"uuid":"212453798","full_name":"jc21/cypress-swagger-validation","owner":"jc21","description":"Validate your request responses against Swagger JSON Endpoints. AKA Contract Testing.","archived":false,"fork":false,"pushed_at":"2024-03-13T00:34:22.000Z","size":239,"stargazers_count":22,"open_issues_count":2,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-14T13:32:54.412Z","etag":null,"topics":["contract-testing","cypress","openapi","swagger"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/jc21.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":"2019-10-02T22:34:57.000Z","updated_at":"2024-06-19T00:22:27.484Z","dependencies_parsed_at":"2023-01-15T14:42:47.012Z","dependency_job_id":"8145f066-ef9a-449f-9f1f-f8b401b5d05b","html_url":"https://github.com/jc21/cypress-swagger-validation","commit_stats":{"total_commits":17,"total_committers":3,"mean_commits":5.666666666666667,"dds":"0.17647058823529416","last_synced_commit":"4fb776403c72f9e890511bcea0af18ac0a998a76"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jc21%2Fcypress-swagger-validation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jc21%2Fcypress-swagger-validation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jc21%2Fcypress-swagger-validation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jc21%2Fcypress-swagger-validation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jc21","download_url":"https://codeload.github.com/jc21/cypress-swagger-validation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247801160,"owners_count":20998339,"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":["contract-testing","cypress","openapi","swagger"],"created_at":"2024-11-25T14:35:47.206Z","updated_at":"2025-04-12T05:36:21.881Z","avatar_url":"https://github.com/jc21.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cypress Swagger Validation Plugin\n\nValidate your request responses against Swagger JSON Endpoints. AKA Contract Testing.\n\n[![npm (scoped)](https://img.shields.io/npm/v/@jc21/cypress-swagger-validation.svg?style=for-the-badge)](https://www.npmjs.com/package/@jc21/cypress-swagger-validation)\n[![npm (types)](https://img.shields.io/npm/types/@jc21/cypress-swagger-validation.svg?style=for-the-badge)](https://www.npmjs.com/package/@jc21/cypress-swagger-validation)\n[![npm (licence)](https://img.shields.io/npm/l/@jc21/cypress-swagger-validation.svg?style=for-the-badge)](https://www.npmjs.com/package/@jc21/cypress-swagger-validation)\n\nDo you use Cypress to perform API endpoint testing? Do you have Swagger/Openapi v3 schema?\nThis is the plugin for you.\n\nSee the [example swagger files](testing) to see how the usage below works with it.\n\nYour swagger doc will need endpoints with content schema defined.\n\n\n### Cypress Installation\n\n```bash\nyarn add @jc21/cypress-swagger-validation\n```\n\nThen in your cypress Plugins file:\n```javascript\nconst {SwaggerValidation} = require('@jc21/cypress-swagger-validation');\n\nmodule.exports = (on, config) =\u003e {\n    // ...\n    on('task', SwaggerValidation(config));\n    // ...\n    return config;\n};\n```\n\n\n### Cypress Usage\n\n```javascript\ndescribe('Basic API checks', () =\u003e {\n    it('Should be a valid swagger schema', function () {\n        cy.task('validateSwaggerFile', {\n            file: './testing/swagger.json',  // optional path or full URL, see below\n        }).should('equal', null);\n    });\n\n    it('Should return a valid health payload', function () {\n        cy.request('/healthz').then($response =\u003e {\n            // Check the swagger schema:\n            cy.task('validateSwaggerSchema', {\n                file:           './testing/swagger.json',  // optional path or full URL, see below\n                endpoint:       '/healthz',\n                method:         'get',\n                statusCode:     200,\n                responseSchema: $response.body,\n                verbose:        true,                      // optional, default: false\n            }).should('equal', null);\n        });\n    });\n});\n```\n\n### The swagger file\n\nThis can either be a file on disk or a URL.\n\nWhen using a file on disk and due to the fact that this plugin runs on the Cypress Backend, the location of the file must be defined as either\nthe full path on disk or relative path to the running of the cypress command.\n\nYou can define the swagger file location either with an environment variable which can apply to all tests:\n\n`config.env.swaggerFile`\n\nor within each individial test using the options below.\n\n\n### Options\n\n#### validateSwaggerFile\n\n| Option           | Description                                                   | Optional | Default                  |\n| ---------------- | ------------------------------------------------------------- | -------- | ------------------------ |\n| `file`           | The location of the swagger file to use for contract testing  | true     | `config.env.swaggerFile` |\n\n#### validateSwaggerSchema\n\n| Option           | Description                                                   | Optional | Default                  |\n| ---------------- | ------------------------------------------------------------- | -------- | ------------------------ |\n| `file`           | The location of the swagger file to use for contract testing  | true     | `config.env.swaggerFile` |\n| `endpoint`       | The name of the swagger endpoint to check                     |          |                          |\n| `method`         | The request method of the endpoint                            |          |                          |\n| `statuscode`     | The http status code beneath the method                       |          |                          |\n| `responseSchema` | The payload of the API response to validate                   |          |                          |\n| `verbose`        | Console.log more info when validation fails                   | true     | false                    |\n\n\n### Compiling Source\n\n```bash\nyarn install\nyarn build\nyarn test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjc21%2Fcypress-swagger-validation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjc21%2Fcypress-swagger-validation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjc21%2Fcypress-swagger-validation/lists"}