Coder Social home page Coder Social logo

jc21 / cypress-swagger-validation Goto Github PK

View Code? Open in Web Editor NEW
22.0 3.0 5.0 298 KB

Validate your request responses against Swagger JSON Endpoints. AKA Contract Testing.

License: MIT License

JavaScript 1.06% TypeScript 98.94%
cypress swagger openapi contract-testing

cypress-swagger-validation's Introduction

๐Ÿ“™ Some of my open source projects

Nginx Proxy Manager dnsrouter Juxtapose

All my Repos

๐Ÿ”ฅ Streak stats

Streak streak

๐Ÿ“Š GitHub Profile Stats

My GitHub stats My most used languages

๐Ÿ“Š Recent GitHub Activity

My recent GitHub activity


Made with โค๏ธ by Pius Walter and affectionately stolen by jc21

cypress-swagger-validation's People

Contributors

dependabot[bot] avatar jc21 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cypress-swagger-validation's Issues

Problems integrating with Cypress LTS

Thanks for the work that you've been doing with this lib. I'm testing out a couple of OAS validator libs to integrate with our Cypress tests and I'm having some troubles integrating yours with Cypress 13.5.0 - was wondering if you can help out.

The format for cypress.config.ts changed itm and following your example:

import {expect, use} from "chai";
const {SwaggerValidation} = require('@jc21/cypress-swagger-validation');

export default defineConfig({
    screenshotOnRunFailure: false,
    env: {
        hideCredentials: true,
    },
    e2e: {
        baseUrl: 'https://api.stg.thousandeyes.com',
        setupNodeEvents(on, config) {
            on('task', {
                 SwaggerValidation(config){
                    return config;
                },
                 otherTask(){}

simply states that validateSwaggerSchema does not exist. I also tried putting everything in the test, without success:

describe('API Test', () => {
    it.only('should satisfy OpenAPI spec', () => {
        MyEndpoint.getAll().then((response) => {
            const config = {
                file:                 'path.to.yaml.file', 
                endpoint:       '/v7/account-groups',
                method:         'GET',
                statusCode:     200,
                responseSchema: response.body,
                verbose:        true,                     
            }
            // cy.task('validateSwaggerSchema', config).should('equal', null);
            SwaggerValidation(config).validateSwaggerSchema(config)
        });
    });
});

Do you have any idea what I'm doing wrong?

Validate intercepts

Hi and thanks for the nice plugin!
I wanted to share an idea of validating intercepts with the openapi schema.

Kind of like:

beforeEach(() => {
    cy.intercept('*', req => {
        req.continue(res => {
            cy.task('validateSwaggerSchema', {
                file: './../swagger.json',
                endpoint: req.url,
                method: req.method,
                statusCode: res.statusCode,
                responseSchema: res.body,
                verbose: true // optional, default: false
            }).should('equal', null);
        });
    });
});

This example does not work because of cypress-io/cypress#7667

This would ensure fixtures (e.g. cy.intercept('GET', '/api/identity', { fixture: 'identity/sys-admin.json'})) are still adhering to the schema.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.